Skip to content

Commit

Permalink
Merge pull request #319 from dakyskye/respect-users-target-low-and-ta…
Browse files Browse the repository at this point in the history
…rget-high

Respect user's target low and target high
  • Loading branch information
CrazyMarvin authored Aug 5, 2024
2 parents 3b41bc3 + 65074dc commit 7f80bae
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 12 deletions.
2 changes: 1 addition & 1 deletion .erb/scripts/notarize.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ const { build } = require('../../package.json');

exports.default = async function notarizeMacos(context) {
const { electronPlatformName, appOutDir } = context;
if (electronPlatformName !== 'darwin')
if (electronPlatformName !== 'darwin') {
return;
}

Expand Down
4 changes: 2 additions & 2 deletions src/renderer/lib/linkup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ export async function getAuthToken(request: LoginAttemptRequest): Promise<string
return null
}

export async function getGraphData(request: GetGeneralRequest): Promise<string|null> {
export async function getCGMData(request: GetGeneralRequest): Promise<string|null> {
try {
const baseURL = getBaseUrl(request.country)
const headers = {
Expand Down Expand Up @@ -81,7 +81,7 @@ export async function getGraphData(request: GetGeneralRequest): Promise<string|n

console.log(graphResponse?.data?.data)

return graphResponse?.data?.data?.connection?.glucoseMeasurement
return graphResponse?.data?.data?.connection
} catch (error) {
console.log("Unable to get the token: ", error)
}
Expand Down
33 changes: 24 additions & 9 deletions src/renderer/pages/dashboard.tsx
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
import { useEffect, useState } from "react"
import { BaseLayout } from "@/layouts/base-layout"
import { useAuthStore } from "@/stores/auth"
import { getGraphData } from "@/lib/linkup"
import { getCGMData } from "@/lib/linkup"
import { TrendArrow } from "@/components/ui/trend-arrow"
import { GearIcon } from "@radix-ui/react-icons"
import { useNavigate } from "react-router-dom"
import { LoadingScreen } from "@/components/ui/loading"
import { useClearSession } from "@/hooks/session"
import { openNewWindow, setRedirectTo } from "@/lib/utils"

const LOW = 70;
const HIGH = 240;

export default function DashboardPage() {
const { clearSession } = useClearSession()
const navigate = useNavigate()
Expand All @@ -18,7 +21,7 @@ export default function DashboardPage() {
const [isReady, setIsReady] = useState(false)

const populateGraphData = async () => {
const data = await getGraphData({
const data = await getCGMData({
token: token ?? "",
country: country ?? "",
})
Expand All @@ -32,12 +35,20 @@ export default function DashboardPage() {
setIsReady(true)
}

const getColor = (value: number): string => {
if (value > 70 && value < 180) {
return "bg-green-500"
const getColor = (value: number, targetLow: number, targetHigh: number): string => {
if (value < LOW) {
return "bg-red-500"
}

if (value > HIGH) {
return "bg-orange-500"
}

if ((value < targetLow && value >= LOW) || (value > targetHigh && value <= HIGH)) {
return "bg-yellow-500"
}

return "bg-yellow-500"
return "bg-green-500"
}

useEffect(() => {
Expand All @@ -61,7 +72,11 @@ export default function DashboardPage() {

return (
<BaseLayout
className={`${getColor(graphData?.ValueInMgPerDl ?? 1)} flex justify-center items-center`}
className={`${getColor(
graphData?.glucoseMeasurement?.ValueInMgPerDl ?? 1,
graphData?.targetLow ?? 1,
graphData?.targetHigh ?? 1
)} flex justify-center items-center`}
>
<button
onClick={() => openSettings('/settings/general')}
Expand All @@ -70,9 +85,9 @@ export default function DashboardPage() {
<GearIcon className="text-white h-6 w-6" />
</button>
<div className="flex items-center gap-3">
<p className="text-white text-3xl font-semibold">{graphData?.ValueInMgPerDl} mg/dL</p>
<p className="text-white text-3xl font-semibold">{graphData?.glucoseMeasurement?.ValueInMgPerDl} mg/dL</p>
<div className="flex justify-center items-center h-12 w-12 rounded-full bg-white/25">
<TrendArrow className="h-9 w-9 text-white" trend={graphData?.TrendArrow ?? 1} />
<TrendArrow className="h-9 w-9 text-white" trend={graphData?.glucoseMeasurement?.TrendArrow ?? 1} />
</div>
</div>
</BaseLayout>
Expand Down

0 comments on commit 7f80bae

Please sign in to comment.