mirror of
https://github.com/pacnpal/thrilltrack-explorer.git
synced 2025-12-21 16:51:13 -05:00
Fix: Show moderator edits in creation submissions
This commit is contained in:
@@ -229,10 +229,15 @@ export function SubmissionChangesDisplay({
|
|||||||
<h4 className="text-sm font-medium">Creation Data (with moderator edits highlighted)</h4>
|
<h4 className="text-sm font-medium">Creation Data (with moderator edits highlighted)</h4>
|
||||||
<div className="grid gap-2">
|
<div className="grid gap-2">
|
||||||
{changes.fieldChanges.map((change, idx) => {
|
{changes.fieldChanges.map((change, idx) => {
|
||||||
// Highlight fields that were modified (not just added)
|
// Highlight fields that were added OR modified by moderator
|
||||||
const wasEditedByModerator = change.changeType === 'modified' &&
|
const wasEditedByModerator = item.original_data &&
|
||||||
item.original_data &&
|
Object.keys(item.original_data).length > 0 &&
|
||||||
item.original_data[change.field] !== undefined;
|
(
|
||||||
|
// Field was modified from original value
|
||||||
|
(change.changeType === 'modified') ||
|
||||||
|
// Field was added by moderator (not in original submission)
|
||||||
|
(change.changeType === 'added' && item.original_data[change.field] === undefined)
|
||||||
|
);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div key={idx} className={wasEditedByModerator ? 'border-l-4 border-blue-500 pl-3 bg-blue-50/50 dark:bg-blue-950/30 rounded' : ''}>
|
<div key={idx} className={wasEditedByModerator ? 'border-l-4 border-blue-500 pl-3 bg-blue-50/50 dark:bg-blue-950/30 rounded' : ''}>
|
||||||
|
|||||||
@@ -157,21 +157,64 @@ export async function detectChanges(
|
|||||||
let hasLocationChange = false;
|
let hasLocationChange = false;
|
||||||
|
|
||||||
if (action === 'create') {
|
if (action === 'create') {
|
||||||
// For creates, all fields are "added" - be more permissive to show all data
|
// Check if this creation was edited by a moderator
|
||||||
Object.entries(itemData).forEach(([key, value]) => {
|
const hasModeratorEdits = originalData && Object.keys(originalData).length > 0;
|
||||||
// For creates, exclude only system fields and internal metadata
|
|
||||||
const systemFields = ['id', 'created_at', 'updated_at', 'slug', 'images', 'image_assignments'];
|
if (hasModeratorEdits) {
|
||||||
const shouldShow = !systemFields.includes(key) && value !== null && value !== undefined && value !== '';
|
// Compare item_data with original_data to detect moderator changes
|
||||||
|
const allKeys = new Set([
|
||||||
|
...Object.keys(itemData),
|
||||||
|
...Object.keys(originalData)
|
||||||
|
]);
|
||||||
|
|
||||||
if (shouldShow) {
|
allKeys.forEach(key => {
|
||||||
fieldChanges.push({
|
if (!shouldTrackField(key)) return;
|
||||||
field: key,
|
|
||||||
oldValue: null,
|
const oldValue = originalData[key];
|
||||||
newValue: value,
|
const newValue = itemData[key];
|
||||||
changeType: 'added',
|
|
||||||
});
|
// Skip if both are empty
|
||||||
}
|
const oldEmpty = oldValue === null || oldValue === undefined || oldValue === '';
|
||||||
});
|
const newEmpty = newValue === null || newValue === undefined || newValue === '';
|
||||||
|
|
||||||
|
if (oldEmpty && newEmpty) return;
|
||||||
|
|
||||||
|
// Detect the type of change
|
||||||
|
if (!isEqual(oldValue, newValue)) {
|
||||||
|
fieldChanges.push({
|
||||||
|
field: key,
|
||||||
|
oldValue,
|
||||||
|
newValue,
|
||||||
|
changeType: oldEmpty && !newEmpty ? 'added' : // Moderator added new field
|
||||||
|
newEmpty && !oldEmpty ? 'removed' : // Moderator removed field
|
||||||
|
'modified', // Moderator changed value
|
||||||
|
});
|
||||||
|
} else if (!newEmpty) {
|
||||||
|
// Field unchanged - show as 'added' (part of original submission)
|
||||||
|
fieldChanges.push({
|
||||||
|
field: key,
|
||||||
|
oldValue: null,
|
||||||
|
newValue,
|
||||||
|
changeType: 'added',
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
// No moderator edits - show all fields as 'added' (original behavior)
|
||||||
|
Object.entries(itemData).forEach(([key, value]) => {
|
||||||
|
const systemFields = ['id', 'created_at', 'updated_at', 'slug', 'images', 'image_assignments'];
|
||||||
|
const shouldShow = !systemFields.includes(key) && value !== null && value !== undefined && value !== '';
|
||||||
|
|
||||||
|
if (shouldShow) {
|
||||||
|
fieldChanges.push({
|
||||||
|
field: key,
|
||||||
|
oldValue: null,
|
||||||
|
newValue: value,
|
||||||
|
changeType: 'added',
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
} else if (action === 'edit') {
|
} else if (action === 'edit') {
|
||||||
// Compare each field
|
// Compare each field
|
||||||
const allKeys = new Set([
|
const allKeys = new Set([
|
||||||
|
|||||||
Reference in New Issue
Block a user