bug: feed loading
This commit is contained in:
parent
6219626ba0
commit
46fc4500d7
@ -1,12 +1,14 @@
|
|||||||
import { useEffect } from "react";
|
import { useEffect, useState } from "react";
|
||||||
|
|
||||||
import Timeline from "Element/Timeline";
|
import Timeline from "Element/Timeline";
|
||||||
import { TaskList } from "Tasks/TaskList";
|
import { TaskList } from "Tasks/TaskList";
|
||||||
import useLogin from "Hooks/useLogin";
|
import useLogin from "Hooks/useLogin";
|
||||||
import { markNotificationsRead } from "Login";
|
import { markNotificationsRead } from "Login";
|
||||||
|
import { unixNow } from "Util";
|
||||||
|
|
||||||
export default function NotificationsPage() {
|
export default function NotificationsPage() {
|
||||||
const login = useLogin();
|
const login = useLogin();
|
||||||
|
const [now] = useState(unixNow());
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
markNotificationsRead(login);
|
markNotificationsRead(login);
|
||||||
@ -24,6 +26,8 @@ export default function NotificationsPage() {
|
|||||||
items: [login.publicKey],
|
items: [login.publicKey],
|
||||||
discriminator: login.publicKey.slice(0, 12),
|
discriminator: login.publicKey.slice(0, 12),
|
||||||
}}
|
}}
|
||||||
|
now={now}
|
||||||
|
window={60 * 60 * 12}
|
||||||
postsOnly={false}
|
postsOnly={false}
|
||||||
method={"TIME_RANGE"}
|
method={"TIME_RANGE"}
|
||||||
/>
|
/>
|
||||||
|
@ -65,19 +65,23 @@ class ProfileLoaderService {
|
|||||||
|
|
||||||
const q = System.Query<PubkeyReplaceableNoteStore>(PubkeyReplaceableNoteStore, sub);
|
const q = System.Query<PubkeyReplaceableNoteStore>(PubkeyReplaceableNoteStore, sub);
|
||||||
// never release this callback, it will stop firing anyway after eose
|
// never release this callback, it will stop firing anyway after eose
|
||||||
const releaseOnEvent = q.onEvent(e => this.onProfileEvent(e));
|
const releaseOnEvent = q.onEvent(async e => {
|
||||||
|
await this.onProfileEvent(e);
|
||||||
|
});
|
||||||
const results = await new Promise<Readonly<Array<TaggedRawEvent>>>(resolve => {
|
const results = await new Promise<Readonly<Array<TaggedRawEvent>>>(resolve => {
|
||||||
let timeout: ReturnType<typeof setTimeout> | undefined = undefined;
|
let timeout: ReturnType<typeof setTimeout> | undefined = undefined;
|
||||||
const release = q.hook(() => {
|
const release = q.hook(() => {
|
||||||
if (!q.loading) {
|
if (!q.loading) {
|
||||||
clearTimeout(timeout);
|
clearTimeout(timeout);
|
||||||
resolve(q.getSnapshotData() ?? []);
|
resolve(q.getSnapshotData() ?? []);
|
||||||
|
console.debug("Profiles finished: ", sub.id);
|
||||||
|
release();
|
||||||
}
|
}
|
||||||
release();
|
|
||||||
});
|
});
|
||||||
timeout = setTimeout(() => {
|
timeout = setTimeout(() => {
|
||||||
release();
|
release();
|
||||||
resolve(q.getSnapshotData() ?? []);
|
resolve(q.getSnapshotData() ?? []);
|
||||||
|
console.debug("Profiles timeout: ", sub.id);
|
||||||
}, 5_000);
|
}, 5_000);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -1,18 +1,23 @@
|
|||||||
import { Connection } from "@snort/nostr";
|
import { Connection } from "@snort/nostr";
|
||||||
import { Query } from "./Query";
|
import { Query } from "./Query";
|
||||||
import { getRandomValues } from "crypto";
|
import { getRandomValues } from "crypto";
|
||||||
|
import { FlatNoteStore } from "./NoteCollection";
|
||||||
|
|
||||||
window.crypto = {} as any;
|
window.crypto = {} as any;
|
||||||
window.crypto.getRandomValues = getRandomValues as any;
|
window.crypto.getRandomValues = getRandomValues as any;
|
||||||
|
|
||||||
describe("query", () => {
|
describe("query", () => {
|
||||||
test("progress", () => {
|
test("progress", () => {
|
||||||
const q = new Query("test", [
|
const q = new Query(
|
||||||
{
|
"test",
|
||||||
kinds: [1],
|
[
|
||||||
authors: ["test"],
|
{
|
||||||
},
|
kinds: [1],
|
||||||
]);
|
authors: ["test"],
|
||||||
|
},
|
||||||
|
],
|
||||||
|
new FlatNoteStore()
|
||||||
|
);
|
||||||
const opt = {
|
const opt = {
|
||||||
read: true,
|
read: true,
|
||||||
write: true,
|
write: true,
|
||||||
@ -38,12 +43,16 @@ describe("query", () => {
|
|||||||
q.eose(q.id, c3);
|
q.eose(q.id, c3);
|
||||||
expect(q.progress).toBe(1);
|
expect(q.progress).toBe(1);
|
||||||
|
|
||||||
const qs = new Query("test-1", [
|
const qs = new Query(
|
||||||
{
|
"test-1",
|
||||||
kinds: [1],
|
[
|
||||||
authors: ["test-sub"],
|
{
|
||||||
},
|
kinds: [1],
|
||||||
]);
|
authors: ["test-sub"],
|
||||||
|
},
|
||||||
|
],
|
||||||
|
new FlatNoteStore()
|
||||||
|
);
|
||||||
q.subQueries.push(qs);
|
q.subQueries.push(qs);
|
||||||
qs.sendToRelay(c1);
|
qs.sendToRelay(c1);
|
||||||
|
|
||||||
|
@ -121,9 +121,9 @@ export class Query {
|
|||||||
/**
|
/**
|
||||||
* Feed object which collects events
|
* Feed object which collects events
|
||||||
*/
|
*/
|
||||||
#feed?: NoteStore;
|
#feed: NoteStore;
|
||||||
|
|
||||||
constructor(id: string, filters: Array<RawReqFilter>, feed?: NoteStore) {
|
constructor(id: string, filters: Array<RawReqFilter>, feed: NoteStore) {
|
||||||
this.id = id;
|
this.id = id;
|
||||||
this.filters = filters;
|
this.filters = filters;
|
||||||
this.#feed = feed;
|
this.#feed = feed;
|
||||||
@ -190,14 +190,12 @@ export class Query {
|
|||||||
}
|
}
|
||||||
|
|
||||||
eose(sub: string, conn: Readonly<Connection>) {
|
eose(sub: string, conn: Readonly<Connection>) {
|
||||||
const qt = this.#tracing.filter(a => a.subId === sub && a.connId === conn.Id);
|
const qt = this.#tracing.find(a => a.subId === sub && a.connId === conn.Id);
|
||||||
|
qt?.gotEose();
|
||||||
if (sub === this.id) {
|
if (sub === this.id) {
|
||||||
console.debug(`[EOSE][${sub}] ${conn.Address}`);
|
console.debug(`[EOSE][${sub}] ${conn.Address}`);
|
||||||
qt.forEach(a => a.gotEose());
|
this.#feed.loading = this.progress < 1;
|
||||||
if (this.#feed) {
|
if (!this.leaveOpen && !this.#feed.loading) {
|
||||||
this.#feed.loading = this.progress < 1;
|
|
||||||
}
|
|
||||||
if (!this.leaveOpen) {
|
|
||||||
this.sendClose();
|
this.sendClose();
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
@ -212,14 +212,13 @@ export class NostrSystem {
|
|||||||
this.#changed();
|
this.#changed();
|
||||||
return unwrap(q.feed) as Readonly<T>;
|
return unwrap(q.feed) as Readonly<T>;
|
||||||
} else {
|
} else {
|
||||||
const subQ = new Query(`${q.id}-${q.subQueries.length + 1}`, filters);
|
const subQ = new Query(`${q.id}-${q.subQueries.length + 1}`, filters, q.feed);
|
||||||
q.subQueries.push(subQ);
|
q.subQueries.push(subQ);
|
||||||
q.filters = filters;
|
q.filters = filters;
|
||||||
const f = unwrap(q.feed);
|
q.feed.loading = true;
|
||||||
f.loading = true;
|
|
||||||
this.SendQuery(subQ);
|
this.SendQuery(subQ);
|
||||||
this.#changed();
|
this.#changed();
|
||||||
return f as Readonly<T>;
|
return q.feed as Readonly<T>;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
return this.AddQuery<T>(type, req);
|
return this.AddQuery<T>(type, req);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user