diff --git a/src/components/Hack/VersionActions.tsx b/src/components/Hack/VersionActions.tsx index e2e4780..64c3faa 100644 --- a/src/components/Hack/VersionActions.tsx +++ b/src/components/Hack/VersionActions.tsx @@ -40,6 +40,7 @@ interface VersionActionsProps { isCurrent: boolean; hackSlug: string; baseRom: string; + currentPatchCreatedAt: string | null; onActionComplete: () => void; } @@ -48,6 +49,7 @@ export default function VersionActions({ isCurrent, hackSlug, baseRom, + currentPatchCreatedAt, onActionComplete, }: VersionActionsProps) { const { isLinked, hasPermission, hasCached, importUploadedBlob, ensurePermission, getFileBlob, supported } = useBaseRoms(); @@ -75,6 +77,14 @@ export default function VersionActions({ const baseRomNeedsPermission = baseRom && isLinked(baseRom) && !baseRomReady; const baseRomMissing = baseRom && !isLinked(baseRom) && !hasCached(baseRom); + // Determine if this patch is newer than the current patch + const isNewerThanCurrent = currentPatchCreatedAt + ? new Date(patch.created_at).getTime() > new Date(currentPatchCreatedAt).getTime() + : false; + + // Don't show Rollback if the patch is unpublished and newer than the current version + const shouldShowRollback = !isCurrent && !(!patch.published && isNewerThanCurrent); + useEffect(() => { if (showDeleteModal || showRestoreModal || showRollbackModal || showPublishModal || showReuploadModal) { const html = document.documentElement; @@ -469,26 +479,26 @@ export default function VersionActions({ Re-upload - {!isCurrent && ( - <> - + {shouldShowRollback && ( + + )} - - + {!isCurrent && ( + )} @@ -534,26 +544,30 @@ export default function VersionActions({ Re-upload - {!isCurrent && ( + {(!isCurrent || shouldShowRollback) && ( <> - setShowRollbackModal(true)} - className="flex w-full items-center gap-3 px-3 py-2 text-left text-sm data-focus:bg-black/5 dark:data-focus:bg-white/10" - > - - Rollback - + {shouldShowRollback && ( + setShowRollbackModal(true)} + className="flex w-full items-center gap-3 px-3 py-2 text-left text-sm data-focus:bg-black/5 dark:data-focus:bg-white/10" + > + + Rollback + + )} - setShowDeleteModal(true)} - className="flex w-full items-center gap-3 px-3 py-2 text-left text-sm text-red-600 data-focus:bg-red-600/10" - > - - Archive - + {!isCurrent && ( + setShowDeleteModal(true)} + className="flex w-full items-center gap-3 px-3 py-2 text-left text-sm text-red-600 data-focus:bg-red-600/10" + > + + Archive + + )} )} diff --git a/src/components/Hack/VersionList.tsx b/src/components/Hack/VersionList.tsx index 2ed3a4f..39e4057 100644 --- a/src/components/Hack/VersionList.tsx +++ b/src/components/Hack/VersionList.tsx @@ -115,6 +115,8 @@ export default function VersionList({ patches, currentPatchId, canEdit, hackSlug const hasChangelog = patch.changelog && patch.changelog.trim().length > 0; const isExpanded = expandedChangelogs.has(patch.id); const isEditing = editingChangelog === patch.id; + const currentPatch = allPatches.find(p => p.id === currentPatchId); + const currentPatchCreatedAt = currentPatch?.created_at || null; return (
{ router.refresh(); setEditingChangelog(null);