From c4dde4aba5f5c494dd0484f1253e00f4402c5818 Mon Sep 17 00:00:00 2001 From: Eric Bailey Date: Wed, 5 Feb 2025 09:26:51 -0600 Subject: [PATCH] WIP hook it up --- .../ModerationInteractionSettings/index.tsx | 122 +++++++++++++++--- 1 file changed, 107 insertions(+), 15 deletions(-) diff --git a/src/screens/ModerationInteractionSettings/index.tsx b/src/screens/ModerationInteractionSettings/index.tsx index 77610b5ccb..6c7c85caf2 100644 --- a/src/screens/ModerationInteractionSettings/index.tsx +++ b/src/screens/ModerationInteractionSettings/index.tsx @@ -1,12 +1,40 @@ +import React from 'react' import {View} from 'react-native' -import {Trans} from '@lingui/macro' +import {msg, Trans} from '@lingui/macro' +import {useLingui} from '@lingui/react' +import {AppBskyFeedDefs, AppBskyFeedPostgate, AtUri} from '@atproto/api' -import {useGutters} from '#/alf' +import {logger} from '#/logger' +import {useAgent, useSession} from '#/state/session' +import {atoms as a, useGutters} from '#/alf' import {PostInteractionSettingsForm} from '#/components/dialogs/PostInteractionSettingsDialog' import * as Layout from '#/components/Layout' +import {Admonition} from '#/components/Admonition' +import { + createPostgateQueryKey, + getPostgateRecord, + usePostgateQuery, + useWritePostgateMutation, +} from '#/state/queries/postgate' +import { + createPostgateRecord, + embeddingRules, +} from '#/state/queries/postgate/util' +import { + createThreadgateViewQueryKey, + getThreadgateView, + ThreadgateAllowUISetting, + threadgateViewToAllowUISetting, + useSetThreadgateAllowMutation, + useThreadgateViewQuery, + threadgateRecordToAllowUISetting, +} from '#/state/queries/threadgate' +import {usePreferencesQuery, UsePreferencesQueryResponse} from '#/state/queries/preferences' +import {Loader} from '#/components/Loader' export function Screen() { const gutters = useGutters(['base']) + const {data: preferences} = usePreferencesQuery() return ( @@ -19,21 +47,85 @@ export function Screen() { - - {}} - postgate={{ - $type: 'app.bsky.feed.postgate', - createdAt: new Date().toString(), - post: '', - }} - onChangePostgate={() => {}} - threadgateAllowUISettings={[]} - onChangeThreadgateAllowUISettings={() => {}} - /> + + + + The following settings will be applied automatically to all new + posts you create. + + + {preferences ? ( + + ) : ( + + + + )} ) } + +function Inner({preferences}: {preferences: UsePreferencesQueryResponse}) { + const {_} = useLingui() + const {currentAccount} = useSession() + const [isSaving, setIsSaving] = React.useState(false) + console.log(preferences) + + const [postgate, setPostgate] = React.useState(() => { + return createPostgateRecord({ + post: '', + embeddingRules: preferences.postInteractionSettings.postgateEmbeddingRules + }) + }) + const [allowUISettings, setAllowUISettings] = React.useState(() => { + return threadgateRecordToAllowUISetting({ + $type: 'app.bsky.feed.threadgate', + post: '', + createdAt: new Date().toString(), + allow: preferences.postInteractionSettings.threadgateAllowRules + }) + }) + + const onSave = React.useCallback(async () => { + setIsSaving(true) + + try { + const requests = [] + + if (postgate) { + // TODO + } + + if (allowUISettings) { + // TODO + } + } catch (e: any) { + logger.error(`Failed to save post interaction settings`, { + context: 'PostInteractionSettingsDialogControlledInner', + safeMessage: e.message, + }) + } finally { + setIsSaving(false) + } + }, [ + _, + postgate, + allowUISettings, + setIsSaving, + ]) + + return ( + <> + + + ) +}