mirror of
https://github.com/streetwriters/notesnook.git
synced 2025-12-23 23:19:40 +01:00
feat: show attachments count on note items
This commit is contained in:
@@ -11,7 +11,7 @@
|
||||
"@mdi/react": "^1.4.0",
|
||||
"@notesnook/desktop": "file:desktop",
|
||||
"@rebass/forms": "^4.0.6",
|
||||
"@streetwritersco/tinymce-plugins": "^1.4.11",
|
||||
"@streetwritersco/tinymce-plugins": "^1.4.14",
|
||||
"@tinymce/tinymce-react": "^3.13.0",
|
||||
"async-mutex": "^0.3.2",
|
||||
"axios": "^0.21.4",
|
||||
|
||||
@@ -25,6 +25,7 @@ const NotesProfile = createProfile(
|
||||
item={item}
|
||||
tags={getTags(item)}
|
||||
notebook={getNotebook(item.notebooks, context?.type)}
|
||||
attachments={getAttachmentsCount(item.id)}
|
||||
context={context}
|
||||
/>
|
||||
),
|
||||
@@ -107,3 +108,7 @@ function getNotebook(notebooks, contextType) {
|
||||
topic: { id: topicId, title: topic.title },
|
||||
};
|
||||
}
|
||||
|
||||
function getAttachmentsCount(noteId) {
|
||||
return db.attachments.ofNote(noteId, "all").length;
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import React, { useMemo } from "react";
|
||||
import { Button, Flex } from "rebass";
|
||||
import { Button, Flex, Text } from "rebass";
|
||||
import * as Icon from "../icons";
|
||||
import TimeAgo from "../time-ago";
|
||||
import ListItem from "../list-item";
|
||||
@@ -17,7 +17,7 @@ import Vault from "../../common/vault";
|
||||
import IconTag from "../icon-tag";
|
||||
|
||||
function Note(props) {
|
||||
const { tags, notebook, item, index, context } = props;
|
||||
const { tags, notebook, item, index, context, attachments } = props;
|
||||
const note = item;
|
||||
const isOpened = useStore((store) => store.selectedNote === note.id);
|
||||
const isCompact = useStore((store) => store.viewMode === "compact");
|
||||
@@ -110,6 +110,13 @@ function Note(props) {
|
||||
mr={1}
|
||||
/>
|
||||
|
||||
{attachments > 0 && (
|
||||
<Flex mr={1}>
|
||||
<Icon.Attachment size={16} color="fontTertiary" />
|
||||
<Text ml={"2px"}>{attachments}</Text>
|
||||
</Flex>
|
||||
)}
|
||||
|
||||
{note.pinned && !props.context && (
|
||||
<Icon.Pin size={13} color={primary} sx={{ mr: 1 }} />
|
||||
)}
|
||||
@@ -170,6 +177,7 @@ export default React.memo(Note, function (prevProps, nextProps) {
|
||||
prevItem.locked === nextItem.locked &&
|
||||
prevItem.conflicted === nextItem.conflicted &&
|
||||
prevItem.color === nextItem.color &&
|
||||
prevProps.attachments === nextProps.attachments &&
|
||||
prevProps.notebook?.dateEdited === nextProps.notebook?.dateEdited &&
|
||||
JSON.stringify(prevProps.tags) === JSON.stringify(nextProps.tags)
|
||||
);
|
||||
|
||||
@@ -186,12 +186,12 @@ class EditorStore extends BaseStore {
|
||||
noteStore.setSelectedNote(id);
|
||||
}
|
||||
|
||||
const attachments = db.attachments.ofNote(note.id, "all");
|
||||
this.set((state) => {
|
||||
state.session.id = note.id;
|
||||
state.session.isSaving = false;
|
||||
state.session.notebooks = note.notebooks;
|
||||
state.session.attachments =
|
||||
db.attachments.ofNote(note.id, "all") || [];
|
||||
state.session.attachments = attachments;
|
||||
});
|
||||
|
||||
if (!oldSession) {
|
||||
@@ -200,6 +200,7 @@ class EditorStore extends BaseStore {
|
||||
}
|
||||
|
||||
if (
|
||||
attachments?.length !== oldSession.attachments.length ||
|
||||
note.headline !== oldSession.headline ||
|
||||
note.title !== oldSession.title
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user