From bd026dd3071a0e39efd4232c1d6effb4fef63865 Mon Sep 17 00:00:00 2001 From: maxitect Date: Mon, 16 Dec 2024 10:38:38 +0000 Subject: [PATCH 1/5] refactor: update DatabaseManager.ts with correct type for getFromDb method --- src/lib/db/DatabaseManager.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/lib/db/DatabaseManager.ts b/src/lib/db/DatabaseManager.ts index ac5e6823..c719ebbf 100644 --- a/src/lib/db/DatabaseManager.ts +++ b/src/lib/db/DatabaseManager.ts @@ -1,4 +1,4 @@ -import { addRxPlugin, RxDocumentData } from "rxdb"; +import { addRxPlugin, RxDocument } from "rxdb"; import { RxDBDevModePlugin } from "rxdb/plugins/dev-mode"; import { getRxStorageDexie } from "rxdb/plugins/storage-dexie"; import { createRxDatabase, RxDatabase } from "rxdb"; @@ -121,7 +121,7 @@ class DatabaseManager { } } - async getFromDb(collection: string): Promise[]> { + async getFromDb(collection: string): Promise[]> { const db = await this.accessDatabase(); const collectionExists = db.collections[collection]; if (!collectionExists) From 587857caf994e171965dac5b2b820750f8da3a03 Mon Sep 17 00:00:00 2001 From: maxitect Date: Mon, 16 Dec 2024 10:41:02 +0000 Subject: [PATCH 2/5] refactor: update InsightsDisplay.tsx with simpler types due to DatabaseManager type fix --- .../insights/components/InsightsDisplay.tsx | 61 ++++++++++--------- 1 file changed, 32 insertions(+), 29 deletions(-) diff --git a/src/app/insights/components/InsightsDisplay.tsx b/src/app/insights/components/InsightsDisplay.tsx index e965bee8..5b78ba3b 100644 --- a/src/app/insights/components/InsightsDisplay.tsx +++ b/src/app/insights/components/InsightsDisplay.tsx @@ -9,10 +9,8 @@ import { useState, useEffect } from "react"; import Button from "@/ui/shared/Button"; import clsx from "clsx"; import MoodStreamGraph from "./StreamGraph"; -import { RxDocument } from "rxdb"; import BarGraph from "./BarGraph"; - export interface Insight { neurotransmitters: { dopamine: number; @@ -29,21 +27,25 @@ interface Need { id: string; name: string; category: string; - selectedTimestamps: string[]; - timestamp: string; - selectedExpiry?: string; + mood?: string; + priority?: object; + selectedTimestamps: string[]; + timestamp: string; + selectedExpiry?: string; } interface Category { - id: string; - name: string; - timestamp: string; + id: string; + name: string; + timestamp: string; } export default function InsightsDisplay() { const database = useDatabase(); const [insights, setInsights] = useState(null); - const [needsData, setNeedsData] = useState<{ name: string; value: number }[] | null>(null); + const [needsData, setNeedsData] = useState< + { name: string; value: number }[] | null + >(null); const dateOptions = ["day", "week", "month", "year"]; @@ -89,9 +91,7 @@ export default function InsightsDisplay() { }, [/* useNow, */ selectedButton, now]); const getInsights = async () => { - const insightsResponse = await database.getFromDb>( - "mood_records" - ); + const insightsResponse = await database.getFromDb("mood_records"); if (!insightsResponse) { console.log("No insights found."); @@ -112,34 +112,38 @@ export default function InsightsDisplay() { } }; - const getNeedsData = async () => { try { - const needsResponse = await database.getFromDb>("needs"); - const categoriesResponse = await database.getFromDb>("needs_categories"); + const needsResponse = await database.getFromDb("needs"); + const categoriesResponse = await database.getFromDb("needs_categories"); const needs = needsResponse.map((doc) => doc.toJSON() as Need); - const categories = categoriesResponse.map((doc) => doc.toJSON() as Category); + const categories = categoriesResponse.map( + (doc) => doc.toJSON() as Category + ); // Aggregate `selectedTimestamps` counts by category - const categoryCounts = needs.reduce((acc: Record, need: Need) => { - const { category, selectedTimestamps } = need; + const categoryCounts = needs.reduce( + (acc: Record, need: Need) => { + const { category, selectedTimestamps } = need; - if (!acc[category]) { - acc[category] = 0; - } + if (!acc[category]) { + acc[category] = 0; + } - acc[category] += selectedTimestamps ? selectedTimestamps.length : 0; - return acc; - }, {}); + acc[category] += selectedTimestamps ? selectedTimestamps.length : 0; + return acc; + }, + {} + ); // Map categories to their names with counts const needsData = categories.map((category: Category) => ({ name: category.name, value: categoryCounts[category.id] || 0, })); - + console.log("Final Needs Data for BarGraph:", needsData); setNeedsData(needsData); } catch (error) { @@ -152,20 +156,19 @@ export default function InsightsDisplay() { getNeedsData(); }, []); - const dummyNeedsData = [ { name: "Integrity", value: 8 }, { name: "Celebration", value: 35 }, { name: "Physical Nurturance", value: 12 }, { name: "Autonomy", value: 10 }, - { name: "Harmony", value: 71 }, + { name: "Harmony", value: 71 }, { name: "Play", value: 54 }, { name: "Interdependence", value: 15 }, ]; return ( <> -
+
{dateOptions.map((dateOption, index) => { const isActive = selectedButton === dateOption; return ( @@ -230,7 +233,7 @@ export default function InsightsDisplay() { {/* unmet needs graph */} {needsData === null ? (
Loading Needs Data...
- ) : needsData.some(item => item.value > 0) ? ( + ) : needsData.some((item) => item.value > 0) ? ( ) : ( From f96fe330f7bbbfe613e031d2be7756a9b8daf7f2 Mon Sep 17 00:00:00 2001 From: maxitect Date: Mon, 16 Dec 2024 10:42:30 +0000 Subject: [PATCH 3/5] refactor: update ToolList.tsx with simpler types due to DatabaseManager type fix --- src/app/toolkit/components/ToolList.tsx | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/src/app/toolkit/components/ToolList.tsx b/src/app/toolkit/components/ToolList.tsx index 6e25f622..0aa6a6a5 100644 --- a/src/app/toolkit/components/ToolList.tsx +++ b/src/app/toolkit/components/ToolList.tsx @@ -10,7 +10,6 @@ import { import SortableItem from "./SortableItem"; import Search from "@/ui/shared/Search"; import { useToolkit } from "@/context/ToolkitContext"; -import { RxDocument } from "rxdb"; export interface ToolkitComponentData { id: string; @@ -36,9 +35,7 @@ export default function ToolkitList() { useEffect(() => { const fetchData = async () => { try { - const items = await database.getFromDb< - RxDocument - >("toolkit_items"); + const items = await database.getFromDb("toolkit_items"); if (items) { const toolkitData = items.map( (doc) => doc.toJSON() as ToolkitComponentData From 42e9d99a3fc47480ff0780d0a49cfd61e5439650 Mon Sep 17 00:00:00 2001 From: maxitect Date: Mon, 16 Dec 2024 10:43:26 +0000 Subject: [PATCH 4/5] refactor: increase to z-20 for InfoButton.tsx component so that the popup appears in front of catbar --- src/ui/shared/InfoButton.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ui/shared/InfoButton.tsx b/src/ui/shared/InfoButton.tsx index 06e65566..34f1ff4c 100644 --- a/src/ui/shared/InfoButton.tsx +++ b/src/ui/shared/InfoButton.tsx @@ -54,7 +54,7 @@ export default function InfoButton({ {isPopupOpen && (

{popupText}

From b76a6f64a844376df6c8096a6fc4d87648becdf5 Mon Sep 17 00:00:00 2001 From: maxitect Date: Mon, 16 Dec 2024 10:44:13 +0000 Subject: [PATCH 5/5] refactor: update CategoriesBar.tsx, remove comments, add dependencies and remove eslint disable --- src/app/toolkit/components/CategoriesBar.tsx | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/src/app/toolkit/components/CategoriesBar.tsx b/src/app/toolkit/components/CategoriesBar.tsx index 8af01b3b..dca00b4b 100644 --- a/src/app/toolkit/components/CategoriesBar.tsx +++ b/src/app/toolkit/components/CategoriesBar.tsx @@ -42,8 +42,7 @@ export default function CategoriesBar({ } }; fetchCategories(); - // eslint-disable-next-line react-hooks/exhaustive-deps - }, [refreshCategories]); + }, [database, refreshCategories]); const handleCategoriesClick = (category: string) => { setSelectedCategories( @@ -64,11 +63,6 @@ export default function CategoriesBar({ > - {/*
{/* Scrollable Categories */}