Do some renaming for clarity

This commit is contained in:
Eric Bailey
2024-08-05 09:59:48 -05:00
parent 571d00cf41
commit dcb6aa41cc
6 changed files with 37 additions and 33 deletions
+10 -10
View File
@@ -20,8 +20,8 @@ import {isNative} from '#/platform/detection'
import {RQKEY_ROOT as POST_THREAD_RQKEY_ROOT} from '#/state/queries/post-thread' import {RQKEY_ROOT as POST_THREAD_RQKEY_ROOT} from '#/state/queries/post-thread'
import {threadgateRecordQueryKeyRoot} from '#/state/queries/threadgate' import {threadgateRecordQueryKeyRoot} from '#/state/queries/threadgate'
import { import {
ThreadgateSetting, ThreadgateAllowUISetting,
threadgateViewToSettings, threadgateViewToAllowUISetting,
} from '#/state/queries/threadgate' } from '#/state/queries/threadgate'
import {useAgent} from '#/state/session' import {useAgent} from '#/state/session'
import * as Toast from 'view/com/util/Toast' import * as Toast from 'view/com/util/Toast'
@@ -52,7 +52,7 @@ export function WhoCanReply({post, isThreadAuthor, style}: WhoCanReplyProps) {
const queryClient = useQueryClient() const queryClient = useQueryClient()
const settings = React.useMemo( const settings = React.useMemo(
() => threadgateViewToSettings(post.threadgate), () => threadgateViewToAllowUISetting(post.threadgate),
[post], [post],
) )
const isRootPost = !('reply' in post.record) 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)) { if (JSON.stringify(settings) === JSON.stringify(newSettings)) {
return return
} }
@@ -100,7 +100,7 @@ export function WhoCanReply({post, isThreadAuthor, style}: WhoCanReplyProps) {
await whenAppViewReady(agent, post.uri, res => { await whenAppViewReady(agent, post.uri, res => {
const thread = res.data.thread const thread = res.data.thread
if (AppBskyFeedDefs.isThreadViewPost(thread)) { if (AppBskyFeedDefs.isThreadViewPost(thread)) {
const fetchedSettings = threadgateViewToSettings( const fetchedSettings = threadgateViewToAllowUISetting(
thread.post.threadgate, thread.post.threadgate,
) )
return JSON.stringify(fetchedSettings) === JSON.stringify(newSettings) return JSON.stringify(fetchedSettings) === JSON.stringify(newSettings)
@@ -178,7 +178,7 @@ function Icon({
}: { }: {
color: string color: string
width?: number width?: number
settings: ThreadgateSetting[] settings: ThreadgateAllowUISetting[]
}) { }) {
const isEverybody = settings.length === 0 const isEverybody = settings.length === 0
const isNobody = !!settings.find(gate => gate.type === 'nobody') const isNobody = !!settings.find(gate => gate.type === 'nobody')
@@ -193,7 +193,7 @@ function WhoCanReplyDialog({
}: { }: {
control: Dialog.DialogControlProps control: Dialog.DialogControlProps
post: AppBskyFeedDefs.PostView post: AppBskyFeedDefs.PostView
settings: ThreadgateSetting[] settings: ThreadgateAllowUISetting[]
}) { }) {
return ( return (
<Dialog.Outer control={control}> <Dialog.Outer control={control}>
@@ -208,7 +208,7 @@ function WhoCanReplyDialogInner({
settings, settings,
}: { }: {
post: AppBskyFeedDefs.PostView post: AppBskyFeedDefs.PostView
settings: ThreadgateSetting[] settings: ThreadgateAllowUISetting[]
}) { }) {
const {_} = useLingui() const {_} = useLingui()
return ( return (
@@ -230,7 +230,7 @@ function Rules({
settings, settings,
}: { }: {
post: AppBskyFeedDefs.PostView post: AppBskyFeedDefs.PostView
settings: ThreadgateSetting[] settings: ThreadgateAllowUISetting[]
}) { }) {
const t = useTheme() const t = useTheme()
return ( return (
@@ -271,7 +271,7 @@ function Rule({
post, post,
lists, lists,
}: { }: {
rule: ThreadgateSetting rule: ThreadgateAllowUISetting
post: AppBskyFeedDefs.PostView post: AppBskyFeedDefs.PostView
lists: AppBskyGraphDefs.ListViewBasic[] | undefined lists: AppBskyGraphDefs.ListViewBasic[] | undefined
}) { }) {
+10 -10
View File
@@ -5,7 +5,7 @@ import {useLingui} from '@lingui/react'
import isEqual from 'lodash.isequal' import isEqual from 'lodash.isequal'
import {useMyListsQuery} from '#/state/queries/my-lists' 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 {atoms as a, useTheme} from '#/alf'
import {Button, ButtonText} from '#/components/Button' import {Button, ButtonText} from '#/components/Button'
import * as Dialog from '#/components/Dialog' import * as Dialog from '#/components/Dialog'
@@ -14,9 +14,9 @@ import {Text} from '#/components/Typography'
interface ThreadgateEditorDialogProps { interface ThreadgateEditorDialogProps {
control: Dialog.DialogControlProps control: Dialog.DialogControlProps
threadgate: ThreadgateSetting[] threadgate: ThreadgateAllowUISetting[]
onChange?: (v: ThreadgateSetting[]) => void onChange?: (v: ThreadgateAllowUISetting[]) => void
onConfirm?: (v: ThreadgateSetting[]) => void onConfirm?: (v: ThreadgateAllowUISetting[]) => void
} }
export function ThreadgateEditorDialog({ export function ThreadgateEditorDialog({
@@ -42,9 +42,9 @@ function DialogContent({
onChange, onChange,
onConfirm, onConfirm,
}: { }: {
seedThreadgate: ThreadgateSetting[] seedThreadgate: ThreadgateAllowUISetting[]
onChange?: (v: ThreadgateSetting[]) => void onChange?: (v: ThreadgateAllowUISetting[]) => void
onConfirm?: (v: ThreadgateSetting[]) => void onConfirm?: (v: ThreadgateAllowUISetting[]) => void
}) { }) {
const {_} = useLingui() const {_} = useLingui()
const control = Dialog.useDialogContext() const control = Dialog.useDialogContext()
@@ -59,7 +59,7 @@ function DialogContent({
setDraft(seedThreadgate) // Reset draft. setDraft(seedThreadgate) // Reset draft.
} }
function updateThreadgate(nextThreadgate: ThreadgateSetting[]) { function updateThreadgate(nextThreadgate: ThreadgateAllowUISetting[]) {
setDraft(nextThreadgate) setDraft(nextThreadgate)
onChange?.(nextThreadgate) onChange?.(nextThreadgate)
} }
@@ -72,9 +72,9 @@ function DialogContent({
updateThreadgate([{type: 'nobody'}]) updateThreadgate([{type: 'nobody'}])
} }
const onPressAudience = (setting: ThreadgateSetting) => { const onPressAudience = (setting: ThreadgateAllowUISetting) => {
// remove nobody // remove nobody
let newSelected: ThreadgateSetting[] = draft.filter( let newSelected: ThreadgateAllowUISetting[] = draft.filter(
v => v.type !== 'nobody', v => v.type !== 'nobody',
) )
// toggle // toggle
+3 -3
View File
@@ -12,7 +12,7 @@ import {
import {AtUri} from '@atproto/api' import {AtUri} from '@atproto/api'
import {logger} from '#/logger' import {logger} from '#/logger'
import {ThreadgateSetting} from '#/state/queries/threadgate' import {ThreadgateAllowUISetting} from '#/state/queries/threadgate'
import {isNetworkError} from 'lib/strings/errors' import {isNetworkError} from 'lib/strings/errors'
import {shortenLinks, stripInvalidMentions} from 'lib/strings/rich-text-manip' import {shortenLinks, stripInvalidMentions} from 'lib/strings/rich-text-manip'
import {isNative, isWeb} from 'platform/detection' import {isNative, isWeb} from 'platform/detection'
@@ -61,7 +61,7 @@ interface PostOpts {
extLink?: ExternalEmbedDraft extLink?: ExternalEmbedDraft
images?: ImageModel[] images?: ImageModel[]
labels?: string[] labels?: string[]
threadgate?: ThreadgateSetting[] threadgate?: ThreadgateAllowUISetting[]
onStateChange?: (state: string) => void onStateChange?: (state: string) => void
langs?: string[] langs?: string[]
} }
@@ -277,7 +277,7 @@ export async function post(agent: BskyAgent, opts: PostOpts) {
export async function createThreadgate( export async function createThreadgate(
agent: BskyAgent, agent: BskyAgent,
postUri: string, postUri: string,
threadgate: ThreadgateSetting[], threadgate: ThreadgateAllowUISetting[],
) { ) {
let allow: ( let allow: (
| AppBskyFeedThreadgate.MentionRule | AppBskyFeedThreadgate.MentionRule
+9 -5
View File
@@ -8,15 +8,19 @@ import {useQuery} from '@tanstack/react-query'
import {useAgent} from '#/state/session' import {useAgent} from '#/state/session'
export type ThreadgateSetting = export type ThreadgateAllowUISetting =
| {type: 'nobody'} | {type: 'nobody'}
| {type: 'mention'} | {type: 'mention'}
| {type: 'following'} | {type: 'following'}
| {type: 'list'; list: unknown} | {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, threadgate: AppBskyFeedDefs.ThreadgateView | undefined,
): ThreadgateSetting[] { ): ThreadgateAllowUISetting[] {
const record = const record =
threadgate && threadgate &&
AppBskyFeedThreadgate.isRecord(threadgate.record) && AppBskyFeedThreadgate.isRecord(threadgate.record) &&
@@ -29,9 +33,9 @@ export function threadgateViewToSettings(
if (!record.allow?.length) { if (!record.allow?.length) {
return [{type: 'nobody'}] return [{type: 'nobody'}]
} }
const settings: ThreadgateSetting[] = record.allow const settings: ThreadgateAllowUISetting[] = record.allow
.map(allow => { .map(allow => {
let setting: ThreadgateSetting | undefined let setting: ThreadgateAllowUISetting | undefined
if (allow.$type === 'app.bsky.feed.threadgate#mentionRule') { if (allow.$type === 'app.bsky.feed.threadgate#mentionRule') {
setting = {type: 'mention'} setting = {type: 'mention'}
} else if (allow.$type === 'app.bsky.feed.threadgate#followingRule') { } else if (allow.$type === 'app.bsky.feed.threadgate#followingRule') {
+2 -2
View File
@@ -60,7 +60,7 @@ import {
} from '#/state/preferences/languages' } from '#/state/preferences/languages'
import {useProfileQuery} from '#/state/queries/profile' import {useProfileQuery} from '#/state/queries/profile'
import {Gif} from '#/state/queries/tenor' 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 {useUploadVideo} from '#/state/queries/video/video'
import {useAgent, useSession} from '#/state/session' import {useAgent, useSession} from '#/state/session'
import {useComposerControls} from '#/state/shell/composer' import {useComposerControls} from '#/state/shell/composer'
@@ -184,7 +184,7 @@ export const ComposePost = observer(function ComposePost({
const {extLink, setExtLink} = useExternalLinkFetch({setQuote}) const {extLink, setExtLink} = useExternalLinkFetch({setQuote})
const [extGif, setExtGif] = useState<Gif>() const [extGif, setExtGif] = useState<Gif>()
const [labels, setLabels] = useState<string[]>([]) const [labels, setLabels] = useState<string[]>([])
const [threadgate, setThreadgate] = useState<ThreadgateSetting[]>([]) const [threadgate, setThreadgate] = useState<ThreadgateAllowUISetting[]>([])
const gallery = useMemo( const gallery = useMemo(
() => new GalleryModel(initImageUris), () => new GalleryModel(initImageUris),
@@ -5,7 +5,7 @@ import {msg} from '@lingui/macro'
import {useLingui} from '@lingui/react' import {useLingui} from '@lingui/react'
import {isNative} from '#/platform/detection' import {isNative} from '#/platform/detection'
import {ThreadgateSetting} from '#/state/queries/threadgate' import {ThreadgateAllowUISetting} from '#/state/queries/threadgate'
import {useAnalytics} from 'lib/analytics/analytics' import {useAnalytics} from 'lib/analytics/analytics'
import {atoms as a, useTheme} from '#/alf' import {atoms as a, useTheme} from '#/alf'
import {Button, ButtonIcon, ButtonText} from '#/components/Button' import {Button, ButtonIcon, ButtonText} from '#/components/Button'
@@ -20,8 +20,8 @@ export function ThreadgateBtn({
onChange, onChange,
style, style,
}: { }: {
threadgate: ThreadgateSetting[] threadgate: ThreadgateAllowUISetting[]
onChange: (v: ThreadgateSetting[]) => void onChange: (v: ThreadgateAllowUISetting[]) => void
style?: StyleProp<AnimatedStyle<ViewStyle>> style?: StyleProp<AnimatedStyle<ViewStyle>>
}) { }) {
const {track} = useAnalytics() const {track} = useAnalytics()