Skip to content

Commit

Permalink
Try to Fix empty note at startup
Browse files Browse the repository at this point in the history
  • Loading branch information
srilakshmikanthanp committed Apr 26, 2024
1 parent c2b65ae commit f7ab028
Show file tree
Hide file tree
Showing 9 changed files with 22 additions and 142 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "quicknote",
"productName": "quicknote",
"version": "2.0.1",
"version": "2.0.2",
"description": "Take your note handy with quicknote!",
"main": ".webpack/main",
"scripts": {
Expand Down
11 changes: 2 additions & 9 deletions src/electron/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
// https://opensource.org/licenses/MIT


import { Menu, MenuItem, dialog, app, ipcMain, globalShortcut, screen } from 'electron';
import { Menu, MenuItem, dialog, app, ipcMain, globalShortcut } from 'electron';
import { configure } from 'electron-settings';

import open from 'open';
Expand Down Expand Up @@ -79,12 +79,6 @@ app.on('ready', async () => {
// file store to store the note
const fileStore = new FileStore(path.join(C.APPLICATION_HOME, ".quicknote"));

// Restart App
const restartApp = () => {
app.relaunch();
app.exit();
}

// ipc event for recv
ipcMain.handle(E.RECV_IN_MAIN_CHAN, async (e, arg) => {
return await fileStore.setNote(arg);
Expand All @@ -97,8 +91,7 @@ app.on('ready', async () => {

// ipc event for error
ipcMain.on(E.ONER_IN_MAIN_CHAN, async (e, arg) => {
dialog.showErrorBox(C.APPLICATION_NAME, arg);
restartApp();
dialog.showErrorBox(C.APPLICATION_NAME, arg); app.exit();
});

// create the tray window
Expand Down
1 change: 0 additions & 1 deletion src/electron/storage/FIleStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ export default class FileStore implements INoteStore {
file.openSync(this.file_path = name, 'a+');
}


/*********************************
* private instance variables *
********************************/
Expand Down
24 changes: 13 additions & 11 deletions src/render/App.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
// Copyright (c) 2023 Sri Lakshmi Kanthan P
//
//
// This software is released under the MIT License.
// https://opensource.org/licenses/MIT

import { useDispatch, useSelector } from "react-redux";
import { SetNote, selectNote } from "./redux/slices";
import React from "react";
import { NoteEditor } from "./components";
import * as C from "./constants";

Expand All @@ -13,17 +12,19 @@ import * as C from "./constants";
*/
export default function App() {
// Get the note from the store.
const noteContent = useSelector(selectNote);
const [initialContent, setInitialContent] = React.useState<string>(null);

// Get the dispatch function.
const dispatch = useDispatch();
// Get the note from the store.
React.useEffect(() => {
window.QuickNoteAPI.recvNote().then(setInitialContent).catch(onError);
}, []);

// Set the note in the store.
const setNote = (note: string) => {
dispatch(SetNote(note));
const saveNote = (note: string) => {
initialContent != null && window.QuickNoteAPI.sendNote(note).catch(onError);
};

// on error occured
// on error
const onError = (err: Error) => {
window.QuickNoteAPI.onError(err.message);
};
Expand All @@ -32,9 +33,10 @@ export default function App() {
return (
<NoteEditor
placeHolder={C.PLACEHOLDER_TEXT}
onUpdate={setNote}
noteContent={noteContent}
onUpdate={saveNote}
initialContent={initialContent}
onError={onError}
key={initialContent}
/>
);
}
11 changes: 5 additions & 6 deletions src/render/components/NoteEditor/NoteEditor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,11 @@ import { AutoFocusPlugin } from "@lexical/react/LexicalAutoFocusPlugin";
import { OnChangePlugin } from '@lexical/react/LexicalOnChangePlugin';
import styled from 'styled-components';
import { EditorState } from "lexical";
import * as constants from "../../constants";
import styles from "./NoteEditor.module.css"

// NoteEditor Props Interface Definition
interface INoteEditorProps {
noteContent: string;
initialContent: string;
placeHolder: string;
onUpdate?: (content: string) => void;
onError?: (content: Error) => void;
Expand Down Expand Up @@ -76,19 +75,19 @@ const editorTheme = {

// Note Editor
export default function NoteEditor({
noteContent,
initialContent,
onUpdate,
placeHolder,
onError,
}: INoteEditorProps) {
// change handler for note editor
const onChange = (state: EditorState) => {
onUpdate && onUpdate(JSON.stringify(state.toJSON()) || constants.INITIAL_EDITOR_STATE);
onUpdate && onUpdate(JSON.stringify(state.toJSON()));
}

// editor config
const editorConfig = noteContent ? {
editorState: noteContent,
const editorConfig = initialContent != null ? {
editorState: initialContent,
onError: onError,
theme: editorTheme,
namespace: "note-editor",
Expand Down
25 changes: 1 addition & 24 deletions src/render/main.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,31 +3,10 @@
// This software is released under the MIT License.
// https://opensource.org/licenses/MIT

import { SetNote } from "./redux/slices";
import ReactDOM from "react-dom/client";
import { Provider } from "react-redux";
import store from "./redux/store";
import "./styles/main.plain.css";
import App from "./App";

// Function to be called on note change
async function onNoteChange() {
try {
return await window.QuickNoteAPI.sendNote(store.getState().quicknote.note);
} catch (err) {
window.QuickNoteAPI.onError(err);
}
}

// set up the state of quick note
window.QuickNoteAPI.recvNote().then((note) => {
store.dispatch(SetNote(note));
}).then(() => {
store.subscribe(onNoteChange);
}).catch((err) => {
window.QuickNoteAPI.onError(err);
});

// root element
const rootElement = document.getElementById("root");

Expand All @@ -36,7 +15,5 @@ const reactRoot = ReactDOM.createRoot(rootElement);

// render the app
reactRoot.render(
<Provider store={store}>
<App />
</Provider>
<App />
);
54 changes: 0 additions & 54 deletions src/render/redux/slices/NoteSlice.ts

This file was deleted.

21 changes: 0 additions & 21 deletions src/render/redux/slices/index.ts

This file was deleted.

15 changes: 0 additions & 15 deletions src/render/redux/store/index.ts

This file was deleted.

0 comments on commit f7ab028

Please sign in to comment.