-
Notifications
You must be signed in to change notification settings - Fork 46
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
196 additions
and
56 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
import { Flex, Input, Modal, ModalContent, ModalOverlay, ModalProps, Text } from "@chakra-ui/react"; | ||
import { useRef, useState } from "react"; | ||
import { Link as RouterLink } from "react-router-dom"; | ||
import { useAsync, useThrottle } from "react-use"; | ||
import { matchSorter } from "match-sorter"; | ||
import { nip19 } from "nostr-tools"; | ||
|
||
import { useUserDirectoryContext } from "../../providers/user-directory-provider"; | ||
import { UserAvatar } from "../user-avatar"; | ||
import { useUserMetadata } from "../../hooks/use-user-metadata"; | ||
import { getUserDisplayName } from "../../helpers/user-metadata"; | ||
|
||
function UserOption({ pubkey }: { pubkey: string }) { | ||
const metadata = useUserMetadata(pubkey); | ||
|
||
return ( | ||
<Flex as={RouterLink} to={`/u/${nip19.npubEncode(pubkey)}`} p="2" gap="2" alignItems="center"> | ||
<UserAvatar pubkey={pubkey} size="sm" /> | ||
<Text fontWeight="bold">{getUserDisplayName(metadata, pubkey)}</Text> | ||
</Flex> | ||
); | ||
} | ||
|
||
export default function SearchModal({ isOpen, onClose }: Omit<ModalProps, "children">) { | ||
const searchRef = useRef<HTMLInputElement | null>(null); | ||
const getDirectory = useUserDirectoryContext(); | ||
|
||
const [inputValue, setInputValue] = useState(""); | ||
const search = useThrottle(inputValue); | ||
|
||
const { value: localUsers = [] } = useAsync(async () => { | ||
if (search.trim().length < 2) return []; | ||
|
||
const dir = await getDirectory(); | ||
return matchSorter(dir, search.trim(), { keys: ["names"] }).slice(0, 5); | ||
}, [search]); | ||
|
||
return ( | ||
<Modal isOpen={isOpen} onClose={onClose} size="xl" initialFocusRef={searchRef}> | ||
<ModalOverlay /> | ||
<ModalContent> | ||
<Input | ||
placeholder="Search" | ||
type="search" | ||
w="full" | ||
size="lg" | ||
ref={searchRef} | ||
value={inputValue} | ||
onChange={(e) => setInputValue(e.target.value)} | ||
/> | ||
{localUsers.map(({ pubkey }) => ( | ||
<UserOption key={pubkey} pubkey={pubkey} /> | ||
))} | ||
</ModalContent> | ||
</Modal> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,8 @@ | ||
export const SEARCH_RELAYS = ["wss://relay.nostr.band", "wss://search.nos.today", "wss://relay.noswhere.com"]; | ||
export const SEARCH_RELAYS = [ | ||
"wss://relay.nostr.band", | ||
"wss://search.nos.today", | ||
"wss://relay.noswhere.com", | ||
// TODO: requires NIP-42 auth | ||
// "wss://filter.nostr.wine", | ||
]; | ||
export const COMMON_CONTACT_RELAY = "wss://purplepag.es"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters