A fully open source & end-to-end encrypted note taking alternative to Evernote.
TypeScript asp-net-coredotnet-coreelectronfosshacktoberfestnote-managmentnote-takingnote-taking-appnotebooknotesnotes-appopen-sourceopensourceprivacyproductivityreactreact-nativereactjsself-hosted
web: migrate list-container to typescript
Abdullah Attada5824845673
diff --git a/apps/web/package-lock.json b/apps/web/package-lock.jsonindex a85a04b52..690d0a73f 100644--- a/apps/web/package-lock.json+++ b/apps/web/package-lock.json@@ -16,6 +16,7 @@"@mdi/js": "^6.5.95","@mdi/react": "^1.4.0","@notesnook/desktop": "file:desktop",+ "@tanstack/react-virtual": "^3.0.0-beta.18","@theme-ui/components": "^0.14.7","@theme-ui/core": "^0.14.7","allotment": "^1.12.1",@@ -38,8 +39,6 @@"print-js": "^1.6.0","qclone": "^1.0.4","rc-scrollbars": "^1.1.3",- "react": "^17.0.1",- "react-dom": "^17.0.1","react-dropzone": "^11.4.2","react-hot-toast": "^2.2.0","react-loading-skeleton": "^3.1.0",@@ -48,7 +47,7 @@"react-scripts": "^5.0.1","react-scroll-sync": "^0.9.0","react-toggle": "^4.1.2",- "react-virtuoso": "^2.4.0",+ "react-virtuoso": "2.4.0","showdown": "github:thecodrr/showdown","timeago.js": "^4.0.2","web-streams-polyfill": "^3.1.1",@@ -75,6 +74,8 @@"lorem-ipsum": "^2.0.4","patch-package": "^6.4.7","progress-bar-webpack-plugin": "^2.1.0",+ "react": "17.0.2",+ "react-dom": "17.0.2","source-map-explorer": "^2.5.2","typescript": "^4.8.2","webpack-bundle-analyzer": "^4.5.0",@@ -3895,6 +3896,36 @@"node": ">=6"}},+ "node_modules/@tanstack/react-virtual": {+ "version": "3.0.0-beta.18",+ "resolved": "https://registry.npmjs.org/@tanstack/react-virtual/-/react-virtual-3.0.0-beta.18.tgz",+ "integrity": "sha512-mnyCZT6htcRNw1jVb+WyfMUMbd1UmXX/JWPuMf6Bmj92DB/V7Ogk5n5rby5Y5aste7c7mlsBeMF8HtpwERRvEQ==",+ "dependencies": {+ "@tanstack/virtual-core": "3.0.0-beta.18"+ },+ "engines": {+ "node": ">=12"+ },+ "funding": {+ "type": "github",+ "url": "https://github.com/sponsors/tannerlinsley"+ },+ "peerDependencies": {+ "react": "^16.8.0 || ^17.0.0 || ^18.0.0"+ }+ },+ "node_modules/@tanstack/virtual-core": {+ "version": "3.0.0-beta.18",+ "resolved": "https://registry.npmjs.org/@tanstack/virtual-core/-/virtual-core-3.0.0-beta.18.tgz",+ "integrity": "sha512-tcXutY05NpN9lp3+AXI9Sn85RxSPV0EJC0XMim9oeQj/E7bjXoL0qZ4Er4wwnvIbv/hZjC91EmbIQGjgdr6nZg==",+ "engines": {+ "node": ">=12"+ },+ "funding": {+ "type": "github",+ "url": "https://github.com/sponsors/tannerlinsley"+ }+ },"node_modules/@theme-ui/components": {"version": "0.14.7","resolved": "https://registry.npmjs.org/@theme-ui/components/-/components-0.14.7.tgz",@@ -14334,7 +14365,9 @@},"node_modules/react": {"version": "17.0.2",- "license": "MIT",+ "resolved": "https://registry.npmjs.org/react/-/react-17.0.2.tgz",+ "integrity": "sha512-gnhPt75i/dq/z3/6q/0asP78D0u592D5L1pd7M8P+dck6Fu/jJeL6iVVK23fptSUZj8Vjf++7wXA8UNclGQcbA==",+ "dev": true,"dependencies": {"loose-envify": "^1.1.0","object-assign": "^4.1.1"@@ -14440,7 +14473,9 @@},"node_modules/react-dom": {"version": "17.0.2",- "license": "MIT",+ "resolved": "https://registry.npmjs.org/react-dom/-/react-dom-17.0.2.tgz",+ "integrity": "sha512-s4h96KtLDUQlsENhMn1ar8t2bEa+q/YAtj8pPPdIjPDGBDIVNsrD9aXNWqspUe6AzKCIG0C1HZZLqLV7qpOBGA==",+ "dev": true,"dependencies": {"loose-envify": "^1.1.0","object-assign": "^4.1.1",@@ -14642,8 +14677,9 @@}},"node_modules/react-virtuoso": {- "version": "2.17.2",- "license": "MIT",+ "version": "2.4.0",+ "resolved": "https://registry.npmjs.org/react-virtuoso/-/react-virtuoso-2.4.0.tgz",+ "integrity": "sha512-hjo+ERHcZU5XOnpXMVEhm6mSiPi6oz8xbwKjWTfozbUGPaVAT+9wzU202Y50NOHVXekBVCGL02W2++PKi8z2Tw==","dependencies": {"@virtuoso.dev/react-urx": "^0.2.12","@virtuoso.dev/urx": "^0.2.12"@@ -14652,8 +14688,7 @@"node": ">=10"},"peerDependencies": {- "react": ">=16 || >=17 || >= 18",- "react-dom": ">=16 || >=17 || >= 18"+ "react": ">=16"}},"node_modules/read-cache": {@@ -15270,7 +15305,9 @@},"node_modules/scheduler": {"version": "0.20.2",- "license": "MIT",+ "resolved": "https://registry.npmjs.org/scheduler/-/scheduler-0.20.2.tgz",+ "integrity": "sha512-2eWfGgAqqWFGqtdMmcL5zCMK1U8KlXv8SQFGglL3CEtd0aDVDWgeF/YoCmvln55m5zSk3J/20hTaSBeSObsQDQ==",+ "dev": true,"dependencies": {"loose-envify": "^1.1.0","object-assign": "^4.1.1"@@ -20179,6 +20216,19 @@"defer-to-connect": "^1.0.1"}},+ "@tanstack/react-virtual": {+ "version": "3.0.0-beta.18",+ "resolved": "https://registry.npmjs.org/@tanstack/react-virtual/-/react-virtual-3.0.0-beta.18.tgz",+ "integrity": "sha512-mnyCZT6htcRNw1jVb+WyfMUMbd1UmXX/JWPuMf6Bmj92DB/V7Ogk5n5rby5Y5aste7c7mlsBeMF8HtpwERRvEQ==",+ "requires": {+ "@tanstack/virtual-core": "3.0.0-beta.18"+ }+ },+ "@tanstack/virtual-core": {+ "version": "3.0.0-beta.18",+ "resolved": "https://registry.npmjs.org/@tanstack/virtual-core/-/virtual-core-3.0.0-beta.18.tgz",+ "integrity": "sha512-tcXutY05NpN9lp3+AXI9Sn85RxSPV0EJC0XMim9oeQj/E7bjXoL0qZ4Er4wwnvIbv/hZjC91EmbIQGjgdr6nZg=="+ },"@theme-ui/components": {"version": "0.14.7","resolved": "https://registry.npmjs.org/@theme-ui/components/-/components-0.14.7.tgz",@@ -20350,7 +20400,7 @@"version": "2.2.5","dev": true,"requires": {- "@types/react": "*",+ "@types/react": "17.0.2","csstype": "^3.0.2"}},@@ -26538,6 +26588,9 @@},"react": {"version": "17.0.2",+ "resolved": "https://registry.npmjs.org/react/-/react-17.0.2.tgz",+ "integrity": "sha512-gnhPt75i/dq/z3/6q/0asP78D0u592D5L1pd7M8P+dck6Fu/jJeL6iVVK23fptSUZj8Vjf++7wXA8UNclGQcbA==",+ "dev": true,"requires": {"loose-envify": "^1.1.0","object-assign": "^4.1.1"@@ -26612,6 +26665,9 @@},"react-dom": {"version": "17.0.2",+ "resolved": "https://registry.npmjs.org/react-dom/-/react-dom-17.0.2.tgz",+ "integrity": "sha512-s4h96KtLDUQlsENhMn1ar8t2bEa+q/YAtj8pPPdIjPDGBDIVNsrD9aXNWqspUe6AzKCIG0C1HZZLqLV7qpOBGA==",+ "dev": true,"requires": {"loose-envify": "^1.1.0","object-assign": "^4.1.1",@@ -26737,7 +26793,9 @@}},"react-virtuoso": {- "version": "2.17.2",+ "version": "2.4.0",+ "resolved": "https://registry.npmjs.org/react-virtuoso/-/react-virtuoso-2.4.0.tgz",+ "integrity": "sha512-hjo+ERHcZU5XOnpXMVEhm6mSiPi6oz8xbwKjWTfozbUGPaVAT+9wzU202Y50NOHVXekBVCGL02W2++PKi8z2Tw==","requires": {"@virtuoso.dev/react-urx": "^0.2.12","@virtuoso.dev/urx": "^0.2.12"@@ -27118,6 +27176,9 @@},"scheduler": {"version": "0.20.2",+ "resolved": "https://registry.npmjs.org/scheduler/-/scheduler-0.20.2.tgz",+ "integrity": "sha512-2eWfGgAqqWFGqtdMmcL5zCMK1U8KlXv8SQFGglL3CEtd0aDVDWgeF/YoCmvln55m5zSk3J/20hTaSBeSObsQDQ==",+ "dev": true,"requires": {"loose-envify": "^1.1.0","object-assign": "^4.1.1"diff --git a/apps/web/package.json b/apps/web/package.jsonindex 34e9fae02..f314000bd 100644--- a/apps/web/package.json+++ b/apps/web/package.json@@ -22,6 +22,7 @@"@notesnook/logger": "*","@notesnook/streamable-fs": "*","@notesnook/theme": "*",+ "@tanstack/react-virtual": "^3.0.0-beta.18","@theme-ui/components": "^0.14.7","@theme-ui/core": "^0.14.7","allotment": "^1.12.1",@@ -44,8 +45,6 @@"print-js": "^1.6.0","qclone": "^1.0.4","rc-scrollbars": "^1.1.3",- "react": "^17.0.1",- "react-dom": "^17.0.1","react-dropzone": "^11.4.2","react-hot-toast": "^2.2.0","react-loading-skeleton": "^3.1.0",@@ -54,7 +53,7 @@"react-scripts": "^5.0.1","react-scroll-sync": "^0.9.0","react-toggle": "^4.1.2",- "react-virtuoso": "^2.4.0",+ "react-virtuoso": "2.4.0","showdown": "github:thecodrr/showdown","timeago.js": "^4.0.2","web-streams-polyfill": "^3.1.1",@@ -85,7 +84,15 @@"typescript": "^4.8.2","webpack-bundle-analyzer": "^4.5.0","worker-loader": "^3.0.8",- "zx": "^2.0.0"+ "zx": "^2.0.0",+ "react": "17.0.2",+ "react-dom": "17.0.2"+ },+ "overrides": {+ "react@>17": "17.0.2",+ "react-dom@>17": "17.0.2",+ "@types/react@>17": "17.0.2",+ "@types/react-dom@>17": "17.0.2"},"scripts": {"start": "env-cmd -e all,dev,web react-scripts start",diff --git a/apps/web/src/common/db.js b/apps/web/src/common/db.jsindex 03ca0b870..0b25a7f63 100644--- a/apps/web/src/common/db.js+++ b/apps/web/src/common/db.js@@ -22,7 +22,7 @@ import { NNStorage } from "../interfaces/storage";import { logger } from "../utils/logger";/**- * @type {import("@notesnook/core/api").default}+ * @type {import("@notesnook/core/api/index").default}*/var db;async function initializeDatabase(persistence) {diff --git a/apps/web/src/common/list-profiles.js b/apps/web/src/common/list-profiles.jsdeleted file mode 100644index 0a042c059..000000000--- a/apps/web/src/common/list-profiles.js+++ /dev/null@@ -1,161 +0,0 @@-/*-This file is part of the Notesnook project (https://notesnook.com/)--Copyright (C) 2022 Streetwriters (Private) Limited--This program is free software: you can redistribute it and/or modify-it under the terms of the GNU General Public License as published by-the Free Software Foundation, either version 3 of the License, or-(at your option) any later version.--This program is distributed in the hope that it will be useful,-but WITHOUT ANY WARRANTY; without even the implied warranty of-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the-GNU General Public License for more details.--You should have received a copy of the GNU General Public License-along with this program. If not, see <http://www.gnu.org/licenses/>.-*/--import { navigate } from "../navigation/";-import Note from "../components/note";-import Notebook from "../components/notebook";-import Tag from "../components/tag";-import Topic from "../components/topic";-import TrashItem from "../components/trash-item";-import {- getItemHeight,- getNotebookHeight,- getNoteHeight,- MAX_HEIGHTS-} from "./height-calculator";-import { db } from "./db";-import { getTotalNotes } from ".";-import Attachment from "../components/attachment";--function createProfile(item, itemHeight, estimatedItemHeight) {- return { item, itemHeight, estimatedItemHeight };-}--const NotesProfile = createProfile(- (index, item, type, context) => (- <Note- index={index}- pinnable={!context}- item={item}- tags={getTags(item)}- notebook={getNotebook(item.notebooks, context?.type)}- date={getDate(item, type)}- context={context}- />- ),- getNoteHeight,- MAX_HEIGHTS.note-);--const NotebooksProfile = createProfile(- (index, item, type) => (- <Notebook- index={index}- item={item}- totalNotes={getTotalNotes(item)}- date={getDate(item, type)}- />- ),- getNotebookHeight,- MAX_HEIGHTS.notebook-);--const TagsProfile = createProfile(- (index, item) => <Tag item={item} index={index} />,- getItemHeight,- MAX_HEIGHTS.generic-);--const TopicsProfile = createProfile(- (index, item, _type, context) => (- <Topic- index={index}- item={item}- onClick={() => navigate(`/notebooks/${context.notebookId}/${item.id}`)}- />- ),- getItemHeight,- MAX_HEIGHTS.generic-);--const TrashProfile = createProfile(- (index, item, type) => (- <TrashItem index={index} item={item} date={getDate(item, type)} />- ),- (item) => {- if (item.itemType === "note") return getNoteHeight(item);- else if (item.itemType === "notebook") return getNotebookHeight(item);- },- Math.max(MAX_HEIGHTS.note, MAX_HEIGHTS.notebook)-);--const AttachmentProfile = createProfile(- (index, item) => <Attachment index={index} item={item} />,- (item) => getNoteHeight(item),- Math.max(MAX_HEIGHTS.note, MAX_HEIGHTS.notebook)-);--const Profiles = {- home: NotesProfile,- notebooks: NotebooksProfile,- notes: NotesProfile,- tags: TagsProfile,- topics: TopicsProfile,- trash: TrashProfile,- attachments: AttachmentProfile-};--export default Profiles;--function getTags(item) {- let tags = item.tags;- if (tags)- tags = tags.slice(0, 3).reduce((prev, curr) => {- const tag = db.tags.tag(curr);- if (tag) prev.push(tag);- return prev;- }, []);- return tags || [];-}--function getNotebook(notebooks, contextType) {- if (contextType === "topic" || !notebooks?.length) return;-- const noteNotebook = notebooks[0];- const topicId = noteNotebook.topics[0];-- const notebook = db.notebooks.notebook(noteNotebook.id)?.data;- if (!notebook) return;-- const topic = notebook.topics.find((t) => t.id === topicId);- if (!topic) return;-- return {- id: notebook.id,- title: notebook.title,- dateEdited: notebook.dateEdited,- topic: { id: topicId, title: topic.title }- };-}--function getDate(item, groupType) {- const sortBy = db.settings.getGroupOptions(groupType).sortBy;- switch (sortBy) {- case "dateEdited":- return item.dateEdited;- case "dateCreated":- return item.dateCreated;- case "dateModified":- return item.dateModified;- case "dateDeleted":- return item.dateDeleted;- default:- return item.dateCreated;- }-}diff --git a/apps/web/src/components/list-container/index.js b/apps/web/src/components/list-container/index.tsxsimilarity index 80%rename from apps/web/src/components/list-container/index.jsrename to apps/web/src/components/list-container/index.tsxindex f0a7f2ac1..c6d31f137 100644--- a/apps/web/src/components/list-container/index.js+++ b/apps/web/src/components/list-container/index.tsx@@ -20,30 +20,50 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.import { useEffect, useMemo, useRef, useState } from "react";import { Flex, Button } from "@theme-ui/components";import * as Icon from "../icons";-import { Virtuoso } from "react-virtuoso";+import { Virtuoso, VirtuosoHandle } from "react-virtuoso";import {useStore as useSelectionStore,store as selectionStore} from "../../stores/selection-store";import GroupHeader from "../group-header";-import ListProfiles from "../../common/list-profiles";+import {+ Context,+ DEFAULT_ITEM_HEIGHT,+ Item,+ ListProfiles+} from "./list-profiles";import { CustomScrollbarsVirtualList } from "../scroll-container";import ReminderBar from "../reminder-bar";import Announcements from "../announcements";import useAnnouncements from "../../hooks/use-announcements";import { ListLoader } from "../loaders/list-loader";-function ListContainer(props) {- const { type, groupType, items, context, refresh, header } = props;+type ListContainerProps = {+ type: keyof typeof ListProfiles;+ items: Item[];+ groupType: string;+ context: Context;+ refresh: () => void;+ header: JSX.Element;+ placeholder: () => JSX.Element;+ isLoading: boolean;+ button?: {+ onClick: () => void;+ };+};++function ListContainer(props: ListContainerProps) {+ const { type, groupType, items, context, refresh, header, button } = props;const [focusedGroupIndex, setFocusedGroupIndex] = useState(-1);const [announcements, removeAnnouncement] = useAnnouncements();- const profile = useMemo(() => ListProfiles[type], [type]);const setSelectedItems = useSelectionStore((store) => store.setSelectedItems);- const listRef = useRef();++ const listRef = useRef<VirtuosoHandle>(null);const focusedItemIndex = useRef(-1);- const listContainerRef = useRef();+ const listContainerRef = useRef(null);+const groups = useMemo(() => props.items.filter((v) => v.type === "header"),[props.items]@@ -55,6 +75,8 @@ function ListContainer(props) {};}, []);+ const Component = ListProfiles[type];+return (<Flex variant="columnFill">{!props.items.length && props.placeholder ? (@@ -77,7 +99,7 @@ function ListContainer(props) {variant="columnFill"data-test-id="note-list"onFocus={(e) => {- if (e.target.parentElement.dataset.index) {+ if (e.target.parentElement?.dataset.index) {focusedItemIndex.current = parseInt(e.target.parentElement.dataset.index);@@ -88,11 +110,15 @@ function ListContainer(props) {ref={listRef}data={items}computeItemKey={(index) => items[index].id || items[index].title}- defaultItemHeight={profile.estimatedItemHeight}+ defaultItemHeight={DEFAULT_ITEM_HEIGHT}totalCount={items.length}onMouseDown={(e) => {- const listItem = e.target.closest(`[data-item-index]`);- if (e.shiftKey && listItem) {+ const target = e.target as HTMLElement;++ const listItem = target.closest(+ `[data-item-index]`+ ) as HTMLElement;+ if (e.shiftKey && listItem && listItem.dataset.index) {e.preventDefault();const endIndex = parseInt(listItem.dataset.index);if (isNaN(endIndex)) return;@@ -100,7 +126,7 @@ function ListContainer(props) {...selectionStore.get().selectedItems,...items.slice(focusedItemIndex.current + 1, endIndex + 1)]);- listItem.firstElementChild.focus();+ (listItem.firstElementChild as HTMLElement)?.focus();}}}onBlur={() => setFocusedGroupIndex(-1)}@@ -122,12 +148,13 @@ function ListContainer(props) {// const isShiftKey = e.shiftKey;const isUp = e.code === "ArrowUp";const isDown = e.code === "ArrowDown";- const isHeader = (i) => items && items[i]?.type === "header";- const moveDown = (i) =>+ const isHeader = (i: number) =>+ items && items[i]?.type === "header";+ const moveDown = (i: number) =>i < items.length - 1 ? ++i : items.length - 1;- const moveUp = (i) => (i > 0 ? --i : 0);+ const moveUp = (i: number) => (i > 0 ? --i : 0);- let i = focusedItemIndex.current;+ const i = focusedItemIndex.current;let nextIndex = i;if (nextIndex <= -1 && (isUp || isDown)) {@@ -145,14 +172,14 @@ function ListContainer(props) {if (isUp || isDown) {e.preventDefault();- listRef.current.scrollIntoView({+ listRef.current?.scrollIntoView({index: nextIndex,behavior: "auto",done: () => {const query = `[data-item-index="${nextIndex}"]`;const listItem = document.querySelector(query);if (!listItem) return;- listItem.firstElementChild.focus();+ (listItem.firstElementChild as HTMLElement)?.focus();}});selectionStore.toggleSelectionMode(false);@@ -181,9 +208,14 @@ function ListContainer(props) {// }}}}- // overscan={10}+ overscan={5}components={{Scroller: CustomScrollbarsVirtualList,+ Item: (props) => (+ <div {...props} style={{ paddingBottom: 1 }}>+ {props.children}+ </div>+ ),Header: () =>header ? (header@@ -225,12 +257,12 @@ function ListContainer(props) {]);}}groups={groups}- onJump={(title) => {+ onJump={(title: string) => {const index = props.items.findIndex((v) => v.title === title);if (index < 0) return;- listRef.current.scrollToIndex({+ listRef.current?.scrollToIndex({index,align: "center",behavior: "auto"@@ -240,18 +272,25 @@ function ListContainer(props) {/>);default:- return profile.item(index, item, groupType, context);+ return (+ <Component+ item={item}+ context={context}+ index={index}+ type={type}+ />+ );}}}/></Flex></>)}- {props.button && (+ {button && (<Buttonvariant="primary"data-test-id={`${props.type}-action-button`}- onClick={props.button.onClick}+ onClick={button.onClick}sx={{position: "absolute",bottom: 0,diff --git a/apps/web/src/components/list-container/list-profiles.tsx b/apps/web/src/components/list-container/list-profiles.tsxnew file mode 100644index 000000000..3c546f67f--- /dev/null+++ b/apps/web/src/components/list-container/list-profiles.tsx@@ -0,0 +1,155 @@+/*+This file is part of the Notesnook project (https://notesnook.com/)++Copyright (C) 2022 Streetwriters (Private) Limited++This program is free software: you can redistribute it and/or modify+it under the terms of the GNU General Public License as published by+the Free Software Foundation, either version 3 of the License, or+(at your option) any later version.++This program is distributed in the hope that it will be useful,+but WITHOUT ANY WARRANTY; without even the implied warranty of+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the+GNU General Public License for more details.++You should have received a copy of the GNU General Public License+along with this program. If not, see <http://www.gnu.org/licenses/>.+*/++import { navigate } from "../../navigation";+import Note from "../note";+import Notebook from "../notebook";+import Tag from "../tag";+import Topic from "../topic";+import TrashItem from "../trash-item";+import Attachment from "../attachment";+import { db } from "../../common/db";+import { getTotalNotes } from "../../common";++const SINGLE_LINE_HEIGHT = 1.4;+const DEFAULT_LINE_HEIGHT =+ (document.getElementById("p")?.clientHeight || 16) - 1;+export const DEFAULT_ITEM_HEIGHT = SINGLE_LINE_HEIGHT * 2 * DEFAULT_LINE_HEIGHT;+// const MAX_HEIGHTS = {+// note: SINGLE_LINE_HEIGHT * 7 * DEFAULT_LINE_HEIGHT,+// notebook: SINGLE_LINE_HEIGHT * 7 * DEFAULT_LINE_HEIGHT,+// generic: SINGLE_LINE_HEIGHT * 4 * DEFAULT_LINE_HEIGHT+// };++export type Item = { id: string; type: string; title: string } & Record<+ string,+ unknown+>;++export type Context = { type: string } & Record<string, unknown>;+type ItemWrapperProps = {+ index: number;+ item: Item;+ type: keyof typeof ListProfiles;+ context: Context;+};++type ItemWrapper = (props: ItemWrapperProps) => JSX.Element;++const NotesProfile: ItemWrapper = ({ index, item, type, context }) => (+ <Note+ index={index}+ pinnable={!context}+ item={item}+ tags={getTags(item)}+ notebook={getNotebook(item.notebooks as Item[], context?.type)}+ date={getDate(item, type)}+ context={context}+ />+);++const NotebooksProfile: ItemWrapper = ({ index, item, type }) => (+ <Notebook+ index={index}+ item={item}+ totalNotes={getTotalNotes(item)}+ date={getDate(item, type)}+ />+);++const TagsProfile: ItemWrapper = ({ index, item }) => (+ <Tag item={item} index={index} />+);++const TopicsProfile: ItemWrapper = ({ index, item, context }) => (+ <Topic+ index={index}+ item={item}+ onClick={() => navigate(`/notebooks/${context.notebookId}/${item.id}`)}+ />+);++const TrashProfile: ItemWrapper = ({ index, item, type }) => (+ <TrashItem index={index} item={item} date={getDate(item, type)} />+);++const AttachmentProfile: ItemWrapper = ({ index, item }) => (+ <Attachment index={index} item={item} isCompact={false} />+);++export const ListProfiles = {+ home: NotesProfile,+ notebooks: NotebooksProfile,+ notes: NotesProfile,+ tags: TagsProfile,+ topics: TopicsProfile,+ trash: TrashProfile,+ attachments: AttachmentProfile+} as const;++function getTags(item: Item) {+ let tags = item.tags as Item[];+ if (tags)+ tags = tags.slice(0, 3).reduce((prev, curr) => {+ const tag = db.tags?.tag(curr);+ if (tag) prev.push(tag);+ return prev;+ }, [] as Item[]);+ return tags || [];+}++function getNotebook(notebooks: Item[], contextType: string) {+ if (contextType === "topic" || !notebooks?.length) return;++ const noteNotebook = notebooks[0] as Item & { topics: string[] };+ const topicId = noteNotebook.topics[0];++ const notebook = db.notebooks?.notebook(noteNotebook.id)?.data as Item & {+ topics: Item[];+ };+ if (!notebook) return;++ const topic = notebook.topics.find((t: Item) => t.id === topicId);+ if (!topic) return;++ return {+ id: notebook.id,+ title: notebook.title,+ dateEdited: notebook.dateEdited,+ topic: { id: topicId, title: topic.title }+ };+}++function getDate(item: Item, groupType: keyof typeof ListProfiles) {+ if (groupType === "attachments") return item.dateCreated;++ const sortBy = db.settings?.getGroupOptions(groupType).sortBy;+ switch (sortBy) {+ case "dateEdited":+ return item.dateEdited;+ case "dateCreated":+ return item.dateCreated;+ case "dateModified":+ return item.dateModified;+ case "dateDeleted":+ return item.dateDeleted;+ default:+ return item.dateCreated;+ }+}diff --git a/apps/web/src/components/scroll-container/index.js b/apps/web/src/components/scroll-container/index.jsindex 61ec1d84c..f16d1073e 100644--- a/apps/web/src/components/scroll-container/index.js+++ b/apps/web/src/components/scroll-container/index.js@@ -83,7 +83,7 @@ export function FlexScrollContainer({flex: "1 1 auto",...style}}- renderView={({ _style, ...props }) => (+ renderView={({ style: _style, ...props }) => (<Box{...props}className={className}diff --git a/apps/web/src/components/time-ago/index.js b/apps/web/src/components/time-ago/index.jsindex ce0545c2b..b8bf81deb 100644--- a/apps/web/src/components/time-ago/index.js+++ b/apps/web/src/components/time-ago/index.js@@ -58,7 +58,7 @@ const enShortLocale = [register("short", (_n, index) => shortLocale[index]);register("en_short", (_n, index) => enShortLocale[index]);-function TimeAgo({ datetime, live, locale, opts, ...restProps }) {+function TimeAgo({ datetime, live, locale, opts, sx, ...restProps }) {const timeRef = useRef();useEffect(() => {const element = timeRef.current;@@ -82,6 +82,10 @@ function TimeAgo({ datetime, live, locale, opts, ...restProps }) {<Textref={timeRef}{...restProps}+ sx={{+ ...sx,+ color: sx?.color || "inherit"+ }}title={formatDate(datetime)}as="time"dateTime={toDate(datetime).toISOString()}diff --git a/package.json b/package.jsonindex fb7ba9f9b..21d8af163 100644--- a/package.json+++ b/package.json@@ -7,6 +7,7 @@"build": "nx run-many --target=build --all --exclude=@notesnook/mobile,@notesnook/web","build:web": "nx build @notesnook/web","start:web": "nx start @notesnook/web",+ "install:web": "lerna add --scope=@notesnook/web ","start:android": "nx run-android @notesnook/mobile","start:ios": "nx run-ios @notesnook/mobile","prepare:ios": "nx install-pods @notesnook/mobile",diff --git a/packages/core/types.js b/packages/core/types.jsindex bbf16487d..2660efbe3 100644--- a/packages/core/types.js+++ b/packages/core/types.js@@ -22,7 +22,7 @@ const _ignore = "";/*** @typedef {{* groupBy: "abc" | "year" | "month" | "week" | "none" | undefined,- * sortBy: "dateCreated" | "dateDeleted" | "dateEdited" | "title",+ * sortBy: "dateCreated" | "dateDeleted" | "dateEdited" | "dateModified" | "title",* sortDirection: "desc" | "asc"* }} GroupOptions*/