Fix displaying double notes on profile page

This commit is contained in:
Bojan Mojsilovic 2023-08-31 17:07:14 +02:00
parent eba95df646
commit a8c46af0e2
4 changed files with 21 additions and 18 deletions

View File

@ -1,6 +1,6 @@
{ {
"name": "primal-web-app", "name": "primal-web-app",
"version": "0.77.18", "version": "0.77.19",
"description": "", "description": "",
"scripts": { "scripts": {
"start": "vite", "start": "vite",

View File

@ -61,7 +61,7 @@ export type AccountContextStore = {
removeFollow: (pubkey: string) => void, removeFollow: (pubkey: string) => void,
quoteNote: (noteId: string | undefined) => void, quoteNote: (noteId: string | undefined) => void,
addToMuteList: (pubkey: string) => void, addToMuteList: (pubkey: string) => void,
removeFromMuteList: (pubkey: string) => void, removeFromMuteList: (pubkey: string, then?: () => void) => void,
addRelay: (url: string) => void, addRelay: (url: string) => void,
removeRelay: (url: string) => void, removeRelay: (url: string) => void,
setConnectToPrimaryRelays: (flag: boolean) => void, setConnectToPrimaryRelays: (flag: boolean) => void,
@ -536,12 +536,13 @@ export function AccountProvider(props: { children: number | boolean | Node | JSX
const date = Math.floor((new Date()).getTime() / 1000); const date = Math.floor((new Date()).getTime() / 1000);
const muted = [...store.muted, pubkey]; const muted = [...store.muted, pubkey];
const { success } = await sendMuteList(muted, date, content?.content || '', store.relays, store.relaySettings); const { success, note } = await sendMuteList(muted, date, content?.content || '', store.relays, store.relaySettings);
if (success) { if (success) {
updateStore('muted', () => muted); updateStore('muted', () => muted);
updateStore('mutedSince', () => date); updateStore('mutedSince', () => date);
saveMuted(store.publicKey, muted, date); saveMuted(store.publicKey, muted, date);
note && triggerImportEvents([note], `import_mutelists_event_add_${APP_ID}`);
} }
} }
@ -561,7 +562,7 @@ export function AccountProvider(props: { children: number | boolean | Node | JSX
getProfileMuteList(store.publicKey, `before_mute_${APP_ID}`); getProfileMuteList(store.publicKey, `before_mute_${APP_ID}`);
}; };
const removeFromMuteList = (pubkey: string) => { const removeFromMuteList = (pubkey: string, then?: () => void) => {
if (!store.publicKey || !store.muted || !store.muted.includes(pubkey)) { if (!store.publicKey || !store.muted || !store.muted.includes(pubkey)) {
return; return;
} }
@ -573,15 +574,17 @@ export function AccountProvider(props: { children: number | boolean | Node | JSX
const date = Math.floor((new Date()).getTime() / 1000); const date = Math.floor((new Date()).getTime() / 1000);
const muted = store.muted.filter(m => m !== pubkey); const muted = store.muted.filter(m => m !== pubkey);
const { success } = await sendMuteList(muted, date, content?.content || '', store.relays, store.relaySettings); const { success, note } = await sendMuteList(muted, date, content?.content || '', store.relays, store.relaySettings);
if (success) { if (success) {
updateStore('muted', () => muted); updateStore('muted', () => muted);
updateStore('mutedSince', () => date); updateStore('mutedSince', () => date);
saveMuted(store.publicKey, muted, date); saveMuted(store.publicKey, muted, date);
note && triggerImportEvents([note], `import_mute_list_remove_${APP_ID}`);
} }
} }
then && then();
unsub(); unsub();
return; return;
} }

View File

@ -129,7 +129,6 @@ export const ProfileProvider = (props: { children: ContextChildren }) => {
const saveNotes = (newNotes: PrimalNote[], scope?: 'future') => { const saveNotes = (newNotes: PrimalNote[], scope?: 'future') => {
if (scope) { if (scope) {
console.log('SAVED NEW NOTES ', newNotes);
updateStore(scope, 'notes', (notes) => [ ...notes, ...newNotes ]); updateStore(scope, 'notes', (notes) => [ ...notes, ...newNotes ]);
loadFutureContent(); loadFutureContent();
return; return;
@ -226,7 +225,6 @@ export const ProfileProvider = (props: { children: ContextChildren }) => {
if (store.future.notes.length === 0) { if (store.future.notes.length === 0) {
return; return;
} }
console.log('loadFutureContent', store.future.notes);
updateStore('notes', (notes) => [...store.future.notes, ...notes]); updateStore('notes', (notes) => [...store.future.notes, ...notes]);
clearFuture(); clearFuture();

View File

@ -192,17 +192,17 @@ const Profile: Component = () => {
return account?.publicKey === profile?.profileKey; return account?.publicKey === profile?.profileKey;
}; };
createEffect(() => { // createEffect(() => {
const pk = getHex(); // const pk = getHex();
if (!pk) { // if (!pk) {
return; // return;
} // }
if (!isMuted(pk) && account?.isKeyLookupDone) { // if (!isMuted(pk) && account?.isKeyLookupDone) {
profile?.actions.fetchNotes(pk); // profile?.actions.fetchNotes(pk);
} // }
}); // });
createEffect(() => { createEffect(() => {
const pk = getHex(); const pk = getHex();
@ -233,7 +233,7 @@ const Profile: Component = () => {
return; return;
} }
account.actions.removeFromMuteList(profile.profileKey); account.actions.removeFromMuteList(profile.profileKey, () => setProfile(profile.profileKey));
}; };
const isFollowingMute = (pk: string | undefined) => { const isFollowingMute = (pk: string | undefined) => {
@ -667,7 +667,9 @@ const Profile: Component = () => {
<Note note={note} /> <Note note={note} />
)} )}
</For> </For>
<Paginator loadNextPage={profile?.actions.fetchNextPage}/> <Paginator loadNextPage={() => {
profile?.actions.fetchNextPage();
}}/>
</Match> </Match>
</Switch> </Switch>
</div> </div>