-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: day slider skeleton and all recaps
- Loading branch information
1 parent
1671d49
commit b695597
Showing
23 changed files
with
1,521 additions
and
183 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
import React from "react"; | ||
import { useSafeAreaInsets } from "react-native-safe-area-context"; | ||
|
||
import type { GlucoseRangeTypes } from "@hyper/db/schema"; | ||
|
||
import { Label } from "~/components/ui/label"; | ||
import { | ||
Select, | ||
SelectContent, | ||
SelectGroup, | ||
SelectItem, | ||
SelectTrigger, | ||
SelectValue, | ||
} from "~/components/ui/select"; | ||
import { useGlucoseStore } from "~/stores/glucose-store"; | ||
|
||
interface RangeOption { | ||
value: GlucoseRangeTypes; | ||
label: string; | ||
} | ||
|
||
function ChangeRangeSetting() { | ||
const insets = useSafeAreaInsets(); | ||
const contentInsets = { | ||
top: insets.top, | ||
bottom: insets.bottom, | ||
left: insets.left, | ||
right: insets.right, | ||
}; | ||
|
||
const { rangeView, setRangeView } = useGlucoseStore(); | ||
|
||
console.log(rangeView); | ||
|
||
const capitalizeFirstLetter = (string: string) => { | ||
return string.charAt(0).toUpperCase() + string.slice(1); | ||
}; | ||
|
||
const rangeOptions: RangeOption[] = [ | ||
{ value: "standard", label: capitalizeFirstLetter("standard") }, | ||
{ value: "tight", label: capitalizeFirstLetter("tight") }, | ||
{ value: "optimal", label: capitalizeFirstLetter("optimal") }, | ||
]; | ||
|
||
const currentOption = | ||
rangeOptions.find((option) => option.value === rangeView) ?? | ||
rangeOptions[0]; | ||
|
||
return ( | ||
<> | ||
<Label nativeID="range-view">Range View</Label> | ||
<Select | ||
defaultValue={currentOption} | ||
onValueChange={(option) => | ||
setRangeView(option?.value as "standard" | "tight" | "optimal") | ||
} | ||
> | ||
<SelectTrigger className="w-[250px]" aria-labelledby="range-view"> | ||
<SelectValue | ||
className="native:text-lg text-sm text-foreground" | ||
placeholder="Select a range view" | ||
/> | ||
</SelectTrigger> | ||
<SelectContent insets={contentInsets} className="w-[250px]"> | ||
<SelectGroup> | ||
{/* <SelectLabel>Range View</SelectLabel> */} | ||
<SelectItem label="Standard" value="standard" /> | ||
<SelectItem label="Tight" value="tight" /> | ||
<SelectItem label="Optimal" value="optimal" /> | ||
</SelectGroup> | ||
</SelectContent> | ||
</Select> | ||
</> | ||
); | ||
} | ||
|
||
export { ChangeRangeSetting }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
import React from "react"; | ||
import { Alert, View } from "react-native"; | ||
|
||
import { Button } from "~/components/ui/button"; | ||
import { Text } from "~/components/ui/text"; | ||
import { api } from "~/utils/api"; | ||
|
||
const CalculateRecap: React.FC = () => { | ||
const utils = api.useUtils(); | ||
|
||
const mutation = api.recap.calculateAndStoreRecapsForRange.useMutation({ | ||
onSuccess: async (data) => { | ||
Alert.alert( | ||
"Success", | ||
`Recaps calculated and stored successfully for ${data.length} days.`, | ||
); | ||
await utils.recap.getDailyRecaps.invalidate(); | ||
}, | ||
onError: (error) => { | ||
Alert.alert("Error", `Failed to calculate recaps: ${error.message}`); | ||
}, | ||
}); | ||
|
||
const handleCalculateRecaps = () => { | ||
const augustStart = new Date("2024-08-01T00:00:00Z"); | ||
const augustEnd = new Date("2024-08-31T23:59:59Z"); | ||
|
||
const queryInput = { | ||
startDate: augustStart.toISOString(), | ||
endDate: augustEnd.toISOString(), | ||
}; | ||
|
||
mutation.mutate(queryInput); | ||
}; | ||
|
||
return ( | ||
<View> | ||
<Button onPress={handleCalculateRecaps} disabled={mutation.isPending}> | ||
<Text> | ||
{mutation.isPending | ||
? "Calculating..." | ||
: "Calculate August 2024 Recaps"} | ||
</Text> | ||
</Button> | ||
{mutation.isError ? ( | ||
<Text>An error occurred: {mutation.error.message}</Text> | ||
) : null} | ||
{mutation.isSuccess ? ( | ||
<Text>Last calculated: {new Date().toLocaleString()}</Text> | ||
) : null} | ||
</View> | ||
); | ||
}; | ||
|
||
export { CalculateRecap }; |
Oops, something went wrong.