Skip to content

Commit

Permalink
Add a greeting
Browse files Browse the repository at this point in the history
  • Loading branch information
michaeleii committed Dec 12, 2024
1 parent c90b619 commit 06c25d0
Showing 1 changed file with 19 additions and 1 deletion.
20 changes: 19 additions & 1 deletion app/(tabs)/habits.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,22 @@ type Challenge = NonNullable<
FunctionReturnType<typeof api.challenges.listCurrentUsersChallenges>
>[number];

function getTimeBasedGreeting(): string {
const currentHour = new Date().getHours();

let greeting = "Hello";

if (currentHour >= 5 && currentHour < 12) {
greeting = "Good Morning";
} else if (currentHour >= 12 && currentHour < 18) {
greeting = "Good Afternoon";
} else if (currentHour >= 18 || currentHour < 5) {
greeting = "Good Night";
}

return greeting;
}

export default function HabitsPage() {
useEffect(() => {
SplashScreen.hideAsync();
Expand All @@ -51,7 +67,9 @@ export default function HabitsPage() {
>
<View className="habit-container">
<DateHeading />
<Text className="ml-4 text-2xl font-bold">Habits</Text>
<Text className="ml-4 text-2xl font-bold">
{getTimeBasedGreeting()}
</Text>
<Separator className="mt-6 bg-[#fff]/10" />
<HabitList />
</View>
Expand Down

0 comments on commit 06c25d0

Please sign in to comment.