Skip to content

Commit

Permalink
activity indicators in correct y position
Browse files Browse the repository at this point in the history
  • Loading branch information
trevorpfiz committed Aug 26, 2024
1 parent 982d4d9 commit d3c4762
Show file tree
Hide file tree
Showing 10 changed files with 67 additions and 74 deletions.
6 changes: 6 additions & 0 deletions apps/expo/app.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,5 +92,11 @@ export default ({ config }: ConfigContext): ExpoConfig => ({
enableCodeScanner: true,
},
],
[
"@react-native-google-signin/google-signin",
{
iosUrlScheme: "com.googleusercontent.apps._some_id_here_",
},
],
],
});
6 changes: 5 additions & 1 deletion apps/expo/jest.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,11 @@ import type { Config } from "jest";

const config: Config = {
preset: "jest-expo",
setupFilesAfterEnv: ["<rootDir>/jest-setup.ts", "<rootDir>/setup.ts"],
setupFilesAfterEnv: [
"<rootDir>/jest-setup.ts",
"<rootDir>/setup.ts",
"<rootDir>/node_modules/@react-native-google-signin/google-signin/jest/build/jest/setup.js",
],
testMatch: ["**/?(*.)+(spec|test).ts?(x)"],
collectCoverageFrom: [
"src/**/*.{ts,tsx}",
Expand Down
10 changes: 10 additions & 0 deletions apps/expo/src/app/(app)/(tabs)/account.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { View } from "react-native";
import { useRouter } from "expo-router";
import {
useSessionContext,
useSupabaseClient,
Expand All @@ -10,6 +11,8 @@ import { Button } from "~/components/ui/button";
import { Text } from "~/components/ui/text";

export default function AccountScreen() {
const router = useRouter();

const user = useUser();

const SignOut = () => {
Expand All @@ -28,6 +31,13 @@ export default function AccountScreen() {
>
<Text>Sign Out</Text>
</Button>
<Button
onPress={() => {
router.replace("/(home)");
}}
>
<Text>root</Text>
</Button>
<ThemeToggle />
</View>
);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import React from "react";
import { View } from "react-native";

import AnimatedIntro from "~/components/intro/animated-intro";
Expand Down
11 changes: 3 additions & 8 deletions apps/expo/src/app/_layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ SplashScreen.preventAutoHideAsync();

export const unstable_settings = {
// Ensure any route can link back to `/`
initialRouteName: "index",
initialRouteName: "(home)/index",
};

const InitialLayout = () => {
Expand All @@ -56,9 +56,6 @@ const InitialLayout = () => {
const [isLoaded, setIsLoaded] = useState(false);
const [isSignedIn, setIsSignedIn] = useState(false);

console.log("isLoaded", isLoaded);
console.log("isSignedIn", isSignedIn);

useEffect(() => {
supabase.auth.getSession().then(({ data: { session } }) => {
setIsSignedIn(!!session);
Expand All @@ -84,7 +81,7 @@ const InitialLayout = () => {
if (isSignedIn && !inAppGroup) {
router.replace("/(tabs)");
} else if (!isSignedIn && inAppGroup) {
router.replace("/");
router.replace("/(home)");
}
}, [isLoaded, isSignedIn, segments, router]);

Expand All @@ -97,7 +94,7 @@ const InitialLayout = () => {
<SafeAreaEnv>
<Stack>
<Stack.Screen
name="index"
name="(home)/index"
options={{
headerShown: false,
}}
Expand Down Expand Up @@ -144,8 +141,6 @@ export default function RootLayout() {
const { colorScheme, setColorScheme, isDarkColorScheme } = useColorScheme();
const [isColorSchemeLoaded, setIsColorSchemeLoaded] = useState(false);

console.log("isColorSchemeLoaded", isColorSchemeLoaded);

useEffect(() => {
(async () => {
const theme = await AsyncStorage.getItem("theme");
Expand Down
79 changes: 28 additions & 51 deletions apps/expo/src/components/charts/cgm-chart.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import type { SharedValue } from "react-native-reanimated";
import type { ChartBounds } from "victory-native";
import type { ChartBounds, PointsArray } from "victory-native";
import { useMemo } from "react";
import { View } from "react-native";
import { useDerivedValue, useSharedValue } from "react-native-reanimated";
import { useDerivedValue } from "react-native-reanimated";
import { Inter_500Medium } from "@expo-google-fonts/inter";
import {
Circle,
Expand Down Expand Up @@ -47,7 +47,7 @@ const activityTypeToEmoji = {

export default function CGMChart() {
const { colorScheme } = useColorScheme();
const { selectedActivity, setSelectedActivity } = useActivityStore();
// const { selectedActivity, setSelectedActivity } = useActivityStore();
const font = useFont(Inter_500Medium, 12);

// Preprocess the data to use hour numbers for x-axis
Expand All @@ -60,6 +60,7 @@ export default function CGMChart() {
[],
);

// Preprocess the activity data to use hour numbers for x-axis
const processedActivityData = useMemo(
() =>
mockActivityData.map((item) => ({
Expand All @@ -74,36 +75,6 @@ export default function CGMChart() {
y: { amount: 0 },
});

const selectedActivityIndex = useSharedValue<number | null>(null);

useDerivedValue(() => {
if (isActive) {
const pressedXValue = state.x.value.value;
const nearestActivityIndex = processedActivityData.reduce(
(nearest, current, index) => {
const currentDiff = Math.abs(current.hour - pressedXValue);
const nearestDiff = Math.abs(
processedActivityData[nearest].hour - pressedXValue,
);
return currentDiff < nearestDiff ? index : nearest;
},
0,
);

if (
Math.abs(
processedActivityData[nearestActivityIndex].hour - pressedXValue,
) <= 0.5
) {
selectedActivityIndex.value = nearestActivityIndex;
} else {
selectedActivityIndex.value = null;
}
} else {
selectedActivityIndex.value = null;
}
}, [isActive, state.x.value]);

const labelColor = colorScheme === "dark" ? "white" : "black";
const lineColor =
colorScheme === "dark"
Expand Down Expand Up @@ -166,25 +137,22 @@ export default function CGMChart() {
strokeWidth={3}
animate={{ type: "timing", duration: 500 }}
connectMissingData={false}
curveType="natural"
/>
{processedActivityData.map((activity, index) => (
<ActivityIndicator
key={index}
activity={activity}
chartBounds={chartBounds}
isSelected={selectedActivityIndex.value === index}
points={points.amount}
/>
))}
{(isActive || selectedActivity) && (
{isActive && (
<ActiveValueIndicator
xPosition={
selectedActivity ? selectedActivity.hour : state.x.position
}
xPosition={state.x.position}
yPosition={state.y.amount.position}
activeValue={state.y.amount.value}
activeTime={
selectedActivity ? selectedActivity.hour : state.x.value
}
activeTime={state.x.value}
bottom={chartBounds.bottom}
top={chartBounds.top}
textColor={labelColor}
Expand All @@ -202,27 +170,36 @@ export default function CGMChart() {
const ActivityIndicator = (props: {
activity: ProcessedActivityData;
chartBounds: ChartBounds;
isSelected: boolean;
points: PointsArray;
}) => {
const { activity, chartBounds, isSelected } = props;
const { activity, chartBounds, points } = props;

// Find the closest point to the activity's hour
const closestPoint = points.reduce((prev, curr) =>
Math.abs((curr.xValue as number) - activity.hour) <
Math.abs((prev.xValue as number) - activity.hour)
? curr
: prev,
);

// Calculate x position based on the closest point
const xPosition = closestPoint.x;

const xPosition =
(activity.hour / 24) * (chartBounds.right - chartBounds.left) +
chartBounds.left;
const yPosition = chartBounds.bottom - 20; // Place it slightly above the bottom of the chart
// Calculate y position based on the closest point
const yPosition = closestPoint.y ?? chartBounds.bottom - 20;

return (
<>
<Circle
cx={xPosition}
cy={yPosition}
r={isSelected ? 15 : 10}
color={isSelected ? "rgba(0, 255, 0, 0.5)" : "rgba(200, 200, 200, 0.5)"}
r={10}
color="rgba(200, 200, 200, 0.5)"
/>
<SKText
x={xPosition - 10}
x={xPosition - 5}
y={yPosition + 5}
text={activityTypeToEmoji[activity.type]}
text={"a"}
font={useFont(Inter_500Medium, 20)}
/>
</>
Expand Down
7 changes: 5 additions & 2 deletions apps/expo/src/components/ui/button.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -62,17 +62,20 @@ const buttonTextVariants = cva(
);

type ButtonProps = React.ComponentPropsWithoutRef<typeof Pressable> &
VariantProps<typeof buttonVariants>;
VariantProps<typeof buttonVariants> & {
textClassName?: string;
};

const Button = React.forwardRef<
React.ElementRef<typeof Pressable>,
ButtonProps
>(({ className, variant, size, ...props }, ref) => {
>(({ className, variant, size, textClassName, ...props }, ref) => {
return (
<TextClassContext.Provider
value={cn(
props.disabled && "web:pointer-events-none",
buttonTextVariants({ variant, size }),
textClassName,
)}
>
<Pressable
Expand Down
2 changes: 1 addition & 1 deletion apps/expo/src/data/activity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export const mockActivityData = [
},
{
type: "work",
dateTime: "2024-08-12T09:00:00",
dateTime: "2024-08-12T09:01:00",
title: "Start Work",
description: "Begin workday at the office",
},
Expand Down
1 change: 0 additions & 1 deletion apps/expo/src/lib/use-color-scheme.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ export function useColorScheme() {
const { colorScheme, setColorScheme, toggleColorScheme } =
useNativewindColorScheme();

console.log("colorSchemeasdfffff", colorScheme);
return {
colorScheme: colorScheme ?? "dark",
isDarkColorScheme: colorScheme === "dark",
Expand Down
18 changes: 9 additions & 9 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit d3c4762

Please sign in to comment.