mirror of
https://github.com/PrimalHQ/primal-web-app.git
synced 2024-10-03 02:10:55 +00:00
Persist profile history
This commit is contained in:
parent
0218a2647d
commit
e9f320698c
@ -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(),
|
||||
|
@ -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<string, UserStats>,
|
||||
},
|
||||
};
|
||||
|
||||
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<string, UserStats> }) => {
|
||||
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<string, UserStats> } : undefined;
|
||||
}
|
||||
|
||||
export const saveHomeSidebarSelection = (pubkey: string | undefined, selection: SelectionOption | undefined) => {
|
||||
if (!pubkey) {
|
||||
return;
|
||||
|
Loading…
Reference in New Issue
Block a user