diff options
author | Jan-Olof Eriksson <jan-olof.eriksson@iki.fi> | 2024-03-04 18:11:00 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-03-04 18:11:00 +0200 |
commit | e724ab812346b4224b3efb2de0960f2cda88861b (patch) | |
tree | 9192c98b2b0b4be3388019b15b02a5d7df7fcce2 /src/components/TagMenu/index.web.tsx | |
parent | 963a44ab872a1044d6997a8fcf7b2fc754ac618a (diff) | |
parent | b70c404d4b369d6fab0dfbafd6b31390ffd20014 (diff) | |
download | voidsky-e724ab812346b4224b3efb2de0960f2cda88861b.tar.zst |
Merge branch 'bluesky-social:main' into main
Diffstat (limited to 'src/components/TagMenu/index.web.tsx')
-rw-r--r-- | src/components/TagMenu/index.web.tsx | 45 |
1 files changed, 29 insertions, 16 deletions
diff --git a/src/components/TagMenu/index.web.tsx b/src/components/TagMenu/index.web.tsx index 31187112f..a0dc2bce6 100644 --- a/src/components/TagMenu/index.web.tsx +++ b/src/components/TagMenu/index.web.tsx @@ -14,18 +14,34 @@ import { } from '#/state/queries/preferences' import {enforceLen} from '#/lib/strings/helpers' import {web} from '#/alf' +import * as Dialog from '#/components/Dialog' -export function useTagMenuControl() {} +export function useTagMenuControl(): Dialog.DialogControlProps { + return { + id: '', + // @ts-ignore + ref: null, + open: () => { + throw new Error(`TagMenu controls are only available on native platforms`) + }, + close: () => { + throw new Error(`TagMenu controls are only available on native platforms`) + }, + } +} export function TagMenu({ children, tag, authorHandle, }: React.PropsWithChildren<{ + /** + * This should be the sanitized tag value from the facet itself, not the + * "display" value with a leading `#`. + */ tag: string authorHandle?: string }>) { - const sanitizedTag = tag.replace(/^#/, '') const {_} = useLingui() const navigation = useNavigation<NavigationProp>() const {data: preferences} = usePreferencesQuery() @@ -35,22 +51,22 @@ export function TagMenu({ useRemoveMutedWordMutation() const isMuted = Boolean( (preferences?.mutedWords?.find( - m => m.value === sanitizedTag && m.targets.includes('tag'), + m => m.value === tag && m.targets.includes('tag'), ) ?? optimisticUpsert?.find( - m => m.value === sanitizedTag && m.targets.includes('tag'), + m => m.value === tag && m.targets.includes('tag'), )) && - !(optimisticRemove?.value === sanitizedTag), + !(optimisticRemove?.value === tag), ) - const truncatedTag = enforceLen(tag, 15, true, 'middle') + const truncatedTag = '#' + enforceLen(tag, 15, true, 'middle') const dropdownItems = React.useMemo(() => { return [ { label: _(msg`See ${truncatedTag} posts`), onPress() { - navigation.navigate('Search', { - q: tag, + navigation.push('Hashtag', { + tag: tag.replaceAll('#', '%23'), }) }, testID: 'tagMenuSearch', @@ -66,11 +82,9 @@ export function TagMenu({ !isInvalidHandle(authorHandle) && { label: _(msg`See ${truncatedTag} posts by user`), onPress() { - navigation.navigate({ - name: 'Search', - params: { - q: tag + (authorHandle ? ` from:${authorHandle}` : ''), - }, + navigation.push('Hashtag', { + tag: tag.replaceAll('#', '%23'), + author: authorHandle, }) }, testID: 'tagMenuSeachByUser', @@ -91,9 +105,9 @@ export function TagMenu({ : _(msg`Mute ${truncatedTag}`), onPress() { if (isMuted) { - removeMutedWord({value: sanitizedTag, targets: ['tag']}) + removeMutedWord({value: tag, targets: ['tag']}) } else { - upsertMutedWord([{value: sanitizedTag, targets: ['tag']}]) + upsertMutedWord([{value: tag, targets: ['tag']}]) } }, testID: 'tagMenuMute', @@ -114,7 +128,6 @@ export function TagMenu({ preferences, tag, truncatedTag, - sanitizedTag, upsertMutedWord, removeMutedWord, ]) |