From 7a8b47340621d7d03e85cd3302e2ae38b9a11fa0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?marcin=20miko=C5=82ajczak?= Date: Wed, 10 Apr 2024 00:03:18 +0200 Subject: [PATCH] Fix instance persistence in indexeddb MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: marcin mikołajczak --- src/reducers/instance.ts | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/reducers/instance.ts b/src/reducers/instance.ts index c91bf6107..3425ff37f 100644 --- a/src/reducers/instance.ts +++ b/src/reducers/instance.ts @@ -72,25 +72,26 @@ const handleAuthFetch = (state: Instance) => { }; }; -const getHost = (instance: { uri: string }) => { +const getHost = (instance: { uri?: string; domain?: string }) => { + const domain = instance.uri || instance.domain as string; try { - return new URL(instance.uri).host; + return new URL(domain).host; } catch { try { - return new URL(`https://${instance.uri}`).host; + return new URL(`https://${domain}`).host; } catch { return null; } } }; -const persistInstance = (instance: { uri: string }, host: string | null = getHost(instance)) => { +const persistInstance = ({ instance }: { instance: { uri: string } }, host: string | null = getHost(instance)) => { if (host) { KVStore.setItem(`instance:${host}`, instance).catch(console.error); } }; -const persistInstanceV2 = (instance: { uri: string }, host: string | null = getHost(instance)) => { +const persistInstanceV2 = ({ instance }: { instance: { domain: string } }, host: string | null = getHost(instance)) => { if (host) { KVStore.setItem(`instanceV2:${host}`, instance).catch(console.error); }