Skip to content

Commit

Permalink
problem: we lose our shortlist on navigation changes
Browse files Browse the repository at this point in the history
  • Loading branch information
gsovereignty committed May 1, 2024
1 parent 0fae9f2 commit bcde51f
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 28 deletions.
1 change: 0 additions & 1 deletion src/lib/ndk/Login.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
} else {
if ((user && user.pubkey && user.pubkey != $currentUser?.pubkey) || !$currentUser) {
currentUser.update((cu) => {
console.log(19)
cu = user || undefined;
return cu;
});
Expand Down
1 change: 0 additions & 1 deletion src/lib/snort_workers/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ export async function Init(pubkey?:string) {
}

export function UpdatePubkey(pubkey:string) {
console.log(33)
if (worker) {
worker.terminate()
}
Expand Down
10 changes: 8 additions & 2 deletions src/lib/stores/shortlist.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
import type { NostrEvent } from "nostr-tools";
import { writable, type Readable, type Writable } from "svelte/store";
import { derived, writable, type Readable, type Writable } from "svelte/store";

export let shortListLength: Readable<number>;

let _stableShortlist: NostrEvent[] = [];
export let stableShortList: Writable<NostrEvent[]> = writable(_stableShortlist);
export let stableShortList: Writable<NostrEvent[]> = writable(_stableShortlist);

export let threadParentIDChain = writable(['root']);

export let threadParentID = derived(threadParentIDChain, ($tpi) => {
return $tpi[$tpi.length - 1];
});
44 changes: 20 additions & 24 deletions src/lib/views/messages/Messages.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import { currentUser, ndk } from '@/ndk/ndk';
import { PushEvent, UpdatePubkey, FrontendDataStore as feds, viewed } from '@/snort_workers/main';
import { updateRepliesInPlace } from '@/snort_workers/utils';
import { stableShortList } from '@/stores/shortlist';
import { stableShortList, threadParentID, threadParentIDChain } from '@/stores/shortlist';
import { NDKEvent } from '@nostr-dev-kit/ndk';
import { RequestBuilder, type QueryLike } from '@snort/system';
import { BloomFilter } from 'bloomfilter';
Expand All @@ -26,37 +26,33 @@
return $feds;
});
let threadParentIDChain = writable(['root']);
function pop() {
threadParentIDChain.update((existing) => {
existing.pop();
return existing;
});
}
let threadParentID = derived(threadParentIDChain, ($tpi) => {
return $tpi[$tpi.length - 1];
});
let renderQueue = derived([FrontendDataStore, threadParentID], ([$fds, $parentID]) => {
if ($parentID == 'root') {
let spliced: string[] = []
let spliced: string[] = [];
let maxLength = Math.max($fds.rootsByKeyword.length, $fds.rootsByReplies.length);
for (let i = 0; i < maxLength; i++) {
if (i < $fds.rootsByKeyword.length) {
spliced.push($fds.rootsByKeyword[i])
spliced.push($fds.rootsByKeyword[i]);
}
if (i < $fds.rootsByReplies.length) {
spliced.push($fds.rootsByReplies[i])
spliced.push($fds.rootsByReplies[i]);
}
}
spliced = [...new Set(spliced)]
spliced = [...new Set(spliced)];
let r = Array.from(spliced, (r) => {
return $fds.events.get(r);
});
let r = Array.from(spliced, (r)=>{return $fds.events.get(r)})
//console.log(r.length)
return r
return r;
} else {
let workerSet = $fds.replies.get($parentID);
let fullSet = new Map<string, NostrEvent>();
Expand All @@ -77,11 +73,14 @@
}
});
let q: QueryLike;
let firstRun = true;
threadParentID.subscribe((parentID) => {
if (firstRun) {
firstRun = false
} else {
stableShortList.set([]);
if (parentID != 'root' && parentID.length == 64) {
if (q) {
Expand Down Expand Up @@ -109,6 +108,7 @@
});
})();
}
}
});
renderQueue.subscribe((q) => {});
Expand Down Expand Up @@ -166,8 +166,6 @@
}
let eventID: string;
</script>

<div class=" hidden">{$shortListLength}</div>
Expand All @@ -180,9 +178,7 @@
<slot>
{#if $stableShortList.length > 0 || $threadParentID != 'root'}
{#if $threadParentID != 'root'}
<RenderKind1AsThreadHead
note={$FrontendDataStore.events.get($threadParentID)}
/>
<RenderKind1AsThreadHead note={$FrontendDataStore.events.get($threadParentID)} />
{/if}
{#each $stableShortList as event, i (event.id)}<RenderKind1
isTop={event.id == $stableShortList[0].id && $threadParentID == 'root'}
Expand Down Expand Up @@ -268,9 +264,9 @@
<br />
<h3>Your Keyword Ranks</h3>
<div class="overflow-y-scroll max-h-48">
{#each [...$FrontendDataStore.keywords].sort(([sa, a], [sb, b]) => {
return b - a;
}) as [word, count]}{word}: {count} <br />{/each}
{#each [...$FrontendDataStore.keywords].sort(([sa, a], [sb, b]) => {
return b - a;
}) as [word, count]}{word}: {count} <br />{/each}
</div>
<div>
<br />
Expand Down

0 comments on commit bcde51f

Please sign in to comment.