From 9df5caf3c545a7a1c559c6561625d99154aa0603 Mon Sep 17 00:00:00 2001 From: Eric Bailey Date: Tue, 21 Jan 2025 15:56:01 -0600 Subject: Update hashtag menu to use `Menu`, convert to native link for additional a11y and click handling (#7529) * Make tag a normal link on web * Replace old TagMenu with new RichTextTag component, expand and improve click utils * Clarify intents * Ensure we're passing down hint * ope * DRY --- src/components/TagMenu/index.tsx | 290 --------------------------------------- 1 file changed, 290 deletions(-) delete mode 100644 src/components/TagMenu/index.tsx (limited to 'src/components/TagMenu/index.tsx') diff --git a/src/components/TagMenu/index.tsx b/src/components/TagMenu/index.tsx deleted file mode 100644 index 310ecc4c2..000000000 --- a/src/components/TagMenu/index.tsx +++ /dev/null @@ -1,290 +0,0 @@ -import React from 'react' -import {View} from 'react-native' -import {msg, Trans} from '@lingui/macro' -import {useLingui} from '@lingui/react' -import {useNavigation} from '@react-navigation/native' - -import {NavigationProp} from '#/lib/routes/types' -import {isInvalidHandle} from '#/lib/strings/handles' -import { - usePreferencesQuery, - useRemoveMutedWordsMutation, - useUpsertMutedWordsMutation, -} from '#/state/queries/preferences' -import {atoms as a, native, useTheme} from '#/alf' -import {Button, ButtonText} from '#/components/Button' -import * as Dialog from '#/components/Dialog' -import {Divider} from '#/components/Divider' -import {MagnifyingGlass2_Stroke2_Corner0_Rounded as Search} from '#/components/icons/MagnifyingGlass2' -import {Mute_Stroke2_Corner0_Rounded as Mute} from '#/components/icons/Mute' -import {Person_Stroke2_Corner0_Rounded as Person} from '#/components/icons/Person' -import {createStaticClick, Link} from '#/components/Link' -import {Loader} from '#/components/Loader' -import {Text} from '#/components/Typography' - -export function useTagMenuControl() { - return Dialog.useDialogControl() -} - -export function TagMenu({ - children, - control, - tag, - authorHandle, -}: React.PropsWithChildren<{ - control: Dialog.DialogOuterProps['control'] - /** - * This should be the sanitized tag value from the facet itself, not the - * "display" value with a leading `#`. - */ - tag: string - authorHandle?: string -}>) { - const navigation = useNavigation() - return ( - <> - {children} - - - - - - ) -} - -function TagMenuInner({ - control, - tag, - authorHandle, - navigation, -}: { - control: Dialog.DialogOuterProps['control'] - tag: string - authorHandle?: string - // Passed down because on native, we don't use real portals (and context would be wrong). - navigation: NavigationProp -}) { - const {_} = useLingui() - const t = useTheme() - const {isLoading: isPreferencesLoading, data: preferences} = - usePreferencesQuery() - const { - mutateAsync: upsertMutedWord, - variables: optimisticUpsert, - reset: resetUpsert, - } = useUpsertMutedWordsMutation() - const { - mutateAsync: removeMutedWords, - variables: optimisticRemove, - reset: resetRemove, - } = useRemoveMutedWordsMutation() - const displayTag = '#' + tag - - const isMuted = Boolean( - (preferences?.moderationPrefs.mutedWords?.find( - m => m.value === tag && m.targets.includes('tag'), - ) ?? - optimisticUpsert?.find( - m => m.value === tag && m.targets.includes('tag'), - )) && - !optimisticRemove?.find(m => m?.value === tag), - ) - - /* - * Mute word records that exactly match the tag in question. - */ - const removeableMuteWords = React.useMemo(() => { - return ( - preferences?.moderationPrefs.mutedWords?.filter(word => { - return word.value === tag - }) || [] - ) - }, [tag, preferences?.moderationPrefs?.mutedWords]) - - return ( - - {isPreferencesLoading ? ( - - - - ) : ( - <> - - { - control.close(() => { - navigation.push('Hashtag', { - tag: encodeURIComponent(tag), - }) - }) - })}> - - - - - See{' '} - - {displayTag} - {' '} - posts - - - - - - {authorHandle && !isInvalidHandle(authorHandle) && ( - <> - - - { - control.close(() => { - navigation.push('Hashtag', { - tag: encodeURIComponent(tag), - author: authorHandle, - }) - }) - })}> - - - - - See{' '} - - {displayTag} - {' '} - posts by this user - - - - - - )} - - {preferences ? ( - <> - - - - - ) : null} - - - - - )} - - ) -} -- cgit 1.4.1