mirror of
https://github.com/PrimalHQ/primal-web-app.git
synced 2024-10-03 02:10:55 +00:00
Fix data reload on socket reset
This commit is contained in:
parent
e9f320698c
commit
d849f984ab
@ -344,8 +344,11 @@ export const HomeProvider = (props: { children: ContextChildren }) => {
|
||||
updateStore('scrollTop', () => top);
|
||||
};
|
||||
|
||||
let currentFeed = '';
|
||||
|
||||
const selectFeed = (feed: PrimalFeed | undefined) => {
|
||||
if (feed !== undefined && feed.hex !== undefined) {
|
||||
if (feed?.hex !== undefined && feed.hex !== currentFeed) {
|
||||
currentFeed = feed.hex;
|
||||
updateStore('selectedFeed', reconcile({...feed}));
|
||||
clearNotes();
|
||||
fetchNotes(feed.hex , `${APP_ID}`, 0, feed.includeReplies);
|
||||
@ -623,8 +626,11 @@ export const HomeProvider = (props: { children: ContextChildren }) => {
|
||||
}
|
||||
});
|
||||
|
||||
let keyIsDone = false;
|
||||
|
||||
createEffect(() => {
|
||||
if (account?.isKeyLookupDone) {
|
||||
if (account?.isKeyLookupDone && !keyIsDone && settings?.defaultFeed) {
|
||||
keyIsDone = true;
|
||||
selectFeed(settings?.defaultFeed);
|
||||
}
|
||||
});
|
||||
|
@ -564,10 +564,12 @@ export const MessagesProvider = (props: { children: ContextChildren }) => {
|
||||
|
||||
|
||||
const orderedSenders = () => {
|
||||
if (!store.senders) {
|
||||
const senders = store.senders;
|
||||
|
||||
if (!senders) {
|
||||
return [];
|
||||
}
|
||||
const senders = store.senders;
|
||||
|
||||
const counts = store.messageCountPerSender;
|
||||
|
||||
const ids = Object.keys(senders);
|
||||
@ -797,8 +799,11 @@ export const MessagesProvider = (props: { children: ContextChildren }) => {
|
||||
}
|
||||
});
|
||||
|
||||
let isSecSet = false
|
||||
|
||||
createEffect(() => {
|
||||
if (!account?.sec) {
|
||||
if (!account?.sec && !isSecSet) {
|
||||
isSecSet = true;
|
||||
unsubscribeToMessagesStats(subidMsgCount);
|
||||
updateStore('messageCount', () => 0);
|
||||
updateStore('messageCountPerSender', reconcile({}));
|
||||
@ -818,9 +823,12 @@ export const MessagesProvider = (props: { children: ContextChildren }) => {
|
||||
updateStore('now', () => Math.floor((new Date()).getTime() / 1000));
|
||||
};
|
||||
|
||||
let currentSender = '';
|
||||
|
||||
// When a sender is selected, get the first page of the conversation
|
||||
createEffect(() => {
|
||||
if (store.selectedSender) {
|
||||
if (store.selectedSender && store.selectedSender !== currentSender) {
|
||||
currentSender = store.selectedSender;
|
||||
clearInterval(conversationRefreshInterval);
|
||||
|
||||
updateStore('encryptedMessages', () => []);
|
||||
|
@ -96,8 +96,6 @@ const Home: Component = () => {
|
||||
}
|
||||
|
||||
setNewNotesCount(count);
|
||||
|
||||
|
||||
});
|
||||
|
||||
onCleanup(()=> {
|
||||
|
@ -105,8 +105,11 @@ const Profile: Component = () => {
|
||||
profile?.actions.clearZaps();
|
||||
}
|
||||
|
||||
let keyIsDone = false
|
||||
|
||||
createEffect(() => {
|
||||
if (account?.isKeyLookupDone) {
|
||||
if (account?.isKeyLookupDone && !keyIsDone) {
|
||||
keyIsDone = true;
|
||||
setProfile(getHex());
|
||||
}
|
||||
});
|
||||
|
@ -32,6 +32,8 @@ const Thread: Component = () => {
|
||||
|
||||
let repliesHolder: HTMLDivElement | undefined;
|
||||
|
||||
let initialPostId = '';
|
||||
|
||||
const postId = () => {
|
||||
if (params.postId.startsWith('note')) {
|
||||
return params.postId;
|
||||
@ -95,7 +97,12 @@ const Thread: Component = () => {
|
||||
const isFetching = () => threadContext?.isFetching;
|
||||
|
||||
createEffect(() => {
|
||||
threadContext?.actions.fetchNotes(postId());
|
||||
const pid = postId();
|
||||
|
||||
if (pid !== initialPostId) {
|
||||
threadContext?.actions.fetchNotes(pid);
|
||||
initialPostId = pid;
|
||||
}
|
||||
});
|
||||
|
||||
let observer: IntersectionObserver | undefined;
|
||||
|
@ -13,9 +13,9 @@ const onOpen = () => {
|
||||
const hook = (window as PrimalWindow).onPrimalCacheServerConnected;
|
||||
hook && hook(cacheServer, socket());
|
||||
|
||||
socket().addEventListener('message', function(event) {
|
||||
const hook = (window as PrimalWindow).onPrimalCacheServerMessageReceived;
|
||||
hook && hook(cacheServer, event.data);
|
||||
socket()?.addEventListener('message', function(event) {
|
||||
const hook = (window as PrimalWindow).onPrimalCacheServerMessageReceived;
|
||||
hook && hook(cacheServer, event.data);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
2
src/types/primal.d.ts
vendored
2
src/types/primal.d.ts
vendored
@ -277,6 +277,8 @@ export type FeedPage = {
|
||||
postStats: NostrPostStats,
|
||||
mentions?: Record<string, NostrNoteContent>,
|
||||
noteActions: Record<string, NoteActions>,
|
||||
since?: number,
|
||||
until?: number,
|
||||
};
|
||||
|
||||
export type TrendingNotesStore = {
|
||||
|
Loading…
Reference in New Issue
Block a user