Skip to content

feat(viewer): add unsaved change confirm dialog (#3069)#322

Merged
HFO4 merged 3 commits intocloudreve:masterfrom
YUDONGLING:feat-editer-close-confirmation-20251217.1
Jan 3, 2026
Merged

feat(viewer): add unsaved change confirm dialog (#3069)#322
HFO4 merged 3 commits intocloudreve:masterfrom
YUDONGLING:feat-editer-close-confirmation-20251217.1

Conversation

@YUDONGLING
Copy link
Member

@YUDONGLING YUDONGLING commented Dec 17, 2025

Fixed to cloudreve/cloudreve#3069.

& i18n item for Polish given by AI: You have unsaved changes. Still discard?Niezapisane zmiany. Czy na pewno zamknąć?, would this be ok? @LukaszOn.

Close cloudreve/cloudreve#3069.

@LukaszOn
Copy link

A more correct translation to "You have unsaved changes. Still discard?" would be "Masz niezapisane zmiany. Czy na pewno chcesz je odrzucić?"

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR adds an unsaved changes confirmation dialog when users attempt to close the Markdown or Code viewer with unsaved modifications. The feature prevents accidental data loss by prompting users to confirm before discarding their changes when closing via backdrop click or ESC key.

Key Changes:

  • Implements handleDialogClose handlers in both MarkdownViewer and CodeViewer that check for unsaved changes before closing
  • Modifies ViewerDialog to pass a custom close reason when the X button is clicked
  • Adds the discardUnsavedConfirm i18n key across 11 language locales

Reviewed changes

Copilot reviewed 14 out of 14 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
src/component/Viewers/ViewerDialog.tsx Modified close button handler to pass custom "closeButtonClick" reason instead of standard "backdropClick"
src/component/Viewers/MarkdownEditor/MarkdownViewer.tsx Added handleDialogClose that shows confirmation dialog when closing with unsaved changes via backdrop/ESC
src/component/Viewers/CodeViewer/CodeViewer.tsx Added handleDialogClose that shows confirmation dialog when closing with unsaved changes via backdrop/ESC
public/locales/zh-TW/application.json Added Traditional Chinese translation for unsaved changes confirmation
public/locales/zh-CN/application.json Added Simplified Chinese translation for unsaved changes confirmation
public/locales/ru-RU/application.json Added Russian translation for unsaved changes confirmation
public/locales/pt-BR/application.json Added Brazilian Portuguese translation for unsaved changes confirmation
public/locales/ko-KR/application.json Added Korean translation for unsaved changes confirmation
public/locales/ja-JP/application.json Added Japanese translation for unsaved changes confirmation
public/locales/it-IT/application.json Added Italian translation for unsaved changes confirmation
public/locales/fr-FR/application.json Added French translation for unsaved changes confirmation
public/locales/es-ES/application.json Added Spanish translation for unsaved changes confirmation
public/locales/en-US/application.json Added English translation for unsaved changes confirmation
public/locales/de-DE/application.json Added German translation for unsaved changes confirmation

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

const [fullScreen, setFullScreen] = useState(props.fullScreen || isMobile);
const onClose = useCallback(() => {
props.dialogProps.onClose && props.dialogProps.onClose({}, "backdropClick");
props.dialogProps.onClose && props.dialogProps.onClose({}, "closeButtonClick" as any);
Copy link

Copilot AI Dec 17, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The custom "closeButtonClick" reason bypasses the unsaved changes confirmation dialog. This means users clicking the X button will lose unsaved changes without warning, while clicking the backdrop or pressing ESC shows the confirmation. For better UX and data protection, the X button should also trigger the confirmation when there are unsaved changes. Consider removing this custom reason and letting the X button trigger the standard confirmation flow.

Suggested change
props.dialogProps.onClose && props.dialogProps.onClose({}, "closeButtonClick" as any);
if (props.dialogProps.onClose) {
props.dialogProps.onClose({}, "backdropClick");
}

Copilot uses AI. Check for mistakes.
@YUDONGLING
Copy link
Member Author

A more correct translation to "You have unsaved changes. Still discard?" would be "Masz niezapisane zmiany. Czy na pewno chcesz je odrzucić?"

Great, i will update the translate later.

YUDONGLING and others added 2 commits December 17, 2025 22:46
@HFO4 HFO4 merged commit 294214d into cloudreve:master Jan 3, 2026
1 check passed
@HFO4
Copy link
Member

HFO4 commented Jan 3, 2026

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

在线编辑后退出应当询问用户是否保存更改

4 participants