Skip to content

Commit 817257a

Browse files
committed
start template system
1 parent d239d2d commit 817257a

File tree

2 files changed

+100
-5
lines changed

2 files changed

+100
-5
lines changed

apps/mobile/src/components/app/trackableLogStep.tsx

Lines changed: 80 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import React, { useRef, useState } from "react";
22
import { View } from "react-native";
33
import { useRouter } from "expo-router";
44
import { useForm } from "@tanstack/react-form";
5-
import { useMutation } from "@tanstack/react-query";
5+
import { useMutation, useQuery } from "@tanstack/react-query";
66
import { toast } from "sonner-native";
77

88
import type { ConstsTypes } from "@1up/consts";
@@ -12,21 +12,28 @@ import { ImagePickerUploader } from "~/components/ui/image-picker-uploader";
1212
import { Text } from "~/components/ui/text";
1313
import { Textarea } from "~/components/ui/textarea";
1414
import { trpc } from "~/utils/api";
15+
import { Button } from "../ui/button";
1516
import { LogStepWrapper } from "./logStepWrapper";
1617

18+
// Use the proper type from consts
19+
type TrackableParentType = ConstsTypes["TRACKABLE"]["TYPES"]["KEY"];
20+
type TrackableSubType = ConstsTypes["TRACKABLE"]["SUB_TYPES"]["KEY"];
21+
1722
// Lookup data for different trackable types
1823
interface TrackableOptions {
1924
textAreaPlaceholders: string[];
2025
generalName: string;
2126
textAreaLabel: string;
2227
tipText: string;
2328
title: string;
29+
new: {
30+
name: string;
31+
description: string;
32+
icon: string;
33+
subType: TrackableSubType;
34+
}[];
2435
}
2536

26-
// Use the proper type from consts
27-
type TrackableParentType = ConstsTypes["TRACKABLE"]["TYPES"]["KEY"];
28-
type TrackableSubType = ConstsTypes["TRACKABLE"]["SUB_TYPES"]["KEY"];
29-
3037
const trackableLookup: Record<TrackableParentType, TrackableOptions> = {
3138
consumption: {
3239
textAreaPlaceholders: [
@@ -41,6 +48,26 @@ const trackableLookup: Record<TrackableParentType, TrackableOptions> = {
4148
tipText:
4249
"Be as detailed as possible about the components and size of this meal/drink.",
4350
title: "Food & Drink",
51+
new: [
52+
{
53+
name: "Nom npm",
54+
description: "Log your food and drink",
55+
icon: "🍽️",
56+
subType: "consumption.parent.other",
57+
},
58+
{
59+
name: "Lala",
60+
description: "Log your food and drink",
61+
icon: "🍽️",
62+
subType: "consumption.parent.other",
63+
},
64+
{
65+
name: "ooooo",
66+
description: "Log your food and drink",
67+
icon: "🍽️",
68+
subType: "consumption.parent.other",
69+
},
70+
],
4471
},
4572
activity: {
4673
textAreaPlaceholders: [
@@ -55,6 +82,7 @@ const trackableLookup: Record<TrackableParentType, TrackableOptions> = {
5582
tipText:
5683
"Include details like duration, intensity, and any other relevant information.",
5784
title: "Physical Activity",
85+
new: [],
5886
},
5987
medication: {
6088
textAreaPlaceholders: [
@@ -68,6 +96,7 @@ const trackableLookup: Record<TrackableParentType, TrackableOptions> = {
6896
textAreaLabel: "What medication did you take?",
6997
tipText: "Include details like dosage, frequency, and any side effects.",
7098
title: "Medication",
99+
new: [],
71100
},
72101
supplement: {
73102
textAreaPlaceholders: [
@@ -82,6 +111,7 @@ const trackableLookup: Record<TrackableParentType, TrackableOptions> = {
82111
tipText:
83112
"Include details like dosage, brand if relevant, and when you took it.",
84113
title: "Supplement",
114+
new: [],
85115
},
86116
energy: {
87117
textAreaPlaceholders: [
@@ -96,6 +126,7 @@ const trackableLookup: Record<TrackableParentType, TrackableOptions> = {
96126
tipText:
97127
"Note any patterns or factors that might be affecting your energy levels.",
98128
title: "Energy",
129+
new: [],
99130
},
100131
blood: {
101132
textAreaPlaceholders: [
@@ -109,6 +140,7 @@ const trackableLookup: Record<TrackableParentType, TrackableOptions> = {
109140
textAreaLabel: "What blood metric are you logging?",
110141
tipText: "Include specific measurements, units, and context if available.",
111142
title: "Blood Reading",
143+
new: [],
112144
},
113145
body: {
114146
textAreaPlaceholders: [
@@ -122,6 +154,7 @@ const trackableLookup: Record<TrackableParentType, TrackableOptions> = {
122154
textAreaLabel: "What would you like to record about your body?",
123155
tipText: "Include specific measurements with units where applicable.",
124156
title: "Body",
157+
new: [],
125158
},
126159
sleep: {
127160
textAreaPlaceholders: [
@@ -136,6 +169,7 @@ const trackableLookup: Record<TrackableParentType, TrackableOptions> = {
136169
tipText:
137170
"Include details about duration, quality, and any factors affecting your sleep.",
138171
title: "Sleep",
172+
new: [],
139173
},
140174
mind: {
141175
textAreaPlaceholders: [
@@ -150,6 +184,7 @@ const trackableLookup: Record<TrackableParentType, TrackableOptions> = {
150184
tipText:
151185
"Share details about your mental wellbeing, practices, or observations.",
152186
title: "Mind",
187+
new: [],
153188
},
154189
symptom: {
155190
textAreaPlaceholders: [
@@ -164,6 +199,7 @@ const trackableLookup: Record<TrackableParentType, TrackableOptions> = {
164199
tipText:
165200
"Include details about severity, duration, and any potential triggers.",
166201
title: "Symptom",
202+
new: [],
167203
},
168204
custom: {
169205
textAreaPlaceholders: [
@@ -177,6 +213,7 @@ const trackableLookup: Record<TrackableParentType, TrackableOptions> = {
177213
textAreaLabel: "What would you like to log?",
178214
tipText: "Add any relevant details that you want to track.",
179215
title: "Custom Log",
216+
new: [],
180217
},
181218
};
182219

@@ -209,6 +246,17 @@ export const TrackableLogStep = ({
209246
}: TrackableLogStepProps) => {
210247
const lookupValues = getLookupValues(trackableParentType);
211248

249+
// get user profile
250+
const {
251+
data: parentTrackableTypes,
252+
// isLoading: parentTrackableTypesLoading,
253+
// error: parentTrackableTypesError,
254+
} = useQuery(
255+
trpc.log.getTrackableParentTypes.queryOptions({
256+
trackableParentType,
257+
}),
258+
);
259+
212260
// Text related
213261
const [placeholder] = useState(
214262
lookupValues.textAreaPlaceholders[
@@ -348,6 +396,33 @@ export const TrackableLogStep = ({
348396
onSubmit={handleSubmit}
349397
submitting={isFormSubmitting}
350398
/>
399+
400+
<Text className="text-sand-11 text-sm">
401+
Existing TRACKERS {parentTrackableTypes?.length}
402+
</Text>
403+
{parentTrackableTypes?.map((trackable) => (
404+
<Text key={trackable.id} className="text-sand-11 text-sm">
405+
{trackable.name}
406+
</Text>
407+
))}
408+
409+
{lookupValues.new.length > 0 && (
410+
<Text className="text-sand-11 text-sm">
411+
Track something new with a template
412+
</Text>
413+
)}
414+
{lookupValues.new.map((newTrackable) => (
415+
<Button
416+
variant={"outline"}
417+
size={"sm"}
418+
key={newTrackable.name}
419+
onPress={() => {
420+
console.log("pressed");
421+
}}
422+
>
423+
<Text>{newTrackable.name}</Text>
424+
</Button>
425+
))}
351426
</View>
352427
</LogStepWrapper>
353428
);

packages/trpc/src/router/log.ts

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { TRPCError } from "@trpc/server";
33
import { z } from "zod";
44

55
import { CONSTS } from "@1up/consts";
6+
import { and, eq, trackables } from "@1up/db";
67

78
import { protectedProcedure } from "../trpc";
89

@@ -46,4 +47,23 @@ export const logRouter = {
4647
success: true,
4748
};
4849
}),
50+
getTrackableParentTypes: protectedProcedure
51+
.input(
52+
z.object({
53+
trackableParentType: CONSTS.TRACKABLE.TYPES_SCHEMA,
54+
}),
55+
)
56+
.query(async ({ ctx, input }) => {
57+
const { db, auth } = ctx;
58+
const user = auth.user;
59+
60+
const logTypeTrackables = await db.query.trackables.findMany({
61+
where: and(
62+
eq(trackables.ownerId, user.id),
63+
eq(trackables.type, input.trackableParentType),
64+
),
65+
});
66+
67+
return logTypeTrackables;
68+
}),
4969
} satisfies TRPCRouterRecord;

0 commit comments

Comments
 (0)