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",
"version": "0.77.18",
"version": "0.77.19",
"description": "",
"scripts": {
"start": "vite",

View File

@ -61,7 +61,7 @@ export type AccountContextStore = {
removeFollow: (pubkey: string) => void,
quoteNote: (noteId: string | undefined) => void,
addToMuteList: (pubkey: string) => void,
removeFromMuteList: (pubkey: string) => void,
removeFromMuteList: (pubkey: string, then?: () => void) => void,
addRelay: (url: string) => void,
removeRelay: (url: string) => 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 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) {
updateStore('muted', () => muted);
updateStore('mutedSince', () => 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}`);
};
const removeFromMuteList = (pubkey: string) => {
const removeFromMuteList = (pubkey: string, then?: () => void) => {
if (!store.publicKey || !store.muted || !store.muted.includes(pubkey)) {
return;
}
@ -573,15 +574,17 @@ export function AccountProvider(props: { children: number | boolean | Node | JSX
const date = Math.floor((new Date()).getTime() / 1000);
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) {
updateStore('muted', () => muted);
updateStore('mutedSince', () => date);
saveMuted(store.publicKey, muted, date);
note && triggerImportEvents([note], `import_mute_list_remove_${APP_ID}`);
}
}
then && then();
unsub();
return;
}

View File

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

View File

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