feat: improve profile loading

This commit is contained in:
2023-02-20 23:14:15 +00:00
parent 5293991072
commit 3f406ec19e
19 changed files with 340 additions and 523 deletions

View File

@ -2,11 +2,12 @@ import { useSelector } from "react-redux";
import * as secp from "@noble/secp256k1";
import { TaggedRawEvent } from "@snort/nostr";
import { EventKind, Tag, Event as NEvent, System, RelaySettings } from "@snort/nostr";
import { EventKind, Tag, Event as NEvent, RelaySettings } from "@snort/nostr";
import { RootState } from "State/Store";
import { HexKey, RawEvent, u256, UserMetadata, Lists } from "@snort/nostr";
import { bech32ToHex, unwrap } from "Util";
import { DefaultRelays, HashtagRegex } from "Const";
import { System } from "System";
declare global {
interface Window {

View File

@ -19,13 +19,13 @@ import {
} from "State/Login";
import { RootState } from "State/Store";
import { mapEventToProfile, MetadataCache } from "State/Users";
import { useDb } from "State/Users/Db";
import useSubscription from "Feed/Subscription";
import { barrierNip07 } from "Feed/EventPublisher";
import { getMutedKeys } from "Feed/MuteList";
import useModeration from "Hooks/useModeration";
import { unwrap } from "Util";
import { AnyAction, ThunkDispatch } from "@reduxjs/toolkit";
import { ReduxUDB } from "State/Users/Db";
/**
* Managed loading data for the current logged in user
@ -39,7 +39,6 @@ export default function useLoginFeed() {
readNotifications,
} = useSelector((s: RootState) => s.login);
const { isMuted } = useModeration();
const db = useDb();
const subMetadata = useMemo(() => {
if (!pubKey) return null;
@ -176,13 +175,13 @@ export default function useLoginFeed() {
{ created: 0, profile: null as MetadataCache | null }
);
if (maxProfile.profile) {
const existing = await db.find(maxProfile.profile.pubkey);
const existing = await ReduxUDB.find(maxProfile.profile.pubkey);
if ((existing?.created ?? 0) < maxProfile.created) {
await db.put(maxProfile.profile);
await ReduxUDB.put(maxProfile.profile);
}
}
})().catch(console.warn);
}, [dispatch, metadataFeed.store, db]);
}, [dispatch, metadataFeed.store, ReduxUDB]);
useEffect(() => {
const replies = notificationFeed.store.notes.filter(
@ -190,13 +189,13 @@ export default function useLoginFeed() {
);
replies.forEach(nx => {
dispatch(setLatestNotifications(nx.created_at));
makeNotification(db, nx).then(notification => {
makeNotification(ReduxUDB, nx).then(notification => {
if (notification) {
(dispatch as ThunkDispatch<RootState, undefined, AnyAction>)(sendNotification(notification));
}
});
});
}, [dispatch, notificationFeed.store, db, readNotifications]);
}, [dispatch, notificationFeed.store, ReduxUDB, readNotifications]);
useEffect(() => {
const muted = getMutedKeys(mutedFeed.store.notes);

View File

@ -1,7 +1,8 @@
import { useEffect } from "react";
import { MetadataCache } from "State/Users";
import { useKey, useKeys } from "State/Users/Hooks";
import { System, HexKey } from "@snort/nostr";
import { HexKey } from "@snort/nostr";
import { System } from "System";
export function useUserProfile(pubKey?: HexKey): MetadataCache | undefined {
const users = useKey(pubKey);

View File

@ -1,5 +1,6 @@
import { useSyncExternalStore } from "react";
import { System, StateSnapshot } from "@snort/nostr";
import { StateSnapshot } from "@snort/nostr";
import { System } from "System";
const noop = () => {
return () => undefined;

View File

@ -1,6 +1,7 @@
import { useEffect, useMemo, useReducer, useState } from "react";
import { TaggedRawEvent } from "@snort/nostr";
import { System, Subscriptions } from "@snort/nostr";
import { Subscriptions } from "@snort/nostr";
import { System } from "System";
import { debounce, unwrap } from "Util";
import { db } from "Db";