From 108aba022bd7439997dd8afe0be4d8fa23d58c3f Mon Sep 17 00:00:00 2001 From: Samuel Newman Date: Mon, 23 Jun 2025 14:10:23 +0300 Subject: [PATCH] add button --- .../SubscribeProfileDialog.tsx | 56 +++++++++++++++---- 1 file changed, 45 insertions(+), 11 deletions(-) diff --git a/src/components/activity-notifications/SubscribeProfileDialog.tsx b/src/components/activity-notifications/SubscribeProfileDialog.tsx index cbdc4b800f..89ee455f3b 100644 --- a/src/components/activity-notifications/SubscribeProfileDialog.tsx +++ b/src/components/activity-notifications/SubscribeProfileDialog.tsx @@ -4,8 +4,10 @@ import {msg, Trans} from '@lingui/macro' import {useLingui} from '@lingui/react' import {createSanitizedDisplayName} from '#/lib/moderation/create-sanitized-display-name' +import {isNative} from '#/platform/detection' import {useTheme, web} from '#/alf' import {atoms as a} from '#/alf' +import {Button, type ButtonProps, ButtonText} from '#/components/Button' import * as Dialog from '#/components/Dialog' import * as Toggle from '#/components/forms/Toggle' import {Text} from '#/components/Typography' @@ -26,21 +28,24 @@ export function SubscribeProfileDialog({ ) } +// TEMP - should be derived from profile view +const initialState = { + posts: false, + replies: false, +} + function DialogInner({profile}: {profile: bsky.profile.AnyProfileView}) { const {_} = useLingui() const t = useTheme() - const [state, setState] = useState({ - posts: false, - replies: false, - corn: false, - }) + const control = Dialog.useDialogContext() + + const [state, setState] = useState(initialState) const values = useMemo(() => { - const {posts, replies, corn} = state + const {posts, replies} = state const res = [] if (posts) res.push('posts') if (replies) res.push('replies') - if (corn) res.push('corn') return res }, [state]) @@ -48,22 +53,40 @@ function DialogInner({profile}: {profile: bsky.profile.AnyProfileView}) { setState({ posts: newValues.includes('posts'), replies: newValues.includes('replies'), - corn: newValues.includes('corn'), }) + const buttonProps: Omit = useMemo(() => { + const isDirty = + state.posts !== initialState.posts || + state.replies !== initialState.replies + const hasAny = state.posts || state.replies + + if (isDirty) { + return { + label: _(msg`Save changes`), + color: hasAny ? 'primary' : 'negative', + } + } else { + return { + label: _(msg`Cancel`), + color: 'secondary', + } + } + }, [state, _]) + const name = createSanitizedDisplayName(profile, false) return ( - + - Get notified! + Keep me posted - Receive notifications when {name} posts + Get notified of this account’s activity @@ -94,6 +117,17 @@ function DialogInner({profile}: {profile: bsky.profile.AnyProfileView}) { + + {/* don't show cancel button on web */} + {(isNative || buttonProps.color !== 'secondary') && ( + + )}