diff --git a/src/stores/saved-instances.ts b/src/stores/saved-instances.ts index d43db7d..4672208 100644 --- a/src/stores/saved-instances.ts +++ b/src/stores/saved-instances.ts @@ -1,4 +1,5 @@ import { persistentAtom } from "@nanostores/persistent"; +import { getUrlDomain } from "@scripts/util"; const LOCAL_STORAGE_KEY = "recentInstances"; const RECENT_INSTANCES_SIZE = 5; @@ -8,14 +9,25 @@ export const savedInstances = persistentAtom>( new Set(), { encode: (set) => JSON.stringify([...set]), - decode: (value) => new Set(JSON.parse(value)), + decode: (value) => { + return new Set( + // XXX: The conversion to a domain need to be done to support legacy + // users, who may have full URLs in their Storage + JSON.parse(value).map((instanceUrl: string) => + getUrlDomain(instanceUrl), + ), + ); + }, }, ); export const saveInstance = (instance: string) => { savedInstances.set( new Set( - [instance, ...savedInstances.get()].slice(0, RECENT_INSTANCES_SIZE), + [getUrlDomain(instance), ...savedInstances.get()].slice( + 0, + RECENT_INSTANCES_SIZE, + ), ), ); };