Refreash data on profile change

This commit is contained in:
Bojan Mojsilovic 2024-02-28 13:37:04 +01:00
parent a549f7125a
commit 7837453e8f
5 changed files with 20 additions and 24 deletions

View File

@ -25,7 +25,6 @@ import styles from "./ProfileTabs.module.scss";
const ProfileTabs: Component<{
id?: string,
profile: PrimalUser | undefined,
setProfile?: (pk: string) => void,
}> = (props) => {
@ -124,33 +123,33 @@ const ProfileTabs: Component<{
}
const onChangeValue = (value: string) => {
if (!props.profile) return;
if (!profile) return;
switch(value) {
case 'notes':
profile?.notes.length === 0 &&profile?.actions.fetchNotes(props.profile.pubkey);
profile.notes.length === 0 && profile.actions.fetchNotes(profile.profileKey);
break;
case 'replies':
profile?.replies.length === 0 && profile?.actions.fetchReplies(props.profile.pubkey);
profile.replies.length === 0 && profile.actions.fetchReplies(profile.profileKey);
break;
case 'follows':
profile?.contacts.length === 0 && profile?.actions.fetchContactList(props.profile.pubkey);
profile.contacts.length === 0 && profile.actions.fetchContactList(profile.profileKey);
break;
case 'followers':
profile?.followers.length === 0 && profile?.actions.fetchFollowerList(props.profile.pubkey);
profile.followers.length === 0 && profile.actions.fetchFollowerList(profile.profileKey);
break;
case 'zaps':
profile?.zaps.length === 0 && profile?.actions.fetchZapList(props.profile.pubkey);
profile.zaps.length === 0 && profile.actions.fetchZapList(profile.profileKey);
break;
case 'relays':
Object.keys(profile?.relays || {}).length === 0 && profile?.actions.fetchRelayList(props.profile.pubkey);
Object.keys(profile.relays || {}).length === 0 && profile.actions.fetchRelayList(profile.profileKey);
break;
}
};
return (
<Show
when={profile && props.profile && profile.fetchedUserStats}
when={profile && profile.fetchedUserStats}
fallback={<div class={styles.profileTabsPlaceholder}></div>}
>
<Tabs.Root onChange={onChangeValue}>

View File

@ -157,6 +157,8 @@ export function AccountProvider(props: { children: JSXElement }) {
if (key === storedKey) return;
updateStore('isKeyLookupDone', () => false);
setPublicKey(key);
// Read profile from storage
@ -219,7 +221,7 @@ export function AccountProvider(props: { children: JSXElement }) {
const setPublicKey = (pubkey: string | undefined) => {
updateStore('publicKey', () => pubkey);
pubkey ? localStorage.setItem('pubkey', pubkey) : localStorage.removeItem('pubkey');
updateStore('isKeyLookupDone', true);
updateStore('isKeyLookupDone', () => true);
};
const hasPublicKey: () => boolean = () => {
@ -1157,7 +1159,7 @@ export function AccountProvider(props: { children: JSXElement }) {
};
const checkNostrKey = () => {
updateStore('isKeyLookupDone', false);
updateStore('isKeyLookupDone', () => false);
fetchNostrKey();
};

View File

@ -626,11 +626,8 @@ export const HomeProvider = (props: { children: ContextChildren }) => {
}
});
let keyIsDone = false;
createEffect(() => {
if (account?.isKeyLookupDone && !keyIsDone && settings?.defaultFeed) {
keyIsDone = true;
if (account?.isKeyLookupDone && settings?.defaultFeed) {
selectFeed(settings?.defaultFeed);
}
});

View File

@ -456,14 +456,14 @@ export const SettingsProvider = (props: { children: ContextChildren }) => {
const feedLatest = {
name: feedLatestLabel,
hex: publicKey,
npub: hexToNpub(publicKey),
hex: account?.publicKey,
npub: hexToNpub(account?.publicKey),
};
const feedLatestWithReplies = {
name: feedLatestWithRepliesLabel,
hex: publicKey,
npub: hexToNpub(publicKey),
hex: account?.publicKey,
npub: hexToNpub(account?.publicKey),
includeReplies: true,
};
@ -560,7 +560,7 @@ export const SettingsProvider = (props: { children: ContextChildren }) => {
const feedLatestLabel = intl.formatMessage(t.feedLatest);
const feedLatestWithRepliesLabel = intl.formatMessage(t.feedLatestWithReplies);
let publicKey: string | undefined;
// let publicKey: string | undefined;
// Initial setup for a user with a public key
createEffect(() => {
@ -569,9 +569,7 @@ export const SettingsProvider = (props: { children: ContextChildren }) => {
return;
}
if (publicKey) return;
publicKey = account?.publicKey;
const publicKey = account?.publicKey;
const initFeeds = initAvailableFeeds(publicKey);

View File

@ -665,7 +665,7 @@ const Profile: Component = () => {
</Show>
</div>
<ProfileTabs profile={profile?.userProfile}/>
<ProfileTabs />
<ConfirmModal
open={confirmReportUser()}