Multiple profiles (#312)
* Navbar user profile * profiles stuff * fix profile * Lint fix * Some ui experiments * More ui work * progress * Lint fix * migration, web api, wip * profile view and web app * web app and apis * Invidious and profiles * Lint fix * bug fix * Remove ActionContentNode * Profile icon button, profile color * Lint fix * reset server url * href that doesn't work * remove activate button on active profile * TODO * Fin. * Final touches --------- Co-authored-by: github-action linter <githubaction@githubaction.com>
This commit is contained in:
1 parent
8e03ca0ea6
commit
394dd23999
60 files changed
+1725
-311
No files matched your search
@@ -45,8 +45,17 @@ export class PlayletApi {
|
||||
return await response;
|
||||
}
|
||||
|
||||
static async logout() {
|
||||
await fetch(`${PlayletApi.host()}/invidious/logout`);
|
||||
static async getProfiles() {
|
||||
const response = await fetch(`${PlayletApi.host()}/api/profiles`);
|
||||
return await response.json();
|
||||
}
|
||||
|
||||
static async activateProfile(profileId) {
|
||||
await this.postJson(`${PlayletApi.host()}/api/profiles/activate`, { id: profileId });
|
||||
}
|
||||
|
||||
static async logout(profileId) {
|
||||
return await fetch(`${PlayletApi.host()}/api/profiles?id=${profileId}`, { method: "DELETE" });
|
||||
}
|
||||
|
||||
static async playVideo(args) {
|
||||
|
||||
@@ -1,55 +1,48 @@
|
||||
<script lang="ts">
|
||||
import PlayletLogoDark from "assets/logo-dark.svg.svelte";
|
||||
import PlayletLogoLight from "assets/logo-light.svg.svelte";
|
||||
import UserIcon from "assets/user.svg.svelte";
|
||||
import { PlayletApi } from "lib/Api/PlayletApi";
|
||||
import { ExternalControlProtocol } from "lib/Api/ExternalControlProtocol";
|
||||
import { appThemeStore, playletStateStore } from "lib/Stores";
|
||||
import ThemeSelect from "lib/ThemeToggle.svelte";
|
||||
import ProfilesDialog from "./ProfilesDialog.svelte";
|
||||
import ProfileAvatar from "./ProfileAvatar.svelte";
|
||||
|
||||
let profilesDialog;
|
||||
let version;
|
||||
let loggedIn = false;
|
||||
let auth_url;
|
||||
let currentInstance;
|
||||
let loggedInInstance;
|
||||
let username;
|
||||
let currentProfile;
|
||||
let appId = "693751";
|
||||
|
||||
playletStateStore.subscribe((value) => {
|
||||
version = value?.app?.lib_version ?? "";
|
||||
version = getAppVersion(value);
|
||||
if (value?.app?.id) {
|
||||
appId = value?.app?.id;
|
||||
}
|
||||
let profiles = value?.profiles?.profiles ?? [];
|
||||
currentProfile = profiles.find(
|
||||
(p) => p.id === value?.profiles?.currentProfile
|
||||
);
|
||||
});
|
||||
|
||||
const showProfilesDialog = () => {
|
||||
profilesDialog.show();
|
||||
};
|
||||
|
||||
function getAppVersion(playletState) {
|
||||
let version = playletState?.app?.lib_version ?? "";
|
||||
const appId = playletState?.app?.id;
|
||||
if (appId === "dev") {
|
||||
version += "-dev";
|
||||
}
|
||||
|
||||
if (
|
||||
value?.app?.lib_url_type === "custom" &&
|
||||
value?.app?.lib_url ===
|
||||
playletState?.app?.lib_url_type === "custom" &&
|
||||
playletState?.app?.lib_url ===
|
||||
"https://github.com/iBicha/playlet/releases/download/canary/playlet-lib.zip"
|
||||
) {
|
||||
version += "-canary";
|
||||
}
|
||||
loggedIn = value?.invidious?.logged_in;
|
||||
auth_url = value?.invidious?.auth_url;
|
||||
currentInstance = value?.invidious?.current_instance;
|
||||
loggedInInstance = value?.invidious?.logged_in_instance;
|
||||
username = value?.invidious?.logged_in_username;
|
||||
});
|
||||
|
||||
const login = () => {
|
||||
if (!auth_url) {
|
||||
alert("Error with login, please refresh the page.");
|
||||
return;
|
||||
}
|
||||
window.location = auth_url;
|
||||
};
|
||||
const logout = async () => {
|
||||
await PlayletApi.logout();
|
||||
PlayletApi.getState().then((value) => {
|
||||
playletStateStore.set(value);
|
||||
});
|
||||
};
|
||||
return version;
|
||||
}
|
||||
</script>
|
||||
|
||||
<div class="navbar bg-base-100 sticky top-0 z-40">
|
||||
@@ -65,41 +58,18 @@
|
||||
</div>
|
||||
<div class="flex-none">
|
||||
<ThemeSelect />
|
||||
{#if loggedIn && username}
|
||||
{#if currentProfile && currentProfile.username}
|
||||
<div class="badge badge-outline">
|
||||
<span>{username}</span>
|
||||
<span>{currentProfile.username}</span>
|
||||
</div>
|
||||
{/if}
|
||||
<div class="dropdown dropdown-end">
|
||||
<div tabindex="-1" class="btn btn-ghost btn-circle avatar">
|
||||
<div class="w-8 rounded-full">
|
||||
<UserIcon />
|
||||
</div>
|
||||
</div>
|
||||
<ul
|
||||
tabindex="-1"
|
||||
class="menu menu-sm dropdown-content mt-3 p-2 shadow bg-base-100 rounded-box"
|
||||
>
|
||||
{#if loggedIn}
|
||||
<li>
|
||||
<div
|
||||
class="tooltip tooltip-left"
|
||||
data-tip={`Logout from ${loggedInInstance}`}
|
||||
>
|
||||
<button on:click={logout}>Logout</button>
|
||||
</div>
|
||||
</li>
|
||||
{:else}
|
||||
<li>
|
||||
<div
|
||||
class="tooltip tooltip-left"
|
||||
data-tip={`Login using ${currentInstance}`}
|
||||
>
|
||||
<button on:click={login}>Login to Invidious</button>
|
||||
</div>
|
||||
</li>
|
||||
{/if}
|
||||
</ul>
|
||||
</div>
|
||||
<button
|
||||
on:click={showProfilesDialog}
|
||||
class="btn btn-ghost btn-circle avatar"
|
||||
>
|
||||
<ProfileAvatar />
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<ProfilesDialog bind:this={profilesDialog} />
|
||||
@@ -0,0 +1,32 @@
|
||||
<script lang="ts">
|
||||
import { playletStateStore } from "lib/Stores";
|
||||
import UserIcon from "assets/user.svg.svelte";
|
||||
|
||||
let currentProfile;
|
||||
|
||||
playletStateStore.subscribe((value) => {
|
||||
let profiles = value?.profiles?.profiles ?? [];
|
||||
currentProfile = profiles.find(
|
||||
(p) => p.id === value?.profiles?.currentProfile
|
||||
);
|
||||
});
|
||||
</script>
|
||||
|
||||
<div>
|
||||
{#if currentProfile && currentProfile.username}
|
||||
<div class="avatar placeholder m-1.5">
|
||||
<div
|
||||
class="rounded-full w-8 ring ring-offset-base-100 ring-offset-2"
|
||||
style="background-color: {currentProfile.color}"
|
||||
>
|
||||
<span class="text-xl font-medium text-gray-200"
|
||||
>{currentProfile.username.substring(0, 1).toUpperCase()}</span
|
||||
>
|
||||
</div>
|
||||
</div>
|
||||
{:else}
|
||||
<div class="w-8 rounded-full">
|
||||
<UserIcon />
|
||||
</div>
|
||||
{/if}
|
||||
</div>
|
||||
@@ -0,0 +1,136 @@
|
||||
<script lang="ts">
|
||||
import { playletStateStore } from "lib/Stores";
|
||||
import { PlayletApi } from "./Api/PlayletApi";
|
||||
import { get } from "svelte/store";
|
||||
|
||||
export function show() {
|
||||
modal.showModal();
|
||||
refreshProfiles();
|
||||
}
|
||||
|
||||
export function close() {
|
||||
modal.close();
|
||||
accordionState = null;
|
||||
}
|
||||
|
||||
let modal;
|
||||
|
||||
let profiles = [];
|
||||
let currentProfile;
|
||||
|
||||
let authUrl;
|
||||
let currentInstance;
|
||||
|
||||
let accordionState = null;
|
||||
|
||||
playletStateStore.subscribe((value) => {
|
||||
authUrl = value?.invidious?.auth_url;
|
||||
currentInstance = value?.invidious?.current_instance;
|
||||
profiles = value?.profiles?.profiles ?? [];
|
||||
currentProfile = profiles.find(
|
||||
(p) => p.id === value?.profiles?.currentProfile
|
||||
);
|
||||
});
|
||||
|
||||
function refreshProfiles() {
|
||||
PlayletApi.getProfiles().then((profiles) => {
|
||||
const state = get(playletStateStore);
|
||||
state.profiles = profiles;
|
||||
playletStateStore.set(state);
|
||||
});
|
||||
}
|
||||
|
||||
async function activate(profileId: string) {
|
||||
await PlayletApi.activateProfile(profileId);
|
||||
window.location.reload();
|
||||
}
|
||||
|
||||
async function logout(profileId: string) {
|
||||
await PlayletApi.logout(profileId);
|
||||
if (profileId === currentProfile?.id) {
|
||||
window.location.reload();
|
||||
return;
|
||||
}
|
||||
refreshProfiles();
|
||||
}
|
||||
|
||||
function login() {
|
||||
if (!authUrl) {
|
||||
alert("Error with login, please refresh the page.");
|
||||
return;
|
||||
}
|
||||
window.location = authUrl;
|
||||
}
|
||||
</script>
|
||||
|
||||
<dialog bind:this={modal} class="modal">
|
||||
<form method="dialog" class="modal-box bg-base-100">
|
||||
<div class="flex flex-col items-center">
|
||||
<div class="text-xl font-medium m-4">Profiles</div>
|
||||
|
||||
{#each profiles as profile}
|
||||
<div class="collapse collapse-arrow bg-base-300 m-1">
|
||||
<input
|
||||
type="radio"
|
||||
name="profiles-accordion"
|
||||
value={profile.id}
|
||||
bind:group={accordionState}
|
||||
/>
|
||||
<div class="collapse-title flex">
|
||||
<div>
|
||||
<div class="avatar placeholder">
|
||||
<div
|
||||
class="rounded-full w-12 {profile.id === currentProfile?.id
|
||||
? 'ring ring-primary ring-offset-base-100 ring-offset-2'
|
||||
: ''} "
|
||||
style="background-color: {profile.color}"
|
||||
>
|
||||
<span class="text-xl font-medium text-gray-200"
|
||||
>{profile.username.substring(0, 1).toUpperCase()}</span
|
||||
>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="ml-4">
|
||||
<div class="font-medium">
|
||||
{profile.username}
|
||||
</div>
|
||||
<div class="text-xs font-light">
|
||||
<a
|
||||
class="link"
|
||||
href={profile.serverUrl}
|
||||
target="_blank"
|
||||
rel="noopener noreferrer">{profile.serverUrl}</a
|
||||
>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="collapse-content">
|
||||
{#if profile.id !== currentProfile?.id}
|
||||
<button
|
||||
on:click={() => activate(profile.id)}
|
||||
class="btn btn-primary m-1">Activate</button
|
||||
>
|
||||
{/if}
|
||||
<button
|
||||
on:click={() => logout(profile.id)}
|
||||
class="btn btn-primary m-1">Logout</button
|
||||
>
|
||||
</div>
|
||||
</div>
|
||||
{/each}
|
||||
<div class="flex items-center">
|
||||
<button class="btn btn-primary" on:click={login}>
|
||||
<div class="">
|
||||
<div class="text-m">Login to Invidious</div>
|
||||
<div class="text-xs font-light">{currentInstance}</div>
|
||||
</div>
|
||||
</button>
|
||||
<button class="btn m-6" on:click={close}>Close</button>
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
<form method="dialog" class="modal-backdrop">
|
||||
<button on:click={close}>Close</button>
|
||||
</form>
|
||||
</dialog>
|
||||
@@ -83,6 +83,7 @@
|
||||
let deviceInfo = {};
|
||||
let invidiousInfo = {};
|
||||
let preferencesInfo = {};
|
||||
let profilesInfo = {};
|
||||
const feedbackTitle = encodeURIComponent("[Feedback] Playlet");
|
||||
let githubUrlIssue = "https://github.com/iBicha/playlet/issues/new";
|
||||
let mailToUrl = "mailto:brahim.hadriche@gmail.com";
|
||||
@@ -92,6 +93,7 @@
|
||||
deviceInfo = value.device || {};
|
||||
invidiousInfo = value.invidious || {};
|
||||
preferencesInfo = value.preferences || {};
|
||||
profilesInfo = value.profiles || {};
|
||||
githubUrlIssue = createGithubIssueUrl();
|
||||
mailToUrl = createMailToUrl();
|
||||
});
|
||||
@@ -118,6 +120,11 @@ ${JSON.stringify(invidiousInfo, null, 2)}
|
||||
#### User preferences
|
||||
\`\`\`
|
||||
${JSON.stringify(preferencesInfo, null, 2)}
|
||||
\`\`\`
|
||||
|
||||
#### Profiles
|
||||
\`\`\`
|
||||
${JSON.stringify(profilesInfo, null, 2)}
|
||||
\`\`\``;
|
||||
}
|
||||
|
||||
|
||||
@@ -9,4 +9,5 @@ export type PlayletState = {
|
||||
device?: any,
|
||||
invidious?: any,
|
||||
preferences?: any,
|
||||
profiles?: any,
|
||||
}
|
||||
@@ -84,7 +84,7 @@
|
||||
playletStateStore.subscribe((value) => {
|
||||
invidiousApi.instance = value?.invidious?.current_instance;
|
||||
invidiousApi.userCountryCode = value?.device?.user_country_code ?? "US";
|
||||
invidiousApi.isLoggedIn = value.invidious?.logged_in ?? false;
|
||||
invidiousApi.isLoggedIn = !!(value.profiles?.currentProfile ?? false);
|
||||
loadRow();
|
||||
});
|
||||
|
||||
|
||||
Reference in new issue
Block a user