From 94bd192b2eefafdc78e6395c4dab39cb3fcd577f Mon Sep 17 00:00:00 2001 From: "plebeius.eth" Date: Mon, 29 Jan 2024 15:29:34 +0100 Subject: [PATCH] style(subplebbit settings): add read only design for challenge settings and exclude --- .../subplebbit-settings.module.css | 4 + .../subplebbit-settings.tsx | 252 ++++++++++++------ 2 files changed, 174 insertions(+), 82 deletions(-) diff --git a/src/views/subplebbit/subplebbit-settings/subplebbit-settings.module.css b/src/views/subplebbit/subplebbit-settings/subplebbit-settings.module.css index 84b4bb11..71246efd 100644 --- a/src/views/subplebbit/subplebbit-settings/subplebbit-settings.module.css +++ b/src/views/subplebbit/subplebbit-settings/subplebbit-settings.module.css @@ -61,6 +61,10 @@ white-space: pre-wrap; } +.readOnlyRoleExclude { + font-size: 12px; +} + .saveOptions button { text-transform: lowercase; margin: 3px 5px; diff --git a/src/views/subplebbit/subplebbit-settings/subplebbit-settings.tsx b/src/views/subplebbit/subplebbit-settings/subplebbit-settings.tsx index 06f7fe8b..aa63a4e3 100644 --- a/src/views/subplebbit/subplebbit-settings/subplebbit-settings.tsx +++ b/src/views/subplebbit/subplebbit-settings/subplebbit-settings.tsx @@ -322,6 +322,7 @@ const challengesNames = ['text-math', 'captcha-canvas-v3', 'fail', 'blacklist', interface ChallengeSettingsProps { challenge: any; index: number; + isReadOnly: boolean; setSubmitStore: (data: Partial) => void; settings: any; showSettings: boolean; @@ -331,7 +332,7 @@ const rolesToExclude = ['moderator', 'admin', 'owner']; const actionsToExclude: Array<'post' | 'reply' | 'vote'> = ['post', 'reply', 'vote']; const customActions: Array<'non-post' | 'non-reply' | 'non-vote'> = ['non-post', 'non-reply', 'non-vote']; -const ChallengeSettings = ({ challenge, index, setSubmitStore, settings, showSettings }: ChallengeSettingsProps) => { +const ChallengeSettings = ({ challenge, index, isReadOnly, setSubmitStore, settings, showSettings }: ChallengeSettingsProps) => { const { name, options } = challenge || {}; const challengeSettings: OptionInput[] = getDefaultChallengeSettings(name); @@ -354,7 +355,7 @@ const ChallengeSettings = ({ challenge, index, setSubmitStore, settings, showSet setSubmitStore({ settings: { ...settings, challenges: updatedChallenges } }); }; - const [showExcludeSettings, setShowExcludeSettings] = useState(challenge.exclude.map(() => false)); + const [showExcludeSettings, setShowExcludeSettings] = useState(challenge.exclude.map(() => (isReadOnly ? true : false))); const toggleExcludeSettings = (excludeIndex: number) => { const newShowExcludeSettings = [...showExcludeSettings]; newShowExcludeSettings[excludeIndex] = !newShowExcludeSettings[excludeIndex]; @@ -432,93 +433,169 @@ const ChallengeSettings = ({ challenge, index, setSubmitStore, settings, showSet ))}
Exclude from challenge #{index + 1}
- + {!isReadOnly && ( + + )} {challenge.exclude.map((exclude: any, excludeIndex: number) => (
Exclude Combination #{excludeIndex + 1} - deleteExcludeCombination(excludeIndex)} title='delete combination' /> - + {!isReadOnly && deleteExcludeCombination(excludeIndex)} title='delete combination' />} + {!isReadOnly && ( + + )} {showExcludeSettings[excludeIndex] && ( <> -
- Users -
Exclude specific users by their addresses, separated by a comma
- handleExcludeAddress(excludeIndex, e.target.value)} - /> -
-
- Users with Karma -
Minimum post karma required:
- handleExcludeChange(excludeIndex, 'postScore', e.target.value)} /> -
Minimum comment karma required:
- handleExcludeChange(excludeIndex, 'postReply', e.target.value)} /> -
-
- Users by account age -
Minimum account age in seconds (eg. 86400 = 24h):
- handleExcludeChange(excludeIndex, 'firstCommentTimestamp', e.target.value)} - /> -
-
- Moderators -
Exclude a specific moderator role
- {rolesToExclude.map((role) => ( -
- -
- ))} -
-
- Actions -
Exclude a specific user action
- {actionsToExclude.map((action) => ( -
- -
- ))} - {customActions.map((action) => ( -
+ {isReadOnly && !exclude?.address ? null : ( +
+ Users +
Exclude specific users by their addresses, separated by a comma
+ {isReadOnly ? ( + {exclude?.address?.join(', ')} + ) : ( + handleExcludeAddress(excludeIndex, e.target.value)} + /> + )} +
+ )} + {isReadOnly && !exclude?.postScore && !exclude?.postReply ? null : ( +
+ Users with Karma + {isReadOnly && !exclude?.postScore ? null : ( + <> +
Minimum post karma required:
+ {isReadOnly ? ( + {exclude?.postScore} + ) : ( + handleExcludeChange(excludeIndex, 'postScore', e.target.value)} /> + )} + + )} + {isReadOnly && !exclude?.postReply ? null : ( + <> +
Minimum comment karma required:
+ {isReadOnly ? ( + {exclude?.postReply} + ) : ( + handleExcludeChange(excludeIndex, 'postReply', e.target.value)} /> + )} + + )} +
+ )} + {isReadOnly && !exclude?.firstCommentTimestamp ? null : ( +
+ Users by account age +
Minimum account age in seconds (eg. 86400 = 24h):
+ {isReadOnly ? ( + {exclude?.firstCommentTimestamp} + ) : ( + handleExcludeChange(excludeIndex, 'firstCommentTimestamp', e.target.value)} + /> + )} +
+ )} + {isReadOnly && !exclude?.role ? null : ( +
+ Moderators +
Exclude a specific moderator role
+ {rolesToExclude.map((role) => + isReadOnly && !exclude?.role?.includes(role) ? null : ( +
+ {isReadOnly ? ( + {role} excluded + ) : ( + + )} +
+ ), + )} +
+ )} + {isReadOnly && actionsToExclude.some((action) => exclude.hasOwnProperty(action)) ? null : ( +
+ Actions +
Exclude a specific user action
+ {actionsToExclude.map((action) => + isReadOnly && !exclude?.[action] ? null : ( +
+ {isReadOnly ? ( + {action} excluded + ) : ( + + )} +
+ ), + )} + {customActions.map((action) => + isReadOnly && exclude?.[action.replace('non-', '')] ? null : ( +
+ {isReadOnly ? ( + {action} excluded + ) : ( + + )} +
+ ), + )} +
+ )} + {isReadOnly && !exclude?.rateLimit ? null : ( +
+ Rate Limit +
Number of free user actions per hour:
+ {isReadOnly ? ( +
{exclude?.rateLimit}
+ ) : ( + handleExcludeChange(excludeIndex, 'rateLimit', e.target.value)} /> + )} + {isReadOnly && !exclude?.rateLimitChallengeSuccess ? null : ( -
- ))} -
-
- Rate Limit -
Number of free user actions per hour:
- handleExcludeChange(excludeIndex, 'rateLimit', e.target.value)} /> - -
+ )} +
+ )} )}
@@ -532,7 +609,7 @@ const Challenges = ({ isReadOnly, readOnlyChallenges }: { isReadOnly: boolean; r const { t } = useTranslation(); const { settings, setSubmitStore } = useSubplebbitSettingsStore(); const challenges = settings?.challenges || readOnlyChallenges || []; - const [showSettings, setShowSettings] = useState(challenges.map(() => false)); + const [showSettings, setShowSettings] = useState(challenges.map(() => (isReadOnly ? true : false))); const toggleSettings = (index: number) => { const newShowSettings = [...showSettings]; @@ -597,7 +674,14 @@ const Challenges = ({ isReadOnly, readOnlyChallenges }: { isReadOnly: boolean; r {showSettings[index] ? 'hide settings' : 'show settings'} )} - +
))} @@ -700,7 +784,11 @@ const SubplebbitSettings = () => {
- {!isReadOnly && } + {!isReadOnly && ( + + )} {showLoading && }