Skip to content

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

web: spellcheck should be enabled by default for new notes && hide properties toggle if disabled on desktop Signed-off-by: 01zulfi <[email protected]>

01zulfie3ed75461e88
diff --git a/apps/web/__e2e__/models/note-properties.model.ts b/apps/web/__e2e__/models/note-properties.model.ts
index b557068dd..ce9d1325a 100644
--- a/apps/web/__e2e__/models/note-properties.model.ts
+++ b/apps/web/__e2e__/models/note-properties.model.ts
@@ -41,6 +41,7 @@ abstract class BaseProperties {
private readonly favoriteToggle: ToggleModel;
private readonly lockToggle: ToggleModel;
private readonly archiveToggle: ToggleModel;
+ private readonly spellcheckToggle: ToggleModel;
constructor(
page: Page,
@@ -52,6 +53,7 @@ abstract class BaseProperties {
this.lockToggle = new ToggleModel(page, `${itemPrefix}-lock`);
this.favoriteToggle = new ToggleModel(page, `${itemPrefix}-favorite`);
this.archiveToggle = new ToggleModel(page, `${itemPrefix}-archive`);
+ this.spellcheckToggle = new ToggleModel(page, `${itemPrefix}-spellcheck`);
}
async isPinned() {
@@ -150,6 +152,13 @@ abstract class BaseProperties {
await this.close();
}
+ async isSpellcheckEnabled() {
+ await this.open();
+ const state = await this.spellcheckToggle.isToggled();
+ await this.close();
+ return state;
+ }
+
abstract isColored(color: string): Promise<boolean>;
abstract color(color: string): Promise<void>;
abstract open(): Promise<void>;
diff --git a/apps/web/__e2e__/notes.test.ts b/apps/web/__e2e__/notes.test.ts
index cefac7827..28e2df5a2 100644
--- a/apps/web/__e2e__/notes.test.ts
+++ b/apps/web/__e2e__/notes.test.ts
@@ -461,3 +461,17 @@ test("edit note creation date in properties panel", async ({ page }) => {
const dateCreated = await note?.properties.getDateCreated();
expect(date.format("DD-MM-YYYY hh:mm A")).toBe(dateCreated);
});
+
+test("spellcheck should be enabled by default for new notes", async ({
+ page
+}) => {
+ const app = new AppModel(page);
+ await app.goto();
+ const notes = await app.goToNotes();
+
+ const note = await notes.createNote(NOTE);
+
+ expect(note).toBeDefined();
+ expect(await note?.contextMenu.isSpellcheckEnabled()).toBe(true);
+ expect(await note?.properties.isSpellcheckEnabled()).toBe(true);
+});
diff --git a/apps/web/src/components/editor/index.tsx b/apps/web/src/components/editor/index.tsx
index 1c8dc2a64..2b2a78478 100644
--- a/apps/web/src/components/editor/index.tsx
+++ b/apps/web/src/components/editor/index.tsx
@@ -408,7 +408,8 @@ function EditorView({
options={{
readonly: session?.type === "readonly" || session?.type === "deleted",
focusMode: isFocusMode,
- spellcheck: "note" in session && session.note.spellcheck
+ spellcheck:
+ "note" in session ? session.note.spellcheck : session.type === "new"
}}
/>
</Flex>
diff --git a/apps/web/src/components/properties/index.tsx b/apps/web/src/components/properties/index.tsx
index ad286d396..65e46eca0 100644
--- a/apps/web/src/components/properties/index.tsx
+++ b/apps/web/src/components/properties/index.tsx
@@ -68,6 +68,7 @@ import {
import { VirtualizedTable } from "../virtualized-table";
import { TextSlice } from "@notesnook/core";
import { strings } from "@notesnook/intl";
+import { useSpellChecker } from "../../hooks/use-spell-checker";
const tools = [
{ key: "pin", property: "pinned", icon: Pin, label: strings.pin() },
@@ -100,7 +101,8 @@ const tools = [
key: "spellcheck",
icon: SpellCheck,
label: strings.spellCheck(),
- property: "spellcheck"
+ property: "spellcheck",
+ isHidden: () => IS_DESKTOP_APP && !useSpellChecker.getState().enabled
}
] as const;
@@ -128,6 +130,7 @@ type EditorPropertiesProps = {
};
function EditorProperties(props: EditorPropertiesProps) {
const toggleProperties = useEditorStore((store) => store.toggleProperties);
+ useSpellChecker((store) => store.enabled);
const isFocusMode = useAppStore((store) => store.isFocusMode);
const session = useEditorStore((store) =>
store.getSession(props.sessionId, [
@@ -183,19 +186,21 @@ function EditorProperties(props: EditorPropertiesProps) {
{session.type === "deleted" ||
session.type === "diff" ? null : (
<>
- {tools.map((tool) => (
- <Toggle
- {...tool}
- key={tool.key}
- isOn={
- tool.property === "locked"
- ? "locked" in session && !!session.locked
- : !!session.note[tool.property]
- }
- onToggle={() => changeToggleState(tool.key, session)}
- testId={`properties-${tool.key}`}
- />
- ))}
+ {tools.map((tool) =>
+ "isHidden" in tool && tool.isHidden() ? null : (
+ <Toggle
+ {...tool}
+ key={tool.key}
+ isOn={
+ tool.property === "locked"
+ ? "locked" in session && !!session.locked
+ : !!session.note[tool.property]
+ }
+ onToggle={() => changeToggleState(tool.key, session)}
+ testId={`properties-${tool.key}`}
+ />
+ )
+ )}
</>
)}
diff --git a/packages/core/src/database/migrations.ts b/packages/core/src/database/migrations.ts
index cfd44470c..4cbc4f81f 100644
--- a/packages/core/src/database/migrations.ts
+++ b/packages/core/src/database/migrations.ts
@@ -437,7 +437,7 @@ export class NNMigrationProvider implements MigrationProvider {
async up(db) {
await db.schema
.alterTable("notes")
- .addColumn("spellcheck", "boolean")
+ .addColumn("spellcheck", "boolean", (c) => c.defaultTo(true))
.execute();
await db
.updateTable("notes")