Skip to content

Commit

Permalink
fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
stormyy00 committed Dec 22, 2024
1 parent 8d07a31 commit 3af5b83
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 27 deletions.
32 changes: 9 additions & 23 deletions src/components/calendar/Calendar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,42 +9,28 @@ import { Loader } from "lucide-react";

const CalendarCall = () => {
const [date, setDate] = useState<Date | undefined>(new Date());
const {
data: events,
isFetching,
isError,
error,
} = useQuery({
const { data: events, isFetching } = useQuery({
queryKey: ["calendarEvents"],
queryFn: fetchCalendarEvents,
staleTime: 1000 * 60 * 5,
retry: 1,
});
const proppedEvents: EventProps[] = events || [];

if (isFetching) {
return (
<div className="flex w-full items-center justify-center gap-4 bg-gradient-to-b from-sw-gold-100 via-sw-white to-sw-gold-200 bg-clip-text text-center text-sm font-semibold text-transparent md:text-3xl">
Currently fetching data from hyperpace{" "}
<span>
<Loader className="text-sw-white" />
</span>
</div>
);
}
if (isError) {
return (
<div className="bg-red-500 bg-gradient-to-b from-sw-gold-100 via-sw-white to-sw-gold-200 bg-clip-text p-4 text-center text-sm font-semibold text-transparent md:text-3xl">
Error: {error.message}
</div>
);
}
return (
<div className="flex w-full flex-col items-center">
<div className="flex w-fit items-center justify-center md:w-2/5">
<Header title="Event Calendar" />
</div>
<div className="relative w-screen overflow-clip">
{isFetching && (
<div className="flex w-full items-center justify-center gap-4 bg-gradient-to-b from-sw-gold-100 via-sw-white to-sw-gold-200 bg-clip-text text-center text-sm font-semibold text-transparent md:text-3xl">
Currently fetching data from hyperpace{" "}
<span>
<Loader className="text-sw-white" />
</span>
</div>
)}
<Calendar
mode="single"
selected={date}
Expand Down
9 changes: 9 additions & 0 deletions src/components/calendar/Event.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import logo2 from "@/public/eventsIcon/eventslogo2.svg";
import logo3 from "@/public/eventsIcon/eventslogo3.svg";
import Filter from "./Filter";
import { FILTERS } from "@/data/filters";
import { Loader } from "lucide-react";

type items = {
id: string;
Expand Down Expand Up @@ -47,6 +48,14 @@ const Events = () => {
return (
<div className="my-10 flex h-full w-full flex-col gap-5">
<Filter filters={FILTERS} onChange={handleFilterChange} />
{isFetching && (
<div className="flex w-full items-center justify-center gap-4 bg-gradient-to-b from-sw-gold-100 via-sw-white to-sw-gold-200 bg-clip-text text-center text-sm font-semibold text-transparent md:text-3xl">
Currently fetching data from hyperpace{" "}
<span>
<Loader className="text-sw-white" />
</span>
</div>
)}
<div className="flex w-full flex-wrap justify-center gap-10 md:gap-0">
{filteredEvents.length > 0 ? (
filteredEvents.slice(0, 6).map((element: items, index: number) => (
Expand Down
8 changes: 4 additions & 4 deletions src/data/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,6 @@ type GoogleCalendarEvent = {
};

export const fetchCalendarEvents = async (): Promise<EventProps[]> => {
if (!API_KEY || !CALENDAR_ID) {
throw new Error("Google Calendar API key or calendar ID is missing.");
}
const url = `https://www.googleapis.com/calendar/v3/calendars/${CALENDAR_ID}/events?key=${API_KEY}`;
const response = await fetch(url);

Expand Down Expand Up @@ -56,7 +53,10 @@ export const fetchEvents = async () => {
const max = new Date(
new Date().getTime() + 7 * 24 * 60 * 60 * 1000,
).toISOString();

if (!CALENDAR_ID || !API_KEY) {
console.warn("Missing Google Calendar API credentials.");
return { items: [] };
}
const response = await fetch(
`https://www.googleapis.com/calendar/v3/calendars/${process.env.NEXT_PUBLIC_GOOGLE_CALENDAR_EMAIL}/events?key=${process.env.NEXT_PUBLIC_GOOGLE_CALENDAR_API_KEY}&singleEvents=true&orderBy=startTime&timeMin=${min}&timeMax=${max}`,
);
Expand Down

0 comments on commit 3af5b83

Please sign in to comment.