fix: profile mentions
This commit is contained in:
@ -1,3 +1,4 @@
|
|||||||
|
/* eslint-disable max-lines */
|
||||||
import "./NoteCreator.css";
|
import "./NoteCreator.css";
|
||||||
|
|
||||||
import { fetchNip05Pubkey, unixNow } from "@snort/shared";
|
import { fetchNip05Pubkey, unixNow } from "@snort/shared";
|
||||||
|
@ -1,14 +1,15 @@
|
|||||||
import "@webscopeio/react-textarea-autocomplete/style.css";
|
import "@webscopeio/react-textarea-autocomplete/style.css";
|
||||||
import "./Textarea.css";
|
import "./Textarea.css";
|
||||||
|
|
||||||
import { CachedMetadata, NostrPrefix } from "@snort/system";
|
import { NostrPrefix } from "@snort/system";
|
||||||
import ReactTextareaAutocomplete from "@webscopeio/react-textarea-autocomplete";
|
import ReactTextareaAutocomplete from "@webscopeio/react-textarea-autocomplete";
|
||||||
import { useIntl } from "react-intl";
|
import { useIntl } from "react-intl";
|
||||||
import TextareaAutosize from "react-textarea-autosize";
|
import TextareaAutosize from "react-textarea-autosize";
|
||||||
|
|
||||||
import { UserCache } from "@/Cache";
|
|
||||||
import Avatar from "@/Components/User/Avatar";
|
import Avatar from "@/Components/User/Avatar";
|
||||||
import Nip05 from "@/Components/User/Nip05";
|
import Nip05 from "@/Components/User/Nip05";
|
||||||
|
import { FuzzySearchResult } from "@/Db/FuzzySearch";
|
||||||
|
import { userSearch } from "@/Hooks/useProfileSearch";
|
||||||
import { hexToBech32 } from "@/Utils";
|
import { hexToBech32 } from "@/Utils";
|
||||||
import searchEmoji from "@/Utils/emoji-search";
|
import searchEmoji from "@/Utils/emoji-search";
|
||||||
|
|
||||||
@ -28,7 +29,7 @@ const EmojiItem = ({ entity: { name, char } }: { entity: EmojiItemProps }) => {
|
|||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
const UserItem = (metadata: CachedMetadata) => {
|
const UserItem = (metadata: FuzzySearchResult) => {
|
||||||
const { pubkey, display_name, nip05, ...rest } = metadata;
|
const { pubkey, display_name, nip05, ...rest } = metadata;
|
||||||
return (
|
return (
|
||||||
<div key={pubkey} className="user-item">
|
<div key={pubkey} className="user-item">
|
||||||
@ -45,7 +46,7 @@ const UserItem = (metadata: CachedMetadata) => {
|
|||||||
|
|
||||||
interface TextareaProps {
|
interface TextareaProps {
|
||||||
autoFocus: boolean;
|
autoFocus: boolean;
|
||||||
className: string;
|
className?: string;
|
||||||
placeholder?: string;
|
placeholder?: string;
|
||||||
onChange(ev: React.ChangeEvent<HTMLTextAreaElement>): void;
|
onChange(ev: React.ChangeEvent<HTMLTextAreaElement>): void;
|
||||||
value: string;
|
value: string;
|
||||||
@ -59,8 +60,8 @@ interface TextareaProps {
|
|||||||
const Textarea = (props: TextareaProps) => {
|
const Textarea = (props: TextareaProps) => {
|
||||||
const { formatMessage } = useIntl();
|
const { formatMessage } = useIntl();
|
||||||
|
|
||||||
const userDataProvider = async (token: string) => {
|
const userDataProvider = (token: string) => {
|
||||||
return await UserCache.search(token);
|
return userSearch(token).slice(0, 10);
|
||||||
};
|
};
|
||||||
|
|
||||||
const emojiDataProvider = async (token: string) => {
|
const emojiDataProvider = async (token: string) => {
|
||||||
@ -84,7 +85,7 @@ const Textarea = (props: TextareaProps) => {
|
|||||||
"@": {
|
"@": {
|
||||||
afterWhitespace: true,
|
afterWhitespace: true,
|
||||||
dataProvider: userDataProvider,
|
dataProvider: userDataProvider,
|
||||||
component: (props: { entity: CachedMetadata }) => <UserItem {...props.entity} />,
|
component: (props: { entity: FuzzySearchResult }) => <UserItem {...props.entity} />,
|
||||||
output: (item: { pubkey: string }) => `@${hexToBech32(NostrPrefix.PublicKey, item.pubkey)}`,
|
output: (item: { pubkey: string }) => `@${hexToBech32(NostrPrefix.PublicKey, item.pubkey)}`,
|
||||||
},
|
},
|
||||||
}}
|
}}
|
||||||
|
@ -5,6 +5,13 @@ import fuzzySearch from "@/Db/FuzzySearch";
|
|||||||
|
|
||||||
export default function useProfileSearch(search: string) {
|
export default function useProfileSearch(search: string) {
|
||||||
const results = useMemo(() => {
|
const results = useMemo(() => {
|
||||||
|
return userSearch(search);
|
||||||
|
}, [search]);
|
||||||
|
|
||||||
|
return results;
|
||||||
|
}
|
||||||
|
|
||||||
|
export function userSearch(search: string) {
|
||||||
const searchString = search.trim();
|
const searchString = search.trim();
|
||||||
const fuseResults = fuzzySearch.search(searchString);
|
const fuseResults = fuzzySearch.search(searchString);
|
||||||
|
|
||||||
@ -42,7 +49,4 @@ export default function useProfileSearch(search: string) {
|
|||||||
});
|
});
|
||||||
|
|
||||||
return combinedResults.map(r => r.item);
|
return combinedResults.map(r => r.item);
|
||||||
}, [search]);
|
|
||||||
|
|
||||||
return results;
|
|
||||||
}
|
}
|
Reference in New Issue
Block a user