Skip to content

Commit

Permalink
fix build
Browse files Browse the repository at this point in the history
  • Loading branch information
hzrd149 committed Oct 18, 2023
1 parent 0e1cbfc commit 701a309
Show file tree
Hide file tree
Showing 7 changed files with 77 additions and 84 deletions.
4 changes: 2 additions & 2 deletions src/components/magic-textarea.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { nip19 } from "nostr-tools";
import { matchSorter } from "match-sorter/dist/match-sorter.esm.js";

import { Emoji, useContextEmojis } from "../providers/emoji-provider";
import { useUserDirectoryContext } from "../providers/user-directory-provider";
import { useUserSearchDirectoryContext } from "../providers/user-directory-provider";
import { UserAvatar } from "./user-avatar";

export type PeopleToken = { pubkey: string; names: string[] };
Expand Down Expand Up @@ -57,7 +57,7 @@ const Loading: ReactTextareaAutocompleteProps<

function useAutocompleteTriggers() {
const emojis = useContextEmojis();
const getDirectory = useUserDirectoryContext();
const getDirectory = useUserSearchDirectoryContext();

const triggers: TriggerType<Token> = {
":": {
Expand Down
6 changes: 3 additions & 3 deletions src/components/post-modal/zap-split-creator.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import { useForm } from "react-hook-form";

import { EventSplit } from "../../helpers/nostr/zaps";
import { AddIcon } from "../icons";
import { useUserDirectoryContext } from "../../providers/user-directory-provider";
import { useUserSearchDirectoryContext } from "../../providers/user-directory-provider";
import { useAsync } from "react-use";
import { getUserDisplayName } from "../../helpers/user-metadata";
import userMetadataService from "../../services/user-metadata";
Expand Down Expand Up @@ -58,10 +58,10 @@ function AddUserForm({
});
watch("percent");

const getDirectory = useUserDirectoryContext();
const getDirectory = useUserSearchDirectoryContext();
const { value: users } = useAsync(async () => {
const dir = await getDirectory();
return dir.map((pubkey) => ({ pubkey, metadata: userMetadataService.getSubject(pubkey).value }));
return dir.map(({ pubkey }) => ({ pubkey, metadata: userMetadataService.getSubject(pubkey).value }));
}, [getDirectory]);

const submit = handleSubmit((values) => {
Expand Down
4 changes: 2 additions & 2 deletions src/components/search-modal/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { useAsync, useThrottle } from "react-use";
import { matchSorter } from "match-sorter";
import { nip19 } from "nostr-tools";

import { useUserDirectoryContext } from "../../providers/user-directory-provider";
import { useUserSearchDirectoryContext } from "../../providers/user-directory-provider";
import { UserAvatar } from "../user-avatar";
import { useUserMetadata } from "../../hooks/use-user-metadata";
import { getUserDisplayName } from "../../helpers/user-metadata";
Expand All @@ -23,7 +23,7 @@ function UserOption({ pubkey }: { pubkey: string }) {

export default function SearchModal({ isOpen, onClose }: Omit<ModalProps, "children">) {
const searchRef = useRef<HTMLInputElement | null>(null);
const getDirectory = useUserDirectoryContext();
const getDirectory = useUserSearchDirectoryContext();

const [inputValue, setInputValue] = useState("");
const search = useThrottle(inputValue);
Expand Down
6 changes: 3 additions & 3 deletions src/providers/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { InvoiceModalProvider } from "./invoice-modal";
import NotificationTimelineProvider from "./notification-timeline";
import PostModalProvider from "./post-modal-provider";
import { DefaultEmojiProvider, UserEmojiProvider } from "./emoji-provider";
import { AllUserDirectoryProvider } from "./user-directory-provider";
import { AllUserSearchDirectoryProvider } from "./user-directory-provider";
import MuteModalProvider from "./mute-modal-provider";
import BreakpointProvider from "./breakpoint-provider";

Expand Down Expand Up @@ -39,9 +39,9 @@ export function PageProviders({ children }: { children: React.ReactNode }) {
<NotificationTimelineProvider>
<DefaultEmojiProvider>
<UserEmojiProvider>
<AllUserDirectoryProvider>
<AllUserSearchDirectoryProvider>
<PostModalProvider>{children}</PostModalProvider>
</AllUserDirectoryProvider>
</AllUserSearchDirectoryProvider>
</UserEmojiProvider>
</DefaultEmojiProvider>
</NotificationTimelineProvider>
Expand Down
20 changes: 8 additions & 12 deletions src/providers/user-directory-provider.tsx
Original file line number Diff line number Diff line change
@@ -1,17 +1,13 @@
import { PropsWithChildren, createContext, useCallback, useContext } from "react";

import { useCurrentAccount } from "../hooks/use-current-account";
import useUserContactList from "../hooks/use-user-contact-list";
import { getPubkeysFromList } from "../helpers/nostr/lists";
import userMetadataService from "../services/user-metadata";
import db from "../services/db";

export type UserDirectory = { pubkey: string; names: [] }[];
export type GetDirectoryFn = () => Promise<UserDirectory> | UserDirectory;
const UserDirectoryContext = createContext<GetDirectoryFn>(async () => []);
const UserSearchDirectoryContext = createContext<GetDirectoryFn>(async () => []);

export function useUserDirectoryContext() {
return useContext(UserDirectoryContext);
export function useUserSearchDirectoryContext() {
return useContext(UserSearchDirectoryContext);
}

// export function getNameDirectory(directory: UserDirectory) {
Expand Down Expand Up @@ -46,19 +42,19 @@ export function useUserDirectoryContext() {
// return <UserDirectoryProvider getDirectory={getDirectory}>{children}</UserDirectoryProvider>;
// }

export function AllUserDirectoryProvider({ children }: PropsWithChildren) {
export function AllUserSearchDirectoryProvider({ children }: PropsWithChildren) {
const getDirectory = useCallback(async () => {
return await db.getAll("userSearch");
}, []);

return <UserDirectoryProvider getDirectory={getDirectory}>{children}</UserDirectoryProvider>;
return <UserSearchDirectoryProvider getDirectory={getDirectory}>{children}</UserSearchDirectoryProvider>;
}

export default function UserDirectoryProvider({
export default function UserSearchDirectoryProvider({
children,
getDirectory,
}: PropsWithChildren & { getDirectory: GetDirectoryFn }) {
const parent = useContext(UserDirectoryContext);
const parent = useContext(UserSearchDirectoryContext);
const wrapper = useCallback<() => Promise<UserDirectory>>(async () => {
const dir = parent ? await parent() : [];
const newDir = await getDirectory();
Expand All @@ -68,5 +64,5 @@ export default function UserDirectoryProvider({
return dir;
}, [parent, getDirectory]);

return <UserDirectoryContext.Provider value={wrapper}>{children}</UserDirectoryContext.Provider>;
return <UserSearchDirectoryContext.Provider value={wrapper}>{children}</UserSearchDirectoryContext.Provider>;
}
95 changes: 46 additions & 49 deletions src/views/note/components/reply-form.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ import NostrPublishAction from "../../../classes/nostr-publish-action";
import { unique } from "../../../helpers/array";
import MagicTextArea, { RefType } from "../../../components/magic-textarea";
import { useContextEmojis } from "../../../providers/emoji-provider";
import UserDirectoryProvider from "../../../providers/user-directory-provider";
import { TrustProvider } from "../../../providers/trust";
import { nostrBuildUploadImage } from "../../../helpers/nostr-build";
import { UploadImageIcon } from "../../../components/icons";
Expand Down Expand Up @@ -96,56 +95,54 @@ export default function ReplyForm({ item, onCancel, onSubmitted }: ReplyFormProp
});

return (
<UserDirectoryProvider getDirectory={() => threadMembers}>
<Flex as="form" direction="column" gap="2" pb="4" onSubmit={submit}>
<MagicTextArea
placeholder="Reply"
autoFocus
mb="2"
rows={4}
isRequired
value={getValues().content}
onChange={(e) => setValue("content", e.target.value, { shouldDirty: true })}
instanceRef={(inst) => (textAreaRef.current = inst)}
onPaste={(e) => {
const imageFile = Array.from(e.clipboardData.files).find((f) => f.type.includes("image"));
if (imageFile) uploadImage(imageFile);
<Flex as="form" direction="column" gap="2" pb="4" onSubmit={submit}>
<MagicTextArea
placeholder="Reply"
autoFocus
mb="2"
rows={4}
isRequired
value={getValues().content}
onChange={(e) => setValue("content", e.target.value, { shouldDirty: true })}
instanceRef={(inst) => (textAreaRef.current = inst)}
onPaste={(e) => {
const imageFile = Array.from(e.clipboardData.files).find((f) => f.type.includes("image"));
if (imageFile) uploadImage(imageFile);
}}
/>
<Flex gap="2" alignItems="center">
<VisuallyHiddenInput
type="file"
accept="image/*"
ref={imageUploadRef}
onChange={(e) => {
const img = e.target.files?.[0];
if (img) uploadImage(img);
}}
/>
<Flex gap="2" alignItems="center">
<VisuallyHiddenInput
type="file"
accept="image/*"
ref={imageUploadRef}
onChange={(e) => {
const img = e.target.files?.[0];
if (img) uploadImage(img);
}}
/>
<IconButton
icon={<UploadImageIcon />}
aria-label="Upload Image"
title="Upload Image"
onClick={() => imageUploadRef.current?.click()}
isLoading={uploading}
size="sm"
/>
<UserAvatarStack label="Notify" pubkeys={notifyPubkeys} />
<ButtonGroup size="sm" ml="auto">
<Button onClick={onCancel}>Cancel</Button>
<Button type="submit" colorScheme="primary" size="sm">
Submit
</Button>
</ButtonGroup>
</Flex>
{getValues().content.length > 0 && (
<Box p="2" borderWidth={1} borderRadius="md" mb="2">
<TrustProvider trust>
<NoteContents event={draft} />
</TrustProvider>
</Box>
)}
<IconButton
icon={<UploadImageIcon />}
aria-label="Upload Image"
title="Upload Image"
onClick={() => imageUploadRef.current?.click()}
isLoading={uploading}
size="sm"
/>
<UserAvatarStack label="Notify" pubkeys={notifyPubkeys} />
<ButtonGroup size="sm" ml="auto">
<Button onClick={onCancel}>Cancel</Button>
<Button type="submit" colorScheme="primary" size="sm">
Submit
</Button>
</ButtonGroup>
</Flex>
</UserDirectoryProvider>
{getValues().content.length > 0 && (
<Box p="2" borderWidth={1} borderRadius="md" mb="2">
<TrustProvider trust>
<NoteContents event={draft} />
</TrustProvider>
</Box>
)}
</Flex>
);
}
26 changes: 13 additions & 13 deletions src/views/streams/stream/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ import { UserEmojiProvider } from "../../../providers/emoji-provider";
import StreamStatusBadge from "../components/status-badge";
import ChatMessageForm from "./stream-chat/stream-chat-form";
import useStreamChatTimeline from "./stream-chat/use-stream-chat-timeline";
import UserDirectoryProvider from "../../../providers/user-directory-provider";
import UserSearchDirectoryProvider from "../../../providers/user-directory-provider";
import StreamChatLog from "./stream-chat/chat-log";
import TopZappers from "../components/top-zappers";
import StreamHashtags from "../components/stream-hashtags";
Expand Down Expand Up @@ -206,20 +206,20 @@ function StreamPage({ stream }: { stream: ParsedStream }) {
const isMobile = useBreakpointValue({ base: true, lg: false });
const Layout = isMobile ? MobileStreamPage : DesktopStreamPage;

const chatTimeline = useStreamChatTimeline(stream);
const chatLog = useSubject(chatTimeline.timeline);
const pubkeysInChat = useMemo(() => {
const set = new Set<string>();
for (const event of chatLog) {
set.add(event.pubkey);
}
return Array.from(set);
}, [chatLog]);
// const chatTimeline = useStreamChatTimeline(stream);
// const chatLog = useSubject(chatTimeline.timeline);
// const pubkeysInChat = useMemo(() => {
// const set = new Set<string>();
// for (const event of chatLog) {
// set.add(event.pubkey);
// }
// return Array.from(set);
// }, [chatLog]);

return (
<UserDirectoryProvider getDirectory={() => pubkeysInChat}>
<Layout stream={stream} />
</UserDirectoryProvider>
// <UserDirectoryProvider getDirectory={() => pubkeysInChat}>
<Layout stream={stream} />
// </UserDirectoryProvider>
);
}

Expand Down

0 comments on commit 701a309

Please sign in to comment.