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