mirror of
https://github.com/PrimalHQ/primal-web-app.git
synced 2024-10-01 17:31:13 +00:00
Refresh top zaps after zapping
This commit is contained in:
parent
8570fd4611
commit
c18249d067
@ -127,7 +127,9 @@ const CustomZap: Component<{
|
|||||||
|
|
||||||
const handleZap = (success = false) => {
|
const handleZap = (success = false) => {
|
||||||
if (success) {
|
if (success) {
|
||||||
|
setTimeout(() => {
|
||||||
props.onSuccess(selectedValue());
|
props.onSuccess(selectedValue());
|
||||||
|
}, 2_000)
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -103,6 +103,7 @@ const Note: Component<{
|
|||||||
updateReactionsState('hideZapIcon', () => false);
|
updateReactionsState('hideZapIcon', () => false);
|
||||||
updateReactionsState('zapped', () => true);
|
updateReactionsState('zapped', () => true);
|
||||||
});
|
});
|
||||||
|
threadContext?.actions.fetchTopZaps(props.note.post.id);
|
||||||
};
|
};
|
||||||
|
|
||||||
const onFailZap = (zapOption: ZapOption) => {
|
const onFailZap = (zapOption: ZapOption) => {
|
||||||
@ -168,7 +169,7 @@ const Note: Component<{
|
|||||||
return (likes || 0) + (zapCount || 0) + (reposts || 0);
|
return (likes || 0) + (zapCount || 0) + (reposts || 0);
|
||||||
};
|
};
|
||||||
|
|
||||||
const topZaps = createMemo( () => threadContext?.topZaps[props.note.post.id] || []);
|
const topZaps = () => threadContext?.topZaps[props.note.post.id] || [];
|
||||||
|
|
||||||
const firstZap = createMemo(() => topZaps()[0]);
|
const firstZap = createMemo(() => topZaps()[0]);
|
||||||
|
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
import { batch, Component, createEffect, Show } from 'solid-js';
|
import { batch, Component, createEffect, Show } from 'solid-js';
|
||||||
import { MenuItem, PrimalNote } from '../../../types/primal';
|
import { MenuItem, PrimalNote } from '../../../types/primal';
|
||||||
import { sendRepost } from '../../../lib/notes';
|
import { sendRepost, triggerImportEvents } from '../../../lib/notes';
|
||||||
|
|
||||||
import styles from './NoteFooter.module.scss';
|
import styles from './NoteFooter.module.scss';
|
||||||
import { useAccountContext } from '../../../contexts/AccountContext';
|
import { useAccountContext } from '../../../contexts/AccountContext';
|
||||||
@ -22,6 +22,7 @@ import NoteFooterActionButton from './NoteFooterActionButton';
|
|||||||
import { NoteFooterState } from '../Note';
|
import { NoteFooterState } from '../Note';
|
||||||
import { SetStoreFunction } from 'solid-js/store';
|
import { SetStoreFunction } from 'solid-js/store';
|
||||||
import BookmarkNote from '../../BookmarkNote/BookmarkNote';
|
import BookmarkNote from '../../BookmarkNote/BookmarkNote';
|
||||||
|
import { APP_ID } from '../../../App';
|
||||||
|
|
||||||
export const lottieDuration = () => zapMD.op * 1_000 / zapMD.fr;
|
export const lottieDuration = () => zapMD.op * 1_000 / zapMD.fr;
|
||||||
|
|
||||||
@ -278,19 +279,17 @@ const NoteFooter: Component<{
|
|||||||
props.updateState('isZapping', () => false);
|
props.updateState('isZapping', () => false);
|
||||||
|
|
||||||
if (success) {
|
if (success) {
|
||||||
|
setTimeout(() => {
|
||||||
props.customZapInfo.onSuccess({
|
props.customZapInfo.onSuccess({
|
||||||
emoji,
|
emoji,
|
||||||
amount,
|
amount,
|
||||||
message,
|
message,
|
||||||
});
|
});
|
||||||
|
}, 2_000);
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
batch(() => {
|
|
||||||
props.updateState('zappedAmount', () => -amount);
|
|
||||||
props.updateState('zapped', () => props.note.post.noteActions.zapped);
|
|
||||||
});
|
|
||||||
|
|
||||||
props.customZapInfo.onFail({
|
props.customZapInfo.onFail({
|
||||||
emoji,
|
emoji,
|
||||||
amount,
|
amount,
|
||||||
|
@ -68,6 +68,7 @@ export type ThreadContextStore = {
|
|||||||
updatePage: (content: NostrEventContent) => void,
|
updatePage: (content: NostrEventContent) => void,
|
||||||
savePage: (page: FeedPage) => void,
|
savePage: (page: FeedPage) => void,
|
||||||
setPrimaryNote: (context: PrimalNote | undefined) => void,
|
setPrimaryNote: (context: PrimalNote | undefined) => void,
|
||||||
|
fetchTopZaps: (noteId: string) => void,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -112,7 +113,7 @@ export const ThreadProvider = (props: { children: ContextChildren }) => {
|
|||||||
clearNotes();
|
clearNotes();
|
||||||
updateStore('noteId', noteId)
|
updateStore('noteId', noteId)
|
||||||
getThread(account?.publicKey, noteId, `thread_${APP_ID}`);
|
getThread(account?.publicKey, noteId, `thread_${APP_ID}`);
|
||||||
getEventZaps(noteId, account?.publicKey, `thread_zapps_${APP_ID}`, 10, 0);
|
fetchTopZaps(noteId);
|
||||||
updateStore('isFetching', () => true);
|
updateStore('isFetching', () => true);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -256,16 +257,20 @@ export const ThreadProvider = (props: { children: ContextChildren }) => {
|
|||||||
eventId,
|
eventId,
|
||||||
};
|
};
|
||||||
|
|
||||||
if (store.topZaps[eventId] === undefined) {
|
const oldZaps = store.topZaps[eventId];
|
||||||
|
|
||||||
|
if (oldZaps === undefined) {
|
||||||
updateStore('topZaps', () => ({ [eventId]: [{ ...zap }]}));
|
updateStore('topZaps', () => ({ [eventId]: [{ ...zap }]}));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (store.topZaps[eventId].find(i => i.id === zap.id)) {
|
if (oldZaps.find(i => i.id === zap.id)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
updateStore('topZaps', eventId, (zs) => [ ...zs, { ...zap }]);
|
const newZaps = [ ...oldZaps, { ...zap }].sort((a, b) => b.amount - a.amount);
|
||||||
|
|
||||||
|
updateStore('topZaps', eventId, () => [ ...newZaps ]);
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -283,6 +288,10 @@ export const ThreadProvider = (props: { children: ContextChildren }) => {
|
|||||||
updateStore('primaryNote', () => ({ ...context }));
|
updateStore('primaryNote', () => ({ ...context }));
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const fetchTopZaps = (noteId: string) => {
|
||||||
|
getEventZaps(noteId, account?.publicKey, `thread_zapps_${APP_ID}`, 10, 0);
|
||||||
|
};
|
||||||
|
|
||||||
// SOCKET HANDLERS ------------------------------
|
// SOCKET HANDLERS ------------------------------
|
||||||
|
|
||||||
const onMessage = (event: MessageEvent) => {
|
const onMessage = (event: MessageEvent) => {
|
||||||
@ -410,6 +419,7 @@ export const ThreadProvider = (props: { children: ContextChildren }) => {
|
|||||||
updatePage,
|
updatePage,
|
||||||
savePage,
|
savePage,
|
||||||
setPrimaryNote,
|
setPrimaryNote,
|
||||||
|
fetchTopZaps,
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user