diff options
author | Eric Bailey <git@esb.lol> | 2025-02-28 17:14:02 -0600 |
---|---|---|
committer | GitHub <noreply@github.com> | 2025-02-28 17:14:02 -0600 |
commit | 3be9dde92d64ec540a9097f369d64580fae75fa0 (patch) | |
tree | 49fa640a660af26a51ffa9b3aab2d1b169210048 /src/components/moderation/ReportDialog/state.ts | |
parent | 96f4f6359add6a4f2a37df8f17cf3f2f59f0a2a6 (diff) | |
download | voidsky-3be9dde92d64ec540a9097f369d64580fae75fa0.tar.zst |
New reporting flow (#7832)
* Add option to align web dialogs to top * Add new wait util * Pipe through feed view to feed components * Reset unneeded change to main * Copy over fresh report dialog based on old * Hack in temp testing data * Swap in new dialog in all cases but chat * Cleanup * Add load and initial error state * Fill in states * Add copyright link * Handle single labeler case * Comment out debug code * Improve centering of type in circles * Open details if Other is selected * Remove debug code * Tweak colors * Bump SDK * Tweak Admonition for better x-platform styles * Add retry button * Add close button * Remove todo not covered in this PR * Translate Retry
Diffstat (limited to 'src/components/moderation/ReportDialog/state.ts')
-rw-r--r-- | src/components/moderation/ReportDialog/state.ts | 109 |
1 files changed, 109 insertions, 0 deletions
diff --git a/src/components/moderation/ReportDialog/state.ts b/src/components/moderation/ReportDialog/state.ts new file mode 100644 index 000000000..3f55bfb01 --- /dev/null +++ b/src/components/moderation/ReportDialog/state.ts @@ -0,0 +1,109 @@ +import {AppBskyLabelerDefs, ComAtprotoModerationDefs} from '@atproto/api' + +import {ReportOption} from './utils/useReportOptions' + +export type ReportState = { + selectedOption?: ReportOption + selectedLabeler?: AppBskyLabelerDefs.LabelerViewDetailed + details?: string + detailsOpen: boolean + activeStepIndex1: number + error?: string +} + +export type ReportAction = + | { + type: 'selectOption' + option: ReportOption + } + | { + type: 'clearOption' + } + | { + type: 'selectLabeler' + labeler: AppBskyLabelerDefs.LabelerViewDetailed + } + | { + type: 'clearLabeler' + } + | { + type: 'setDetails' + details: string + } + | { + type: 'setError' + error: string + } + | { + type: 'clearError' + } + | { + type: 'showDetails' + } + +export const initialState: ReportState = { + selectedOption: undefined, + selectedLabeler: undefined, + details: undefined, + detailsOpen: false, + activeStepIndex1: 1, +} + +export function reducer(state: ReportState, action: ReportAction): ReportState { + switch (action.type) { + case 'selectOption': + return { + ...state, + selectedOption: action.option, + activeStepIndex1: 2, + detailsOpen: + !!state.details || + action.option.reason === ComAtprotoModerationDefs.REASONOTHER, + } + case 'clearOption': + return { + ...state, + selectedOption: undefined, + selectedLabeler: undefined, + activeStepIndex1: 1, + detailsOpen: + !!state.details || + state.selectedOption?.reason === ComAtprotoModerationDefs.REASONOTHER, + } + case 'selectLabeler': + return { + ...state, + selectedLabeler: action.labeler, + activeStepIndex1: 3, + } + case 'clearLabeler': + return { + ...state, + selectedLabeler: undefined, + activeStepIndex1: 2, + detailsOpen: + !!state.details || + state.selectedOption?.reason === ComAtprotoModerationDefs.REASONOTHER, + } + case 'setDetails': + return { + ...state, + details: action.details, + } + case 'setError': + return { + ...state, + error: action.error, + } + case 'clearError': + return { + ...state, + error: undefined, + } + case 'showDetails': + return { + ...state, + detailsOpen: true, + } + } +} |