diff --git a/src/contexts/ProfileContext.tsx b/src/contexts/ProfileContext.tsx index 9dd32fb..229ef5e 100644 --- a/src/contexts/ProfileContext.tsx +++ b/src/contexts/ProfileContext.tsx @@ -7,6 +7,7 @@ import { createContext, createEffect, onCleanup, + onMount, useContext } from "solid-js"; import { @@ -52,6 +53,7 @@ import { subscribeTo } from "../sockets"; import { parseBolt11 } from "../utils"; import { convertToUser } from "../stores/profile"; import { sortBreakpoints } from "@solid-primitives/media"; +import { readRecomendedUsers, saveRecomendedUsers } from "../lib/localStore"; export type UserStats = { pubkey: string, @@ -916,6 +918,7 @@ export const ProfileProvider = (props: { children: ContextChildren }) => { list.splice(index, 1); updateStore('profileHistory', 'profiles', () => [user, ...list]); + return; } @@ -1151,6 +1154,21 @@ export const ProfileProvider = (props: { children: ContextChildren }) => { } }); + createEffect(() => { + if (account && account.hasPublicKey()) { + const history = readRecomendedUsers(account.publicKey); + + history && updateStore('profileHistory', reconcile(history)); + } + }); + + createEffect(() => { + const profiles = [...store.profileHistory.profiles]; + const stats = { ...store.profileHistory.stats }; + + saveRecomendedUsers(account?.publicKey, { profiles, stats }); + }); + onCleanup(() => { removeSocketListeners( socket(), diff --git a/src/lib/localStore.ts b/src/lib/localStore.ts index a4efa9e..e51b687 100644 --- a/src/lib/localStore.ts +++ b/src/lib/localStore.ts @@ -1,3 +1,4 @@ +import { UserStats } from "../contexts/ProfileContext"; import { NostrRelays, PrimalFeed, PrimalUser, SelectionOption } from "../types/primal"; export type LocalStore = { @@ -12,6 +13,10 @@ export type LocalStore = { theme: string, homeSidebarSelection: SelectionOption | undefined, userProfile: PrimalUser | undefined, + recomended: { + profiles: PrimalUser[], + stats: Record, + }, }; export const emptyStorage = { @@ -26,6 +31,7 @@ export const emptyStorage = { theme: 'sunset', homeSidebarSelection: undefined, userProfile: undefined, + recomended: { profiles: [], stats: {} }, } export const storageName = (pubkey?: string) => { @@ -146,6 +152,30 @@ export const saveTheme = (pubkey: string | undefined, theme: string) => { setStorage(pubkey, store); }; +export const saveRecomendedUsers = (pubkey: string | undefined, recomended: { profiles: PrimalUser[], stats: Record }) => { + if (!pubkey) { + return; + } + + const store = getStorage(pubkey); + + store.recomended = recomended; + + setStorage(pubkey, store); +} + +export const readRecomendedUsers = (pubkey: string | undefined) => { + if (!pubkey) { + return; + } + + const store = getStorage(pubkey); + + const recomended = store.recomended; + + return recomended ? recomended as { profiles: PrimalUser[], stats: Record } : undefined; +} + export const saveHomeSidebarSelection = (pubkey: string | undefined, selection: SelectionOption | undefined) => { if (!pubkey) { return;