Don't clear Invidious instance or login on instance changed
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
import { localDb } from '$lib/dexie';
|
||||
import { logoutStores } from '$lib/misc';
|
||||
import { clearCaches } from '$lib/misc';
|
||||
import { cleanNumber } from '$lib/numbers';
|
||||
import { relativeTimestamp } from '$lib/time';
|
||||
import { get } from 'svelte/store';
|
||||
@@ -44,7 +44,7 @@ export async function postSubscribeYTjs(authorId: string) {
|
||||
export async function deleteUnsubscribeYTjs(authorId: string) {
|
||||
await localDb.channelSubscriptions.where('channelId').equals(authorId).delete();
|
||||
await localDb.subscriptionFeed.where('authorId').equals(authorId).delete();
|
||||
logoutStores();
|
||||
clearCaches();
|
||||
}
|
||||
|
||||
export async function parseChannelRSS(channelId: string): Promise<void> {
|
||||
|
||||
@@ -11,7 +11,7 @@
|
||||
import type { RgbaColor, HsvaColor, Colord } from 'colord';
|
||||
import { _ } from '$lib/i18n';
|
||||
import { get } from 'svelte/store';
|
||||
import { ensureNoTrailingSlash, isMobile, logoutStores } from '../../misc';
|
||||
import { ensureNoTrailingSlash, isMobile, clearCaches } from '../../misc';
|
||||
import { getPages, type Pages } from '../../navPages';
|
||||
import ColorPicker from 'svelte-awesome-color-picker';
|
||||
import {
|
||||
@@ -75,8 +75,8 @@
|
||||
}
|
||||
}
|
||||
|
||||
function clearPreviousInstance() {
|
||||
logoutStores();
|
||||
function reloadState() {
|
||||
clearCaches();
|
||||
ui('#dialog-settings');
|
||||
goto(resolve('/', {}), { replaceState: true });
|
||||
location.reload();
|
||||
@@ -113,13 +113,14 @@
|
||||
|
||||
instanceStore.set(instance);
|
||||
|
||||
clearPreviousInstance();
|
||||
reloadState();
|
||||
authStore.set(null);
|
||||
}
|
||||
|
||||
async function setBackend(event: Event) {
|
||||
const select = event.target as HTMLSelectElement;
|
||||
backendInUseStore.set(select.value as 'ivg' | 'yt');
|
||||
clearPreviousInstance();
|
||||
reloadState();
|
||||
}
|
||||
|
||||
function allowInsecureRequests() {
|
||||
|
||||
@@ -233,8 +233,7 @@ export function isYTBackend(): boolean {
|
||||
return get(backendInUseStore) === 'yt' && Capacitor.isNativePlatform();
|
||||
}
|
||||
|
||||
export function logoutStores() {
|
||||
authStore.set(null);
|
||||
export function clearCaches() {
|
||||
feedCacheStore.set({});
|
||||
searchCacheStore.set({});
|
||||
playlistCacheStore.set({});
|
||||
|
||||
@@ -1,12 +1,13 @@
|
||||
import { _ } from '$lib/i18n';
|
||||
import { get } from 'svelte/store';
|
||||
import { isYTBackend } from './misc';
|
||||
import { authStore } from './store';
|
||||
|
||||
export type Pages = { icon: string; href: string; name: string; requiresAuth: boolean }[];
|
||||
|
||||
// Must be a func do to how i18n is loaded
|
||||
export function getPages(): Pages {
|
||||
return [
|
||||
let pages: Pages = [
|
||||
{
|
||||
icon: 'home',
|
||||
href: !isYTBackend() ? '/' : '/subscriptions',
|
||||
@@ -26,4 +27,10 @@ export function getPages(): Pages {
|
||||
requiresAuth: true
|
||||
}
|
||||
];
|
||||
|
||||
pages = pages.filter((page) => {
|
||||
return !page.requiresAuth || (get(authStore) && !isYTBackend());
|
||||
});
|
||||
|
||||
return pages;
|
||||
}
|
||||
|
||||
@@ -39,7 +39,7 @@
|
||||
import { _ } from '$lib/i18n';
|
||||
import { get } from 'svelte/store';
|
||||
import { pwaInfo } from 'virtual:pwa-info';
|
||||
import { isYTBackend, logoutStores, truncate } from '$lib/misc';
|
||||
import { isYTBackend, clearCaches, truncate } from '$lib/misc';
|
||||
import Author from '$lib/components/Author.svelte';
|
||||
import Toast from '$lib/components/Toast.svelte';
|
||||
|
||||
@@ -179,7 +179,8 @@
|
||||
}
|
||||
|
||||
function logout() {
|
||||
logoutStores();
|
||||
authStore.set(null);
|
||||
clearCaches();
|
||||
goto(resolve('/', {}));
|
||||
}
|
||||
|
||||
@@ -269,12 +270,10 @@
|
||||
</a>
|
||||
{/if}
|
||||
{#each getPages() as navPage (navPage)}
|
||||
{#if !navPage.requiresAuth || isLoggedIn}
|
||||
<a href={resolve(navPage.href, {})} class:active={$page.url.href.endsWith(navPage.href)}
|
||||
><i>{navPage.icon}</i>
|
||||
<div>{navPage.name}</div>
|
||||
</a>
|
||||
{/if}
|
||||
<a href={resolve(navPage.href, {})} class:active={$page.url.href.endsWith(navPage.href)}
|
||||
><i>{navPage.icon}</i>
|
||||
<div>{navPage.name}</div>
|
||||
</a>
|
||||
{/each}
|
||||
{#if $isAndroidTvStore}
|
||||
<div class="divider"></div>
|
||||
@@ -387,16 +386,14 @@
|
||||
|
||||
<nav class="bottom s">
|
||||
{#each getPages() as navPage (navPage)}
|
||||
{#if !navPage.requiresAuth || isLoggedIn}
|
||||
<a
|
||||
class="round"
|
||||
href={resolve(navPage.href, {})}
|
||||
class:active={$page.url.href.endsWith(navPage.href)}
|
||||
data-sveltekit-preload-data="off"
|
||||
><i>{navPage.icon}</i>
|
||||
<span style="font-size: .8em;">{navPage.name}</span>
|
||||
</a>
|
||||
{/if}
|
||||
<a
|
||||
class="round"
|
||||
href={resolve(navPage.href, {})}
|
||||
class:active={$page.url.href.endsWith(navPage.href)}
|
||||
data-sveltekit-preload-data="off"
|
||||
><i>{navPage.icon}</i>
|
||||
<span style="font-size: .8em;">{navPage.name}</span>
|
||||
</a>
|
||||
{/each}
|
||||
</nav>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user