Skip to content

Commit

Permalink
fix null notes root
Browse files Browse the repository at this point in the history
- check for empty / null value when selecting new chronicles root - it implies the user clicked cancel
  • Loading branch information
cloverich committed Dec 2, 2024
1 parent 07f7c72 commit 1962893
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
3 changes: 2 additions & 1 deletion src/preload/client/preferences.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,9 +78,10 @@ export class PreferencesClient {
return new Promise<{ error?: string; value?: string }>(
(resolve, reject) => {
ipcRenderer.once("directory-selected", (event, arg) => {
console.log("directory-selected", arg);
if (arg.error) {
reject(arg.error);
} else if (!arg.value) {
resolve({ value: undefined });
} else {
this.set("NOTES_DIR", arg.value);
resolve(arg.value);
Expand Down
10 changes: 5 additions & 5 deletions src/views/preferences/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,11 @@ const Preferences = observer(() => {
const client = useClient();
const navigate = useNavigate();

async function openDialogNotesDir() {
async function selectNotesRoot() {
store.loading = true;
try {
const result = await client.preferences.openDialogNotesDir();
if (!result) {
if (!result?.value) {
store.loading = false;
return;
}
Expand All @@ -48,7 +48,7 @@ const Preferences = observer(() => {
}
}

async function openDialogImportDir() {
async function importDirectory() {
store.loading = true;
try {
const result = await client.preferences.openDialogImportDir();
Expand Down Expand Up @@ -133,7 +133,7 @@ const Preferences = observer(() => {
<Button
isLoading={store.loading}
disabled={store.loading}
onClick={openDialogNotesDir}
onClick={selectNotesRoot}
>
Select new directory
</Button>
Expand All @@ -154,7 +154,7 @@ const Preferences = observer(() => {
<Button
isLoading={store.loading}
disabled={store.loading}
onClick={openDialogImportDir}
onClick={importDirectory}
>
Select directory
</Button>
Expand Down

0 comments on commit 1962893

Please sign in to comment.