Skip to content

Commit

Permalink
feat: delay home tab until next release & move everything to insights…
Browse files Browse the repository at this point in the history
… page
  • Loading branch information
oreHGA committed Aug 2, 2023
1 parent 9ba40d5 commit d185777
Show file tree
Hide file tree
Showing 6 changed files with 149 additions and 183 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ export const InsightsHeader = () => {
return (
<View className="flex flex-row p-5 justify-between flex-nowrap bg-dark">
<View className="flex flex-row">
<Text className="font-sans-bold text-[26px] text-white">Monthly</Text>
<Text className="font-sans-bold text-[26px] text-white">Weekly</Text>
<Button
variant="ghost"
size="icon"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ export const PromptOptionsSheet: FC<PromptOptionsSheetProps> = ({
},
},
{
option: "View Responses",
option: "View Insights",
icon: <FontAwesome5 name="history" size={18} color="white" />,
onPress: () => {
onBottomSheetClose?.();
Expand Down
4 changes: 3 additions & 1 deletion fusionMobile/src/navigation/insights-navigator.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@ import { InsightsHeader } from "~/components";
import { InsightsScreen } from "~/pages/insights";

export type InsightsStackParamList = {
InsightsPage: undefined;
InsightsPage: {
promptUuid: string | null;
};
};

export type InsightsScreenNavigationProp =
Expand Down
11 changes: 5 additions & 6 deletions fusionMobile/src/navigation/tab-navigator.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import { ComponentType } from "react";
import type { SvgProps } from "react-native-svg";

import { AccountStack } from "./account-navigator";
import { HomeStack } from "./home-navigator";
import { InsightsStack } from "./insights-navigator";
import { PromptStack } from "./prompt-navigator";

Expand Down Expand Up @@ -54,11 +53,11 @@ export type TabList<T extends keyof TabParamList> = {
};

const tabs: TabType[] = [
{
name: "Home",
component: HomeStack,
label: "Home",
},
// {
// name: "Home",
// component: HomeStack,
// label: "Home",
// },
{
name: "PromptNavigator",
component: PromptStack,
Expand Down
169 changes: 4 additions & 165 deletions fusionMobile/src/pages/home.tsx
Original file line number Diff line number Diff line change
@@ -1,15 +1,7 @@
import { useNavigation } from "@react-navigation/native";
import dayjs from "dayjs";
import React from "react";
import { View, Text } from "react-native";
import { PanGestureHandler, State } from "react-native-gesture-handler";
import { View } from "react-native";

import { Button, ChevronLeft, ChevronRight, Screen } from "../components";

import { Prompt, PromptResponse } from "~/@types";
import { ChartContainer } from "~/components/charts/chart-container";
import { usePromptsQuery } from "~/hooks/usePrompts";
import { promptService } from "~/services";
import { appInsights } from "~/utils";

export function HomeScreen() {
Expand All @@ -22,91 +14,9 @@ export function HomeScreen() {
});
}, []);

const { data: savedPrompts, isLoading } = usePromptsQuery();

const [activeChartPrompt, setActiveChartPrompt] = React.useState<
Prompt | undefined
>();
const [activeChartPromptResponses, setActiveChartPromptResponses] =
React.useState<PromptResponse[]>([]);

const [chartStartDate, setChartStartDate] = React.useState<dayjs.Dayjs>(
dayjs().startOf("week")
);
React.useEffect(() => {
if (savedPrompts && savedPrompts.length > 0) {
setActiveChartPrompt(savedPrompts[0]);
}
// TODO: order the saved prompts by moving inactive prompts to the end
}, [isLoading]);

React.useEffect(() => {
if (activeChartPrompt) {
console.log("activeChartPrompt", activeChartPrompt);
(async () => {
const res = await promptService.getPromptResponses(
activeChartPrompt.uuid
);

// sort events
res.sort((a, b) => {
return a.triggerTimestamp - b.triggerTimestamp;
});

setActiveChartPromptResponses(res);
})();
}
}, [activeChartPrompt]);

const onHandlerStateChange = (event: {
nativeEvent: { state: number; translationX: number };
}) => {
if (
event.nativeEvent.state === State.END &&
event.nativeEvent.translationX < -50
) {
// Check if the swipe is left (translationX is less than -50)
if (
chartStartDate.startOf("week").unix() === dayjs().startOf("week").unix()
) {
return;
}
setChartStartDate(chartStartDate.add(1, "week"));
} else if (
event.nativeEvent.state === State.END &&
event.nativeEvent.translationX > 50
) {
// Check if the swipe is right (translationX is greater than 50)
setChartStartDate(chartStartDate.subtract(1, "week"));
}
};

const panActiveChartPrompt = (direction: "left" | "right") => {
if (savedPrompts && savedPrompts.length > 0) {
const currentIndex = savedPrompts.findIndex(
(prompt) => prompt.uuid === activeChartPrompt?.uuid
);

if (direction === "left") {
if (currentIndex === 0) {
setActiveChartPrompt(savedPrompts[savedPrompts.length - 1]);
} else {
setActiveChartPrompt(savedPrompts[currentIndex - 1]);
}
} else {
if (currentIndex === savedPrompts.length - 1) {
setActiveChartPrompt(savedPrompts[0]);
} else {
setActiveChartPrompt(savedPrompts[currentIndex + 1]);
}
}
}
};

return (
<Screen>
<View>
{/* <>
<View>
{/* <>
<View className="flex flex-row w-full justify-between p-5">
<Text className="text-base font-sans-bold text-white">
Your health data
Expand All @@ -121,77 +31,6 @@ export function HomeScreen() {
size="md"
/>
</> */}
<>
<View className="flex flex-row w-full justify-between p-5">
<Text className="text-base font-sans-bold text-white">
{chartStartDate.format("MMM D") +
" - " +
chartStartDate.add(1, "week").format("MMM D")}
</Text>

{chartStartDate < dayjs().startOf("week") ? (
<Text
className="text-base font-sans text-[#A7ED58]"
onPress={() => setChartStartDate(dayjs().startOf("week"))}
>
View current week
</Text>
) : (
<Text
className="text-base font-sans text-[#A7ED58]"
onPress={() => console.log("view all stats")}
>
View all stats
</Text>
)}
</View>
{/* select the first available prompt */}
{savedPrompts && savedPrompts.length > 0 && (
<View className="flex flex-col w-full bg-secondary-900">
<View className="flex flex-row w-full h-auto justify-between p-3 border-b-2 border-tint rounded-t">
{/* this is where the header of the chart is */}
<Button
variant="ghost"
size="icon"
leftIcon={<ChevronLeft />}
onPress={() => panActiveChartPrompt("left")}
/>

<Text className="font-sans text-base text-white text-[20px] ml-2 w-[80%] text-center">
{activeChartPrompt?.promptText}
</Text>

<Button
variant="ghost"
size="icon"
leftIcon={<ChevronRight />}
onPress={() => panActiveChartPrompt("right")}
/>
</View>

<PanGestureHandler onHandlerStateChange={onHandlerStateChange}>
<View>
{/* this is where the chart is */}
{activeChartPrompt && (
<ChartContainer
prompt={activeChartPrompt}
startDate={chartStartDate}
timePeriod="week"
/>
)}
</View>
</PanGestureHandler>
</View>
)}
</>

<Button
title="Use Fusion Copilot"
onPress={() => console.log("connect to apple health")}
className="w-full p-5 mt-10"
size="md"
/>
</View>
</Screen>
</View>
);
}
Loading

0 comments on commit d185777

Please sign in to comment.