Add category selection to collection report modal (#39456)
This commit is contained in:
parent
291dda95da
commit
e85019c17e
@ -68,7 +68,7 @@ class Category extends PureComponent {
|
|||||||
render () {
|
render () {
|
||||||
const { category, startedFrom, rules, intl } = this.props;
|
const { category, startedFrom, rules, intl } = this.props;
|
||||||
|
|
||||||
const options = rules.length > 0 ? [
|
let options = rules.length > 0 ? [
|
||||||
'dislike',
|
'dislike',
|
||||||
'spam',
|
'spam',
|
||||||
'legal',
|
'legal',
|
||||||
@ -81,10 +81,21 @@ class Category extends PureComponent {
|
|||||||
'other',
|
'other',
|
||||||
];
|
];
|
||||||
|
|
||||||
|
if (startedFrom === 'collection') {
|
||||||
|
options = options.filter(item => item !== 'dislike');
|
||||||
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<NavigationFocusTarget as='h1' className='report-dialog-modal__title'>
|
<NavigationFocusTarget as='h1' className='report-dialog-modal__title'>
|
||||||
<FormattedMessage id='report.category.title' defaultMessage="Tell us what's going on with this {type}" values={{ type: intl.formatMessage(messages[startedFrom]) }} />
|
{startedFrom === 'collection' ? (
|
||||||
|
<FormattedMessage
|
||||||
|
id='report.collection_comment'
|
||||||
|
defaultMessage='Why do you want to report this collection?'
|
||||||
|
/>
|
||||||
|
) : (
|
||||||
|
<FormattedMessage id='report.category.title' defaultMessage="Tell us what's going on with this {type}" values={{ type: intl.formatMessage(messages[startedFrom]) }} />
|
||||||
|
)}
|
||||||
</NavigationFocusTarget>
|
</NavigationFocusTarget>
|
||||||
<p className='report-dialog-modal__lead'><FormattedMessage id='report.category.subtitle' defaultMessage='Choose the best match' /></p>
|
<p className='report-dialog-modal__lead'><FormattedMessage id='report.category.subtitle' defaultMessage='Choose the best match' /></p>
|
||||||
|
|
||||||
|
|||||||
@ -13,7 +13,9 @@ import { NavigationFocusTarget } from 'mastodon/components/navigation_focus_targ
|
|||||||
import { useAccount } from 'mastodon/hooks/useAccount';
|
import { useAccount } from 'mastodon/hooks/useAccount';
|
||||||
import { useAppDispatch } from 'mastodon/store';
|
import { useAppDispatch } from 'mastodon/store';
|
||||||
|
|
||||||
|
import Category from '../../report/category';
|
||||||
import Comment from '../../report/comment';
|
import Comment from '../../report/comment';
|
||||||
|
import Rules from '../../report/rules';
|
||||||
|
|
||||||
const messages = defineMessages({
|
const messages = defineMessages({
|
||||||
close: { id: 'lightbox.close', defaultMessage: 'Close' },
|
close: { id: 'lightbox.close', defaultMessage: 'Close' },
|
||||||
@ -60,8 +62,14 @@ export const ReportCollectionModal: React.FC<{
|
|||||||
'idle' | 'submitting' | 'submitted' | 'error'
|
'idle' | 'submitting' | 'submitted' | 'error'
|
||||||
>('idle');
|
>('idle');
|
||||||
|
|
||||||
const [step, setStep] = useState<'comment' | 'thanks'>('comment');
|
const [step, setStep] = useState<'category' | 'rules' | 'comment' | 'thanks'>(
|
||||||
|
'category',
|
||||||
|
);
|
||||||
|
|
||||||
|
const [category, setCategory] = useState<
|
||||||
|
'spam' | 'legal' | 'violation' | 'other' | null
|
||||||
|
>(null);
|
||||||
|
const [selectedRuleIds, setSelectedRuleIds] = useState<string[]>([]);
|
||||||
const [comment, setComment] = useState('');
|
const [comment, setComment] = useState('');
|
||||||
const [selectedDomains, setSelectedDomains] = useState<string[]>([]);
|
const [selectedDomains, setSelectedDomains] = useState<string[]>([]);
|
||||||
|
|
||||||
@ -73,6 +81,22 @@ export const ReportCollectionModal: React.FC<{
|
|||||||
}
|
}
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
|
const handleRuleToggle = useCallback((ruleId: string) => {
|
||||||
|
setSelectedRuleIds((ruleIds) =>
|
||||||
|
ruleIds.includes(ruleId)
|
||||||
|
? ruleIds.filter((id) => ruleId !== id)
|
||||||
|
: [...ruleIds, ruleId],
|
||||||
|
);
|
||||||
|
}, []);
|
||||||
|
|
||||||
|
const handleNextStep = useCallback(() => {
|
||||||
|
if (step === 'category' && category === 'violation') {
|
||||||
|
setStep('rules');
|
||||||
|
} else {
|
||||||
|
setStep('comment');
|
||||||
|
}
|
||||||
|
}, [category, step]);
|
||||||
|
|
||||||
const handleSubmit = useCallback(() => {
|
const handleSubmit = useCallback(() => {
|
||||||
setSubmitState('submitting');
|
setSubmitState('submitting');
|
||||||
|
|
||||||
@ -85,7 +109,8 @@ export const ReportCollectionModal: React.FC<{
|
|||||||
forward_to_domains: selectedDomains,
|
forward_to_domains: selectedDomains,
|
||||||
comment,
|
comment,
|
||||||
forward: selectedDomains.length > 0,
|
forward: selectedDomains.length > 0,
|
||||||
category: 'spam',
|
category: category ?? 'other',
|
||||||
|
rule_ids: selectedRuleIds,
|
||||||
},
|
},
|
||||||
() => {
|
() => {
|
||||||
setSubmitState('submitted');
|
setSubmitState('submitted');
|
||||||
@ -96,7 +121,15 @@ export const ReportCollectionModal: React.FC<{
|
|||||||
},
|
},
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
}, [account_id, comment, dispatch, collectionId, selectedDomains]);
|
}, [
|
||||||
|
account_id,
|
||||||
|
category,
|
||||||
|
selectedRuleIds,
|
||||||
|
comment,
|
||||||
|
dispatch,
|
||||||
|
collectionId,
|
||||||
|
selectedDomains,
|
||||||
|
]);
|
||||||
|
|
||||||
if (!account) {
|
if (!account) {
|
||||||
return null;
|
return null;
|
||||||
@ -108,15 +141,28 @@ export const ReportCollectionModal: React.FC<{
|
|||||||
let stepComponent;
|
let stepComponent;
|
||||||
|
|
||||||
switch (step) {
|
switch (step) {
|
||||||
|
case 'category':
|
||||||
|
stepComponent = (
|
||||||
|
<Category
|
||||||
|
onNextStep={handleNextStep}
|
||||||
|
startedFrom='collection'
|
||||||
|
category={category}
|
||||||
|
onChangeCategory={setCategory}
|
||||||
|
/>
|
||||||
|
);
|
||||||
|
break;
|
||||||
|
case 'rules':
|
||||||
|
stepComponent = (
|
||||||
|
<Rules
|
||||||
|
onNextStep={handleNextStep}
|
||||||
|
selectedRuleIds={selectedRuleIds}
|
||||||
|
onToggle={handleRuleToggle}
|
||||||
|
/>
|
||||||
|
);
|
||||||
|
break;
|
||||||
case 'comment':
|
case 'comment':
|
||||||
stepComponent = (
|
stepComponent = (
|
||||||
<Comment
|
<Comment
|
||||||
modalTitle={
|
|
||||||
<FormattedMessage
|
|
||||||
id='report.collection_comment'
|
|
||||||
defaultMessage='Why do you want to report this collection?'
|
|
||||||
/>
|
|
||||||
}
|
|
||||||
submitError={
|
submitError={
|
||||||
submitState === 'error' && (
|
submitState === 'error' && (
|
||||||
<Callout
|
<Callout
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user