Skip to content

Commit

Permalink
fix: Greeting in the home page
Browse files Browse the repository at this point in the history
  • Loading branch information
mortale2004 committed Sep 12, 2024
1 parent 08b4a2e commit b6430cb
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 12 deletions.
14 changes: 2 additions & 12 deletions src/app/(main)/(pages)/home/page.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { Greeting } from '@/components/Greeting';
import { MyCourses } from '@/components/MyCourses';
import { Redirect } from '@/components/Redirect';
import SearchBar from '@/components/search/SearchBar';
Expand All @@ -10,22 +11,11 @@ export default async function MyCoursesPage() {
return <Redirect to={'/'} />;
}

// Get the current hour
const currentHour = new Date().getHours();

// Determine the appropriate greeting based on the time of day
let greeting = 'Good Morning';
if (currentHour >= 12 && currentHour < 18) {
greeting = 'Good Afternoon';
} else if (currentHour >= 18 || currentHour < 5) {
greeting = 'Good Evening';
}

return (
<main className="flex flex-col gap-4 pb-16 pt-8">
<div className="flex flex-col justify-between gap-4 lg:flex-row">
<h1 className="text-wrap text-3xl font-extrabold capitalize tracking-tighter md:text-4xl">
{greeting} {session.user.name}
<Greeting /> {session.user.name}
</h1>
<SearchBar />
</div>
Expand Down
18 changes: 18 additions & 0 deletions src/components/Greeting.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
'use client';

export const Greeting = () => {
// Get the current hour
const currentHour = new Date().getHours();

// Determine the appropriate greeting based on the time of day
let greeting = 'Good Morning';
if (currentHour >= 12 && currentHour < 18) {
greeting = 'Good Afternoon';
} else if (currentHour >= 18 || currentHour < 5) {
greeting = 'Good Evening';
} else {
greeting = 'Surprise to see you here!';
}

return greeting;
};

0 comments on commit b6430cb

Please sign in to comment.