Skip to content

A fully open source & end-to-end encrypted note taking alternative to Evernote.

fix: Renaming file attachments in desktop app (fixes streetwriters/notesnook#543)

thecodrr5706c13648cb
diff --git a/apps/web/src/common/dialog-controller.tsx b/apps/web/src/common/dialog-controller.tsx
index b1d9deb3d..327ff7b75 100644
--- a/apps/web/src/common/dialog-controller.tsx
+++ b/apps/web/src/common/dialog-controller.tsx
@@ -151,6 +151,22 @@ export function confirm(props: ConfirmDialogProps) {
));
}
+export function showPromptDialog(props: {
+ title: string;
+ description?: string;
+ defaultValue?: string;
+}) {
+ return showDialog<"Prompt", string | null>("Prompt", (Dialog, perform) => (
+ <Dialog
+ {...props}
+ onClose={() => perform(null)}
+ onSave={(text) => {
+ perform(text);
+ }}
+ />
+ ));
+}
+
export function showError(title: string, message: string) {
return confirm({ title, message, yesText: "Okay" });
}
diff --git a/apps/web/src/components/attachment/index.js b/apps/web/src/components/attachment/index.js
index 00196c761..55ca457cc 100644
--- a/apps/web/src/components/attachment/index.js
+++ b/apps/web/src/components/attachment/index.js
@@ -10,6 +10,7 @@ import { Multiselect } from "../../common/multi-select";
import {
closeOpenedDialog,
showAttachmentsDialog,
+ showPromptDialog,
} from "../../common/dialog-controller";
import { hashNavigate } from "../../navigation";
@@ -173,7 +174,12 @@ const menuItems = [
title: () => "Rename",
icon: Icon.Rename,
onClick: async ({ attachment }) => {
- const newName = prompt("Rename file", attachment.metadata.filename);
+ const newName = await showPromptDialog({
+ title: "Rename attachment",
+ description: attachment.metadata.filename,
+ defaultValue: attachment.metadata.filename,
+ });
+ if (!newName) return;
await store.rename(attachment.metadata.hash, newName);
},
},
diff --git a/apps/web/src/components/dialogs/index.js b/apps/web/src/components/dialogs/index.js
index 2ec07b91d..c0f402be7 100644
--- a/apps/web/src/components/dialogs/index.js
+++ b/apps/web/src/components/dialogs/index.js
@@ -17,12 +17,14 @@ import IssueDialog from "./issuedialog";
import { MultifactorDialog, RecoveryCodesDialog } from "./multi-factor-dialog";
import OnboardingDialog from "./onboarding-dialog";
import AttachmentsDialog from "./attachmentsdialog";
+import { Prompt } from "./prompt";
const Dialogs = {
AddNotebookDialog,
TrackingDetailsDialog,
BuyDialog,
Confirm,
+ Prompt,
EmailVerificationDialog,
LoadingDialog,
MoveDialog,
diff --git a/apps/web/src/components/dialogs/prompt.tsx b/apps/web/src/components/dialogs/prompt.tsx
new file mode 100644
index 000000000..6dff03ec4
--- /dev/null
+++ b/apps/web/src/components/dialogs/prompt.tsx
@@ -0,0 +1,31 @@
+import { useRef } from "react";
+import { Perform } from "../../common/dialog-controller";
+import Field from "../field";
+import Dialog from "./dialog";
+
+export type PromptDialogProps = {
+ onClose: Perform;
+ title: string;
+ onSave: (text: string) => void;
+ description?: string;
+ defaultValue?: string;
+};
+
+export function Prompt(props: PromptDialogProps) {
+ const inputRef = useRef<HTMLInputElement>();
+ return (
+ <Dialog
+ isOpen={true}
+ title={props.title}
+ description={props.description}
+ onClose={props.onClose}
+ positiveButton={{
+ text: "Done",
+ onClick: () => props.onSave(inputRef.current?.value || ""),
+ }}
+ negativeButton={{ text: "Cancel", onClick: props.onClose }}
+ >
+ <Field inputRef={inputRef} defaultValue={props.defaultValue} autoFocus />
+ </Dialog>
+ );
+}