Skip to content

Commit

Permalink
fix: note creator tagging
Browse files Browse the repository at this point in the history
  • Loading branch information
v0l committed Dec 21, 2024
1 parent f425830 commit e9fd593
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 28 deletions.
3 changes: 2 additions & 1 deletion packages/app/src/Components/Textarea/Textarea.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import TextareaAutosize from "react-textarea-autosize";
import Avatar from "@/Components/User/Avatar";
import Nip05 from "@/Components/User/Nip05";
import { FuzzySearchResult } from "@/Db/FuzzySearch";
import { userSearch } from "@/Hooks/useProfileSearch";
import useProfileSearch from "@/Hooks/useProfileSearch";
import searchEmoji from "@/Utils/emoji-search";

import messages from "../messages";
Expand Down Expand Up @@ -58,6 +58,7 @@ interface TextareaProps {

const Textarea = (props: TextareaProps) => {
const { formatMessage } = useIntl();
const userSearch = useProfileSearch();

const userDataProvider = (token: string) => {
return userSearch(token).slice(0, 10);
Expand Down
10 changes: 5 additions & 5 deletions packages/app/src/Hooks/useProfileSearch.tsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import fuzzySearch from "@/Db/FuzzySearch";

import useWoT from "./useWoT";
import useWoT, { WoT } from "./useWoT";

export default function useProfileSearch(search: string | undefined) {
return userSearch(search);
export default function useProfileSearch() {
const wot = useWoT();
return (search: string | undefined) => userSearch(wot, search);
}

export function userSearch(search: string | undefined) {
const wot = useWoT();
function userSearch(wot: WoT, search: string | undefined) {
const searchString = search?.trim() ?? "";
const fuseResults = (searchString?.length ?? 0) > 0 ? fuzzySearch.search(searchString) : [];

Expand Down
45 changes: 23 additions & 22 deletions packages/app/src/Hooks/useWoT.ts
Original file line number Diff line number Diff line change
@@ -1,28 +1,29 @@
import { TaggedNostrEvent } from "@snort/system";
import { SystemInterface, TaggedNostrEvent } from "@snort/system";
import { SnortContext } from "@snort/system-react";
import { useContext, useMemo } from "react";

export interface WoT {
sortEvents: (events: Array<TaggedNostrEvent>) => Array<TaggedNostrEvent>;
sortPubkeys: (events: Array<string>) => Array<string>;
followDistance: (pk: string) => number;
followedByCount: (pk: string) => number;
followedBy: (pk: string) => Set<string>;
}

function wotOnSystem(system: SystemInterface) {
const sgi = system.config.socialGraphInstance;
return {
sortEvents: (events: Array<TaggedNostrEvent>) =>
events.sort((a, b) => sgi.getFollowDistance(a.pubkey) - sgi.getFollowDistance(b.pubkey)),
sortPubkeys: (events: Array<string>) => events.sort((a, b) => sgi.getFollowDistance(a) - sgi.getFollowDistance(b)),
followDistance: (pk: string) => sgi.getFollowDistance(pk),
followedByCount: (pk: string) => sgi.followedByFriendsCount(pk),
followedBy: (pk: string) => sgi.followedByFriends(pk),
instance: sgi,
};
}

export default function useWoT() {
const system = useContext(SnortContext);
return useMemo(
() => ({
sortEvents: (events: Array<TaggedNostrEvent>) =>
events.sort(
(a, b) =>
system.config.socialGraphInstance.getFollowDistance(a.pubkey) -
system.config.socialGraphInstance.getFollowDistance(b.pubkey),
),
sortPubkeys: (events: Array<string>) =>
events.sort(
(a, b) =>
system.config.socialGraphInstance.getFollowDistance(a) -
system.config.socialGraphInstance.getFollowDistance(b),
),
followDistance: (pk: string) => system.config.socialGraphInstance.getFollowDistance(pk),
followedByCount: (pk: string) => system.config.socialGraphInstance.followedByFriendsCount(pk),
followedBy: (pk: string) => system.config.socialGraphInstance.followedByFriends(pk),
instance: system.config.socialGraphInstance,
}),
[system.config.socialGraphInstance],
);
return useMemo<WoT>(() => wotOnSystem(system), [system]);
}

0 comments on commit e9fd593

Please sign in to comment.