Skip to content
This repository has been archived by the owner on Apr 29, 2022. It is now read-only.

Commit

Permalink
handle content deletion #11
Browse files Browse the repository at this point in the history
  • Loading branch information
sballesteros committed Nov 22, 2019
1 parent 8982159 commit e196005
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 37 deletions.
73 changes: 41 additions & 32 deletions src/components/moderate.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,10 @@ import ModerationCard from './moderation-card';
export default function Moderate() {
const [user] = useUser();
const [bookmark, setBookmark] = useState(null);
const [excluded, setExcluded] = useState(new Set());

const search = createModerationQs({ bookmark });

// TODO set of exluded content

const [results, progress] = useActionsSearchResults(search, !!bookmark);

const [isOpenedMap, setIsOpenedMap] = useState(
Expand Down Expand Up @@ -56,36 +55,46 @@ export default function Moderate() {
) : (
<div>
<ul className="moderate__card-list">
{results.rows.map(({ doc }) => (
<li key={getId(doc)}>
<ModerationCard
user={user}
reviewAction={doc}
isOpened={isOpenedMap[getId(doc)] || false}
isLockedBy={undefined /* TODO wire */}
onOpen={() => {
setIsOpenedMap(
results.rows.reduce((map, row) => {
map[getId(row.doc)] = getId(row.doc) === getId(doc);
return map;
}, {})
);
}}
onSuccess={moderationAction => {
// TODO add a `exclude` params to the search qs so that we refresh the results in a safe way
console.log('moderationAction', moderationAction);
}}
onClose={() => {
setIsOpenedMap(
results.rows.reduce((map, row) => {
map[getId(row.doc)] = false;
return map;
}, {})
);
}}
/>
</li>
))}
{results.rows
.filter(row => !excluded.has(getId(row.doc)))
.map(({ doc }) => (
<li key={getId(doc)}>
<ModerationCard
user={user}
reviewAction={doc}
isOpened={isOpenedMap[getId(doc)] || false}
isLockedBy={undefined /* TODO wire */}
onOpen={() => {
setIsOpenedMap(
results.rows.reduce((map, row) => {
map[getId(row.doc)] = getId(row.doc) === getId(doc);
return map;
}, {})
);
}}
onSuccess={(moderationActionType, reviewActionId) => {
if (
moderationActionType ===
'ModerateRapidPREreviewAction' ||
moderationActionType ===
'IgnoreReportRapidPREreviewAction'
) {
setExcluded(
new Set(Array.from(excluded).concat(reviewActionId))
);
}
}}
onClose={() => {
setIsOpenedMap(
results.rows.reduce((map, row) => {
map[getId(row.doc)] = false;
return map;
}, {})
);
}}
/>
</li>
))}
</ul>
</div>
)}
Expand Down
4 changes: 1 addition & 3 deletions src/components/moderation-card.js
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,6 @@ function ModerationCardModal({
moderationReason: ref.current.value
},
body => {
onSuccess(body);
setFrame('success');
}
);
Expand Down Expand Up @@ -324,7 +323,6 @@ function ModerationCardModal({
moderationReason: ref.current.value
},
body => {
onSuccess(body);
setFrame('success');
}
);
Expand Down Expand Up @@ -373,7 +371,6 @@ function ModerationCardModal({
moderationReason: ref.current.value
},
body => {
onSuccess(body);
setFrame('success');
}
);
Expand All @@ -396,6 +393,7 @@ function ModerationCardModal({
<Controls>
<Button
onClick={() => {
onSuccess(defaultFrame, getId(reviewAction));
onClose();
}}
>
Expand Down
11 changes: 9 additions & 2 deletions src/middlewares/cache.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,10 @@ function getOnlyIfValue(obj = {}) {
return obj._rev;

default:
throw createError(500, 'getOnlyIfValue: invalid type for obj');
throw createError(
500,
`getOnlyIfValue: invalid type for obj (got ${obj['@type']})`
);
}
}

Expand Down Expand Up @@ -196,7 +199,11 @@ export function invalidate() {
case 'ModerateRapidPREreviewAction':
case 'RequestForRapidPREreviewAction':
case 'RapidPREreviewAction': {
if (action['@type'] === 'ModerateRapidPREreviewAction') {
if (
action['@type'] === 'ModerateRapidPREreviewAction' ||
action['@type'] === 'ReportRapidPREreviewAction' ||
action['@type'] === 'IgnoreReportRapidPREreviewAction'
) {
action = action.result;
}

Expand Down

0 comments on commit e196005

Please sign in to comment.