mirror of
https://github.com/hzrd149/nostrudel.git
synced 2025-04-10 12:49:29 +02:00
fix bug with user search not updating
This commit is contained in:
parent
f81d3bcacd
commit
99fdff4dbc
@ -2,6 +2,8 @@ import { PropsWithChildren, createContext, useCallback, useContext } from "react
|
||||
import { useAsync } from "react-use";
|
||||
|
||||
import db from "../../services/db";
|
||||
import useSubject from "../../hooks/use-subject";
|
||||
import { userSearchUpdate } from "../../services/username-search";
|
||||
|
||||
export type UserDirectory = { pubkey: string; names: string[] }[];
|
||||
export type GetDirectoryFn = () => UserDirectory;
|
||||
@ -12,7 +14,8 @@ export function useUserSearchDirectoryContext() {
|
||||
}
|
||||
|
||||
export function AllUserSearchDirectoryProvider({ children }: PropsWithChildren) {
|
||||
const { value: users } = useAsync(() => db.getAll("userSearch"));
|
||||
const update = useSubject(userSearchUpdate);
|
||||
const { value: users } = useAsync(() => db.getAll("userSearch"), [update]);
|
||||
const getDirectory = useCallback(() => users as UserDirectory, [users]);
|
||||
|
||||
return <UserSearchDirectoryProvider getDirectory={getDirectory}>{children}</UserSearchDirectoryProvider>;
|
||||
|
@ -4,10 +4,13 @@ import db from "./db";
|
||||
import replaceableEventsService from "./replaceable-events";
|
||||
import userMetadataService from "./user-metadata";
|
||||
import { logger } from "../helpers/debug";
|
||||
import Subject from "../classes/subject";
|
||||
|
||||
const WRITE_USER_SEARCH_BATCH_TIME = 500;
|
||||
const log = logger.extend("UsernameSearch");
|
||||
|
||||
export const userSearchUpdate = new Subject();
|
||||
|
||||
const writeSearchQueue = new Set<string>();
|
||||
const writeSearchData = _throttle(async () => {
|
||||
if (writeSearchQueue.size === 0) return;
|
||||
@ -26,6 +29,7 @@ const writeSearchData = _throttle(async () => {
|
||||
}
|
||||
transaction.commit();
|
||||
await transaction.done;
|
||||
userSearchUpdate.next(Math.random());
|
||||
}, WRITE_USER_SEARCH_BATCH_TIME);
|
||||
|
||||
replaceableEventsService.events.onEvent.subscribe((event) => {
|
||||
|
@ -14,7 +14,7 @@ import NoteFilterTypeButtons from "../../components/note-filter-type-buttons";
|
||||
import KindSelectionProvider, { useKindSelectionContext } from "../../providers/local/kind-selection-provider";
|
||||
import { useReadRelays } from "../../hooks/use-client-relays";
|
||||
|
||||
const defaultKinds = [kinds.ShortTextNote, kinds.Repost, kinds.GenericRepost, kinds.LongFormArticle];
|
||||
const defaultKinds = [kinds.ShortTextNote, kinds.Repost, kinds.GenericRepost];
|
||||
|
||||
function HomePage() {
|
||||
const showReplies = useDisclosure({ defaultIsOpen: localStorage.getItem("show-replies") === "true" });
|
||||
|
Loading…
x
Reference in New Issue
Block a user