From dcb6aa41cce12c22ee907ac93475ac4c235b1fcb Mon Sep 17 00:00:00 2001 From: Eric Bailey Date: Mon, 5 Aug 2024 09:59:48 -0500 Subject: [PATCH] Do some renaming for clarity --- src/components/WhoCanReply.tsx | 20 +++++++++---------- src/components/dialogs/ThreadgateEditor.tsx | 20 +++++++++---------- src/lib/api/index.ts | 6 +++--- src/state/queries/threadgate.ts | 14 ++++++++----- src/view/com/composer/Composer.tsx | 4 ++-- .../com/composer/threadgate/ThreadgateBtn.tsx | 6 +++--- 6 files changed, 37 insertions(+), 33 deletions(-) diff --git a/src/components/WhoCanReply.tsx b/src/components/WhoCanReply.tsx index d6b9effb4e..3b9adf90f5 100644 --- a/src/components/WhoCanReply.tsx +++ b/src/components/WhoCanReply.tsx @@ -20,8 +20,8 @@ import {isNative} from '#/platform/detection' import {RQKEY_ROOT as POST_THREAD_RQKEY_ROOT} from '#/state/queries/post-thread' import {threadgateRecordQueryKeyRoot} from '#/state/queries/threadgate' import { - ThreadgateSetting, - threadgateViewToSettings, + ThreadgateAllowUISetting, + threadgateViewToAllowUISetting, } from '#/state/queries/threadgate' import {useAgent} from '#/state/session' import * as Toast from 'view/com/util/Toast' @@ -52,7 +52,7 @@ export function WhoCanReply({post, isThreadAuthor, style}: WhoCanReplyProps) { const queryClient = useQueryClient() const settings = React.useMemo( - () => threadgateViewToSettings(post.threadgate), + () => threadgateViewToAllowUISetting(post.threadgate), [post], ) const isRootPost = !('reply' in post.record) @@ -83,7 +83,7 @@ export function WhoCanReply({post, isThreadAuthor, style}: WhoCanReplyProps) { } } - const onEditConfirm = async (newSettings: ThreadgateSetting[]) => { + const onEditConfirm = async (newSettings: ThreadgateAllowUISetting[]) => { if (JSON.stringify(settings) === JSON.stringify(newSettings)) { return } @@ -100,7 +100,7 @@ export function WhoCanReply({post, isThreadAuthor, style}: WhoCanReplyProps) { await whenAppViewReady(agent, post.uri, res => { const thread = res.data.thread if (AppBskyFeedDefs.isThreadViewPost(thread)) { - const fetchedSettings = threadgateViewToSettings( + const fetchedSettings = threadgateViewToAllowUISetting( thread.post.threadgate, ) return JSON.stringify(fetchedSettings) === JSON.stringify(newSettings) @@ -178,7 +178,7 @@ function Icon({ }: { color: string width?: number - settings: ThreadgateSetting[] + settings: ThreadgateAllowUISetting[] }) { const isEverybody = settings.length === 0 const isNobody = !!settings.find(gate => gate.type === 'nobody') @@ -193,7 +193,7 @@ function WhoCanReplyDialog({ }: { control: Dialog.DialogControlProps post: AppBskyFeedDefs.PostView - settings: ThreadgateSetting[] + settings: ThreadgateAllowUISetting[] }) { return ( @@ -208,7 +208,7 @@ function WhoCanReplyDialogInner({ settings, }: { post: AppBskyFeedDefs.PostView - settings: ThreadgateSetting[] + settings: ThreadgateAllowUISetting[] }) { const {_} = useLingui() return ( @@ -230,7 +230,7 @@ function Rules({ settings, }: { post: AppBskyFeedDefs.PostView - settings: ThreadgateSetting[] + settings: ThreadgateAllowUISetting[] }) { const t = useTheme() return ( @@ -271,7 +271,7 @@ function Rule({ post, lists, }: { - rule: ThreadgateSetting + rule: ThreadgateAllowUISetting post: AppBskyFeedDefs.PostView lists: AppBskyGraphDefs.ListViewBasic[] | undefined }) { diff --git a/src/components/dialogs/ThreadgateEditor.tsx b/src/components/dialogs/ThreadgateEditor.tsx index 90483b3adf..f529ecc51a 100644 --- a/src/components/dialogs/ThreadgateEditor.tsx +++ b/src/components/dialogs/ThreadgateEditor.tsx @@ -5,7 +5,7 @@ import {useLingui} from '@lingui/react' import isEqual from 'lodash.isequal' import {useMyListsQuery} from '#/state/queries/my-lists' -import {ThreadgateSetting} from '#/state/queries/threadgate' +import {ThreadgateAllowUISetting} from '#/state/queries/threadgate' import {atoms as a, useTheme} from '#/alf' import {Button, ButtonText} from '#/components/Button' import * as Dialog from '#/components/Dialog' @@ -14,9 +14,9 @@ import {Text} from '#/components/Typography' interface ThreadgateEditorDialogProps { control: Dialog.DialogControlProps - threadgate: ThreadgateSetting[] - onChange?: (v: ThreadgateSetting[]) => void - onConfirm?: (v: ThreadgateSetting[]) => void + threadgate: ThreadgateAllowUISetting[] + onChange?: (v: ThreadgateAllowUISetting[]) => void + onConfirm?: (v: ThreadgateAllowUISetting[]) => void } export function ThreadgateEditorDialog({ @@ -42,9 +42,9 @@ function DialogContent({ onChange, onConfirm, }: { - seedThreadgate: ThreadgateSetting[] - onChange?: (v: ThreadgateSetting[]) => void - onConfirm?: (v: ThreadgateSetting[]) => void + seedThreadgate: ThreadgateAllowUISetting[] + onChange?: (v: ThreadgateAllowUISetting[]) => void + onConfirm?: (v: ThreadgateAllowUISetting[]) => void }) { const {_} = useLingui() const control = Dialog.useDialogContext() @@ -59,7 +59,7 @@ function DialogContent({ setDraft(seedThreadgate) // Reset draft. } - function updateThreadgate(nextThreadgate: ThreadgateSetting[]) { + function updateThreadgate(nextThreadgate: ThreadgateAllowUISetting[]) { setDraft(nextThreadgate) onChange?.(nextThreadgate) } @@ -72,9 +72,9 @@ function DialogContent({ updateThreadgate([{type: 'nobody'}]) } - const onPressAudience = (setting: ThreadgateSetting) => { + const onPressAudience = (setting: ThreadgateAllowUISetting) => { // remove nobody - let newSelected: ThreadgateSetting[] = draft.filter( + let newSelected: ThreadgateAllowUISetting[] = draft.filter( v => v.type !== 'nobody', ) // toggle diff --git a/src/lib/api/index.ts b/src/lib/api/index.ts index 12e30bf6c1..a869596335 100644 --- a/src/lib/api/index.ts +++ b/src/lib/api/index.ts @@ -12,7 +12,7 @@ import { import {AtUri} from '@atproto/api' import {logger} from '#/logger' -import {ThreadgateSetting} from '#/state/queries/threadgate' +import {ThreadgateAllowUISetting} from '#/state/queries/threadgate' import {isNetworkError} from 'lib/strings/errors' import {shortenLinks, stripInvalidMentions} from 'lib/strings/rich-text-manip' import {isNative, isWeb} from 'platform/detection' @@ -61,7 +61,7 @@ interface PostOpts { extLink?: ExternalEmbedDraft images?: ImageModel[] labels?: string[] - threadgate?: ThreadgateSetting[] + threadgate?: ThreadgateAllowUISetting[] onStateChange?: (state: string) => void langs?: string[] } @@ -277,7 +277,7 @@ export async function post(agent: BskyAgent, opts: PostOpts) { export async function createThreadgate( agent: BskyAgent, postUri: string, - threadgate: ThreadgateSetting[], + threadgate: ThreadgateAllowUISetting[], ) { let allow: ( | AppBskyFeedThreadgate.MentionRule diff --git a/src/state/queries/threadgate.ts b/src/state/queries/threadgate.ts index d591d35834..4ccb2c8505 100644 --- a/src/state/queries/threadgate.ts +++ b/src/state/queries/threadgate.ts @@ -8,15 +8,19 @@ import {useQuery} from '@tanstack/react-query' import {useAgent} from '#/state/session' -export type ThreadgateSetting = +export type ThreadgateAllowUISetting = | {type: 'nobody'} | {type: 'mention'} | {type: 'following'} | {type: 'list'; list: unknown} -export function threadgateViewToSettings( +/** + * Converts a full {@link AppBskyFeedThreadgate.Record} to a list of + * {@link ThreadgateAllowUISetting}, for use by app UI. + */ +export function threadgateViewToAllowUISetting( threadgate: AppBskyFeedDefs.ThreadgateView | undefined, -): ThreadgateSetting[] { +): ThreadgateAllowUISetting[] { const record = threadgate && AppBskyFeedThreadgate.isRecord(threadgate.record) && @@ -29,9 +33,9 @@ export function threadgateViewToSettings( if (!record.allow?.length) { return [{type: 'nobody'}] } - const settings: ThreadgateSetting[] = record.allow + const settings: ThreadgateAllowUISetting[] = record.allow .map(allow => { - let setting: ThreadgateSetting | undefined + let setting: ThreadgateAllowUISetting | undefined if (allow.$type === 'app.bsky.feed.threadgate#mentionRule') { setting = {type: 'mention'} } else if (allow.$type === 'app.bsky.feed.threadgate#followingRule') { diff --git a/src/view/com/composer/Composer.tsx b/src/view/com/composer/Composer.tsx index 08ce4441f0..ceec655e37 100644 --- a/src/view/com/composer/Composer.tsx +++ b/src/view/com/composer/Composer.tsx @@ -60,7 +60,7 @@ import { } from '#/state/preferences/languages' import {useProfileQuery} from '#/state/queries/profile' import {Gif} from '#/state/queries/tenor' -import {ThreadgateSetting} from '#/state/queries/threadgate' +import {ThreadgateAllowUISetting} from '#/state/queries/threadgate' import {useUploadVideo} from '#/state/queries/video/video' import {useAgent, useSession} from '#/state/session' import {useComposerControls} from '#/state/shell/composer' @@ -184,7 +184,7 @@ export const ComposePost = observer(function ComposePost({ const {extLink, setExtLink} = useExternalLinkFetch({setQuote}) const [extGif, setExtGif] = useState() const [labels, setLabels] = useState([]) - const [threadgate, setThreadgate] = useState([]) + const [threadgate, setThreadgate] = useState([]) const gallery = useMemo( () => new GalleryModel(initImageUris), diff --git a/src/view/com/composer/threadgate/ThreadgateBtn.tsx b/src/view/com/composer/threadgate/ThreadgateBtn.tsx index 6cf2eea2c4..139393cd7c 100644 --- a/src/view/com/composer/threadgate/ThreadgateBtn.tsx +++ b/src/view/com/composer/threadgate/ThreadgateBtn.tsx @@ -5,7 +5,7 @@ import {msg} from '@lingui/macro' import {useLingui} from '@lingui/react' import {isNative} from '#/platform/detection' -import {ThreadgateSetting} from '#/state/queries/threadgate' +import {ThreadgateAllowUISetting} from '#/state/queries/threadgate' import {useAnalytics} from 'lib/analytics/analytics' import {atoms as a, useTheme} from '#/alf' import {Button, ButtonIcon, ButtonText} from '#/components/Button' @@ -20,8 +20,8 @@ export function ThreadgateBtn({ onChange, style, }: { - threadgate: ThreadgateSetting[] - onChange: (v: ThreadgateSetting[]) => void + threadgate: ThreadgateAllowUISetting[] + onChange: (v: ThreadgateAllowUISetting[]) => void style?: StyleProp> }) { const {track} = useAnalytics()