From 69fc27ab6b00aec4b5fc7585304aa24702dbc6c8 Mon Sep 17 00:00:00 2001
From: Daniel Lautzenheiser <lautzd@gmail.com>
Date: Fri, 26 Apr 2024 11:15:28 -0400
Subject: [PATCH] fix: discard on mobile (#1107)

---
 .../components/entry-editor/EditorToolbar.css |  5 ++++
 .../components/entry-editor/EditorToolbar.tsx | 29 ++++++++++++++++---
 2 files changed, 30 insertions(+), 4 deletions(-)

diff --git a/packages/core/src/components/entry-editor/EditorToolbar.css b/packages/core/src/components/entry-editor/EditorToolbar.css
index b01dfdc0..9a59a75a 100644
--- a/packages/core/src/components/entry-editor/EditorToolbar.css
+++ b/packages/core/src/components/entry-editor/EditorToolbar.css
@@ -22,6 +22,11 @@
     lg:!hidden;
 }
 
+.CMS_EditorToolbar_discard-button {
+  @apply flex
+    lg:!hidden;
+}
+
 .CMS_EditorToolbar_delete-button {
   @apply flex
     lg:!hidden;
diff --git a/packages/core/src/components/entry-editor/EditorToolbar.tsx b/packages/core/src/components/entry-editor/EditorToolbar.tsx
index 93c429b8..296de4b8 100644
--- a/packages/core/src/components/entry-editor/EditorToolbar.tsx
+++ b/packages/core/src/components/entry-editor/EditorToolbar.tsx
@@ -29,8 +29,8 @@ import MenuGroup from '../common/menu/MenuGroup';
 import MenuItemButton from '../common/menu/MenuItemButton';
 import EditorWorkflowToolbarButtons from './EditorWorkflowToolbarButtons';
 
-import type { WorkflowStatus } from '@staticcms/core/constants/publishModes';
 import type { CollectionWithDefaults, EditorPersistOptions } from '@staticcms/core';
+import type { WorkflowStatus } from '@staticcms/core/constants/publishModes';
 import type { FC, MouseEventHandler } from 'react';
 
 import './EditorToolbar.css';
@@ -41,6 +41,7 @@ export const classes = generateClassNames('EditorToolbar', [
   'more-menu-button',
   'more-menu-label-icon',
   'preview-toggle',
+  'discard-button',
   'delete-button',
   'publish-button',
   'publish-button-icon',
@@ -419,14 +420,34 @@ const EditorToolbar: FC<EditorToolbarProps> = ({
           disabled={disabled}
         />
       ) : null}
-      {canDelete ? (
+      {hasChanged ? (
+        <IconButton
+          icon={TrashIcon}
+          key="discard-button"
+          title={t('editor.editorToolbar.discardChanges')}
+          color="warning"
+          variant="text"
+          onClick={handleDiscardDraft}
+          rootClassName={classes['discard-button']}
+          aria-label="discard chnages"
+          disabled={disabled}
+        />
+      ) : canDelete &&
+        (!useOpenAuthoring || hasUnpublishedChanges) &&
+        (!useWorkflow || workflowDeleteLabel) ? (
         <IconButton
           icon={TrashIcon}
           key="delete-button"
-          title={t('editor.editorToolbar.deleteEntry')}
+          title={useWorkflow ? t(workflowDeleteLabel!) : t('editor.editorToolbar.deleteEntry')}
           color="error"
           variant="text"
-          onClick={onDelete}
+          onClick={
+            useWorkflow &&
+            workflowDeleteLabel &&
+            workflowDeleteLabel !== 'editor.editorToolbar.deletePublishedEntry'
+              ? onDeleteUnpublishedChanges
+              : onDelete
+          }
           rootClassName={classes['delete-button']}
           aria-label="delete"
           disabled={disabled}