Skip to content

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

feat: use max item height as estimated item height

thecodrr99dd53e07b42
diff --git a/apps/web/src/common/height-calculator.js b/apps/web/src/common/height-calculator.js
index 4304f3aa0..b8da83512 100644
--- a/apps/web/src/common/height-calculator.js
+++ b/apps/web/src/common/height-calculator.js
@@ -1,6 +1,12 @@
const SINGLE_LINE_HEIGHT = 1.4;
const DEFAULT_FONT_SIZE = 16;
+const MAX_HEIGHTS = {
+ note: SINGLE_LINE_HEIGHT * 6 * DEFAULT_FONT_SIZE,
+ notebook: SINGLE_LINE_HEIGHT * 7 * DEFAULT_FONT_SIZE,
+ generic: SINGLE_LINE_HEIGHT * 4 * DEFAULT_FONT_SIZE,
+};
+
function getNoteHeight(item) {
const { title, headline } = item;
let height = SINGLE_LINE_HEIGHT * 3;
@@ -45,4 +51,4 @@ function getItemHeight(item) {
return height * DEFAULT_FONT_SIZE;
}
-export { getNoteHeight, getNotebookHeight, getItemHeight };
+export { getNoteHeight, getNotebookHeight, getItemHeight, MAX_HEIGHTS };
diff --git a/apps/web/src/components/global-menu-wrapper/index.js b/apps/web/src/components/global-menu-wrapper/index.js
index 46188fcbb..02fc8efc3 100644
--- a/apps/web/src/components/global-menu-wrapper/index.js
+++ b/apps/web/src/components/global-menu-wrapper/index.js
@@ -1,4 +1,4 @@
-import React, { useEffect, useRef } from "react";
+import React, { useEffect } from "react";
import Menu from "../menu";
import useContextMenu from "../../utils/useContextMenu";
import Animated from "../animated";
diff --git a/apps/web/src/views/home.js b/apps/web/src/views/home.js
index ca46cd883..f774263df 100644
--- a/apps/web/src/views/home.js
+++ b/apps/web/src/views/home.js
@@ -4,7 +4,7 @@ import { useStore, store } from "../stores/note-store";
import { useStore as useEditorStore } from "../stores/editor-store";
import ListContainer from "../components/list-container";
import NotesPlaceholder from "../components/placeholders/notesplacholder";
-import { getNoteHeight } from "../common/height-calculator";
+import { getNoteHeight, MAX_HEIGHTS } from "../common/height-calculator";
function Home() {
useEffect(() => store.refresh(), []);
@@ -15,7 +15,7 @@ function Home() {
<ListContainer
type="notes"
items={notes}
- estimatedItemHeight={100}
+ estimatedItemHeight={MAX_HEIGHTS.note}
itemHeight={getNoteHeight}
item={(index, item) => <Note index={index} pinnable item={item} />}
placeholder={NotesPlaceholder}
diff --git a/apps/web/src/views/notebooks.js b/apps/web/src/views/notebooks.js
index a5c3f1d9a..4a7c5d57e 100644
--- a/apps/web/src/views/notebooks.js
+++ b/apps/web/src/views/notebooks.js
@@ -9,7 +9,7 @@ import Notes from "./notes.js";
import { useRoutes, navigate } from "hookrouter";
import RouteContainer from "../components/route-container";
import { db } from "../common";
-import { getNotebookHeight } from "../common/height-calculator";
+import { getNotebookHeight, MAX_HEIGHTS } from "../common/height-calculator";
const routes = {
"/": () => (
@@ -63,7 +63,7 @@ function Notebooks() {
<ListContainer
type="notebooks"
items={notebooks}
- estimatedItemHeight={120}
+ estimatedItemHeight={MAX_HEIGHTS.notebook}
itemHeight={getNotebookHeight}
item={(index, item) => (
<Notebook
diff --git a/apps/web/src/views/notes.js b/apps/web/src/views/notes.js
index 6405862d8..ab0bad6ea 100644
--- a/apps/web/src/views/notes.js
+++ b/apps/web/src/views/notes.js
@@ -4,7 +4,7 @@ import ListContainer from "../components/list-container";
import { useStore } from "../stores/editor-store";
import { useStore as useNotesStore } from "../stores/note-store";
import NotesPlaceholder from "../components/placeholders/notesplacholder";
-import { getNoteHeight } from "../common/height-calculator";
+import { getNoteHeight, MAX_HEIGHTS } from "../common/height-calculator";
function Notes(props) {
const newSession = useStore((store) => store.newSession);
@@ -21,7 +21,7 @@ function Notes(props) {
return (
<ListContainer
type="notes"
- estimatedItemHeight={100}
+ estimatedItemHeight={MAX_HEIGHTS.note}
itemHeight={getNoteHeight}
items={context.notes}
placeholder={props.placeholder || NotesPlaceholder}
diff --git a/apps/web/src/views/tags.js b/apps/web/src/views/tags.js
index ce3018619..18afb1f02 100644
--- a/apps/web/src/views/tags.js
+++ b/apps/web/src/views/tags.js
@@ -7,7 +7,7 @@ import TagsPlaceholder from "../components/placeholders/tags-placeholder";
import Notes from "./notes";
import { useRoutes, navigate } from "hookrouter";
import RouteContainer from "../components/route-container";
-import { getItemHeight } from "../common/height-calculator";
+import { getItemHeight, MAX_HEIGHTS } from "../common/height-calculator";
function TagNode({ title }) {
return (
@@ -48,7 +48,7 @@ function Tags() {
type="tags"
items={tags}
itemHeight={getItemHeight}
- estimatedItemHeight={80}
+ estimatedItemHeight={MAX_HEIGHTS.generic}
item={(index, item) => {
const { title, noteIds } = item;
return (
diff --git a/apps/web/src/views/topics.js b/apps/web/src/views/topics.js
index 951d0c7e8..bbad03b60 100644
--- a/apps/web/src/views/topics.js
+++ b/apps/web/src/views/topics.js
@@ -5,7 +5,7 @@ import ListContainer from "../components/list-container";
import { useStore as useNbStore } from "../stores/notebook-store";
import { showTopicDialog } from "../components/dialogs/topicdialog";
import { navigate } from "hookrouter";
-import { getItemHeight } from "../common/height-calculator";
+import { getItemHeight, MAX_HEIGHTS } from "../common/height-calculator";
function Topics(props) {
const { notebookId } = props;
@@ -32,7 +32,7 @@ function Topics(props) {
type="topics"
items={topics}
itemHeight={getItemHeight}
- estimatedItemHeight={80}
+ estimatedItemHeight={MAX_HEIGHTS.generic}
item={(index, item) => (
<Topic
index={index}
diff --git a/apps/web/src/views/trash.js b/apps/web/src/views/trash.js
index 4a6de44ca..738ae2632 100644
--- a/apps/web/src/views/trash.js
+++ b/apps/web/src/views/trash.js
@@ -10,7 +10,11 @@ import { toTitleCase } from "../utils/string";
import TrashPlaceholder from "../components/placeholders/trash-placeholder";
import { showToast } from "../utils/toast";
import { showPermanentDeleteToast } from "../common/toasts";
-import { getNotebookHeight, getNoteHeight } from "../common/height-calculator";
+import {
+ getNotebookHeight,
+ getNoteHeight,
+ MAX_HEIGHTS,
+} from "../common/height-calculator";
function menuItems(item, index) {
return [
@@ -50,7 +54,7 @@ function Trash() {
<ListContainer
type="trash"
placeholder={TrashPlaceholder}
- estimatedItemHeight={120}
+ estimatedItemHeight={Math.max(MAX_HEIGHTS.note, MAX_HEIGHTS.notebook)}
itemHeight={(item) => {
if (item.type === "note") return getNoteHeight(item);
else if (item.type === "notebook") return getNotebookHeight(item);