diff --git a/src/app/insights/components/BarGraph.tsx b/src/app/insights/components/BarGraph.tsx new file mode 100644 index 00000000..62fb7ce2 --- /dev/null +++ b/src/app/insights/components/BarGraph.tsx @@ -0,0 +1,35 @@ + + +interface BarGraphProps { + data: { name: string; value: number }[]; + } + + + + +export default function BarGraph({ data }: BarGraphProps) { + return ( +
+
+

Unmet Needs

+

Summary of needs selected as unmet

+
+
+ {data.map((need, index) => ( +
+
+ {need.name} + {need.value} +
+
+
+
+
+ ))} +
+
+ ) +} \ No newline at end of file diff --git a/src/app/insights/components/InsightsDisplay.tsx b/src/app/insights/components/InsightsDisplay.tsx index 5819bf5b..e965bee8 100644 --- a/src/app/insights/components/InsightsDisplay.tsx +++ b/src/app/insights/components/InsightsDisplay.tsx @@ -10,6 +10,8 @@ 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: { @@ -23,9 +25,25 @@ export interface Insight { createdAt: string; } +interface Need { + id: string; + name: string; + category: string; + selectedTimestamps: string[]; + timestamp: string; + selectedExpiry?: string; +} + +interface Category { + 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 dateOptions = ["day", "week", "month", "year"]; @@ -94,10 +112,57 @@ export default function InsightsDisplay() { } }; + + const getNeedsData = async () => { + try { + 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); + + // Aggregate `selectedTimestamps` counts by category + const categoryCounts = needs.reduce((acc: Record, need: Need) => { + const { category, selectedTimestamps } = need; + + if (!acc[category]) { + acc[category] = 0; + } + + 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) { + console.error("Error fetching needs data:", error); + } + }; + useEffect(() => { getInsights(); + 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: "Play", value: 54 }, + { name: "Interdependence", value: 15 }, + ]; + return ( <>
@@ -161,6 +226,15 @@ export default function InsightsDisplay() { ) : (
Loading Stream Graph...
)} + + {/* unmet needs graph */} + {needsData === null ? ( +
Loading Needs Data...
+ ) : needsData.some(item => item.value > 0) ? ( + + ) : ( + + )} ); } diff --git a/src/app/layout.tsx b/src/app/layout.tsx index 9cdfa744..cedeb0d0 100644 --- a/src/app/layout.tsx +++ b/src/app/layout.tsx @@ -7,8 +7,8 @@ import { Roboto } from "next/font/google"; const APP_NAME = "Things We Do"; const APP_DEFAULT_TITLE = "Things We Do"; -const APP_TITLE_TEMPLATE = "%s - Thing We Do"; -const APP_DESCRIPTION = "Best PWA app in the world!"; +const APP_TITLE_TEMPLATE = "%s - Things We Do"; +const APP_DESCRIPTION = "Your app for tracking things you do."; export const metadata: Metadata = { applicationName: APP_NAME,