Skip to content

Commit

Permalink
web: get total notes count for topic using db
Browse files Browse the repository at this point in the history
  • Loading branch information
thecodrr committed Sep 8, 2022
1 parent 2adce27 commit 10b8703
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions apps/web/src/components/topic/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ 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 React from "react";
import React, { useMemo } from "react";
import ListItem from "../list-item";
import { db } from "../../common/db";
import { store as appStore } from "../../stores/app-store";
Expand All @@ -28,7 +28,12 @@ import { Multiselect } from "../../common/multi-select";
import { pluralize } from "../../utils/string";

function Topic({ item, index, onClick }) {
const { id, notebookId } = item;
const topic = item;
const totalNotes = useMemo(() => {
return db.notebooks.notebook(notebookId)?.topics.topic(id).totalNotes;
}, [id, notebookId]);

return (
<ListItem
selectable
Expand All @@ -50,7 +55,7 @@ function Topic({ item, index, onClick }) {
</Text>
<Text variant="subBody">
{pluralize(topic.notes?.length || 0, "note", "notes")}
{pluralize(totalNotes || 0, "note", "notes")}
</Text>
</Flex>
}
Expand All @@ -64,10 +69,7 @@ function Topic({ item, index, onClick }) {
}

export default React.memo(Topic, (prev, next) => {
return (
prev?.item?.title === next?.item?.title &&
prev?.item?.notes.length === next?.item?.notes.length
);
return prev?.item?.title === next?.item?.title;
});

const menuItems = [
Expand Down

0 comments on commit 10b8703

Please sign in to comment.