Преглед изворни кода

feat: Show active file name when saving to current file (#3733)

* feat: Show active file name when saving to current file

* Make requested changes

* More changes
vanilla_orig
Arun пре 3 година
родитељ
комит
74a2f16501
No account linked to committer's email address

+ 6
- 9
src/actions/actionExport.tsx Прегледај датотеку

@@ -1,6 +1,6 @@
1 1
 import React from "react";
2 2
 import { trackEvent } from "../analytics";
3
-import { load, questionCircle, save, saveAs } from "../components/icons";
3
+import { load, questionCircle, saveAs } from "../components/icons";
4 4
 import { ProjectName } from "../components/ProjectName";
5 5
 import { ToolButton } from "../components/ToolButton";
6 6
 import "../components/ToolIcon.scss";
@@ -17,6 +17,7 @@ import { getExportSize } from "../scene/export";
17 17
 import { DEFAULT_EXPORT_PADDING, EXPORT_SCALES } from "../constants";
18 18
 import { getSelectedElements, isSomeElementSelected } from "../scene";
19 19
 import { getNonDeletedElements } from "../element";
20
+import { ActiveFile } from "../components/ActiveFile";
20 21
 
21 22
 export const actionChangeProjectName = register({
22 23
   name: "changeProjectName",
@@ -153,14 +154,10 @@ export const actionSaveToActiveFile = register({
153 154
   },
154 155
   keyTest: (event) =>
155 156
     event.key === KEYS.S && event[KEYS.CTRL_OR_CMD] && !event.shiftKey,
156
-  PanelComponent: ({ updateData }) => (
157
-    <ToolButton
158
-      type="icon"
159
-      icon={save}
160
-      title={t("buttons.save")}
161
-      aria-label={t("buttons.save")}
162
-      onClick={() => updateData(null)}
163
-      data-testid="save-button"
157
+  PanelComponent: ({ updateData, appState }) => (
158
+    <ActiveFile
159
+      onSave={() => updateData(null)}
160
+      fileName={appState.fileHandle?.name}
164 161
     />
165 162
   ),
166 163
 });

+ 21
- 0
src/components/ActiveFile.scss Прегледај датотеку

@@ -0,0 +1,21 @@
1
+.excalidraw {
2
+  .ActiveFile {
3
+    .ActiveFile__fileName {
4
+      display: flex;
5
+      align-items: center;
6
+
7
+      span {
8
+        text-overflow: ellipsis;
9
+        overflow: hidden;
10
+        white-space: nowrap;
11
+        width: 9.3em;
12
+      }
13
+
14
+      svg {
15
+        width: 1.15em;
16
+        margin-inline-end: 0.3em;
17
+        transform: scaleY(0.9);
18
+      }
19
+    }
20
+  }
21
+}

+ 29
- 0
src/components/ActiveFile.tsx Прегледај датотеку

@@ -0,0 +1,29 @@
1
+import React from "react";
2
+import Stack from "../components/Stack";
3
+import { ToolButton } from "../components/ToolButton";
4
+import { save, file } from "../components/icons";
5
+import { t } from "../i18n";
6
+
7
+import "./ActiveFile.scss";
8
+
9
+type ActiveFileProps = {
10
+  fileName?: string;
11
+  onSave: () => void;
12
+};
13
+
14
+export const ActiveFile = ({ fileName, onSave }: ActiveFileProps) => (
15
+  <Stack.Row className="ActiveFile" gap={1} align="center">
16
+    <span className="ActiveFile__fileName">
17
+      {file}
18
+      <span>{fileName}</span>
19
+    </span>
20
+    <ToolButton
21
+      type="icon"
22
+      icon={save}
23
+      title={t("buttons.save")}
24
+      aria-label={t("buttons.save")}
25
+      onClick={onSave}
26
+      data-testid="save-button"
27
+    />
28
+  </Stack.Row>
29
+);

+ 0
- 5
src/components/BackgroundPickerAndDarkModeToggle.tsx Прегледај датотеку

@@ -16,10 +16,5 @@ export const BackgroundPickerAndDarkModeToggle = ({
16 16
   <div style={{ display: "flex" }}>
17 17
     {actionManager.renderAction("changeViewBackgroundColor")}
18 18
     {showThemeBtn && actionManager.renderAction("toggleTheme")}
19
-    {appState.fileHandle && (
20
-      <div style={{ marginInlineStart: "0.25rem" }}>
21
-        {actionManager.renderAction("saveToActiveFile")}
22
-      </div>
23
-    )}
24 19
   </div>
25 20
 );

+ 5
- 1
src/components/LayerUI.tsx Прегледај датотеку

@@ -488,6 +488,9 @@ const LayerUI = ({
488 488
             setAppState={setAppState}
489 489
             showThemeBtn={showThemeBtn}
490 490
           />
491
+          {appState.fileHandle && (
492
+            <>{actionManager.renderAction("saveToActiveFile")}</>
493
+          )}
491 494
         </Stack.Col>
492 495
       </Island>
493 496
     </Section>
@@ -506,7 +509,8 @@ const LayerUI = ({
506 509
         style={{
507 510
           // we want to make sure this doesn't overflow so substracting 200
508 511
           // which is approximately height of zoom footer and top left menu items with some buffer
509
-          maxHeight: `${appState.height - 200}px`,
512
+          // if active file name is displayed, subtracting 248 to account for its height
513
+          maxHeight: `${appState.height - (appState.fileHandle ? 248 : 200)}px`,
510 514
         }}
511 515
       >
512 516
         <SelectedShapeActions

+ 5
- 0
src/components/icons.tsx Прегледај датотеку

@@ -477,6 +477,11 @@ export const shield = createIcon(
477 477
   { width: 24 },
478 478
 );
479 479
 
480
+export const file = createIcon(
481
+  "M369.9 97.9L286 14C277 5 264.8-.1 252.1-.1H48C21.5 0 0 21.5 0 48v416c0 26.5 21.5 48 48 48h288c26.5 0 48-21.5 48-48V131.9c0-12.7-5.1-25-14.1-34zM332.1 128H256V51.9l76.1 76.1zM48 464V48h160v104c0 13.3 10.7 24 24 24h104v288H48zm32-48h224V288l-23.5-23.5c-4.7-4.7-12.3-4.7-17 0L176 352l-39.5-39.5c-4.7-4.7-12.3-4.7-17 0L80 352v64zm48-240c-26.5 0-48 21.5-48 48s21.5 48 48 48 48-21.5 48-48-21.5-48-48-48z",
482
+  { width: 384, height: 512 },
483
+);
484
+
480 485
 export const GroupIcon = React.memo(({ theme }: { theme: "light" | "dark" }) =>
481 486
   createIcon(
482 487
     <>

Loading…
Откажи
Сачувај