-
-
Notifications
You must be signed in to change notification settings - Fork 779
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: weather, notebooks table and node 20
This commit brings the following changes: - introduces the side box with weather data - introduces the notebooks table in home dashboard layout - upgrades nodejs to v20 - upgrades pnpm to 8.10.0
- Loading branch information
Showing
13 changed files
with
306 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
"use client"; | ||
|
||
import { Icon } from "@/components/icon"; | ||
import { | ||
Chip, | ||
Table, | ||
TableBody, | ||
TableCell, | ||
TableColumn, | ||
TableHeader, | ||
TableRow, | ||
} from "@nextui-org/react"; | ||
|
||
const fakeData = { | ||
name: "Introduction to Information Security", | ||
module: "CS759", | ||
lastEdited: "2 Hours ago", | ||
}; | ||
|
||
export const NotebookTable = () => { | ||
return ( | ||
<Table | ||
isHeaderSticky | ||
isVirtualized | ||
fullWidth | ||
removeWrapper | ||
aria-label="Example static collection table" | ||
> | ||
<TableHeader className="border-b border-default-200"> | ||
<TableColumn className="border-b border-default-200 bg-background dark:border-default-50"> | ||
Name | ||
</TableColumn> | ||
<TableColumn className="border-b border-default-200 bg-background dark:border-default-50"> | ||
Module | ||
</TableColumn> | ||
<TableColumn className="border-b border-default-200 bg-background dark:border-default-50"> | ||
Last edited | ||
</TableColumn> | ||
</TableHeader> | ||
<TableBody> | ||
{Array.from({ length: 20 }).map((_, i) => ( | ||
<TableRow key={i}> | ||
<TableCell className="flex items-center gap-3"> | ||
<Icon name="Lock" size={13} strokeWidth={2} /> {fakeData.name} | ||
</TableCell> | ||
<TableCell> | ||
<Chip color="success" size="sm"> | ||
{fakeData.module} | ||
</Chip> | ||
</TableCell> | ||
<TableCell>{fakeData.lastEdited}</TableCell> | ||
</TableRow> | ||
))} | ||
</TableBody> | ||
</Table> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
"use client"; | ||
|
||
import { type FC } from "react"; | ||
|
||
import { useCoords } from "@/hooks/useCoords"; | ||
import { trpc } from "@/trpc/client"; | ||
import { getFormattedWeatherDescription } from "@/utils/getFormattedWeatherDescription"; | ||
import { Skeleton } from "@nextui-org/react"; | ||
|
||
export const WeatherData: FC = () => { | ||
const coords = useCoords(); | ||
const { data: weatherData, isLoading } = trpc.weather.getWeatherData.useQuery( | ||
{ | ||
latitude: coords?.latitude ?? 0, | ||
longitude: coords?.longitude ?? 0, | ||
}, | ||
{ | ||
enabled: !!coords, | ||
retry: false, | ||
refetchOnMount: false, | ||
refetchOnWindowFocus: false, | ||
refetchOnReconnect: false, | ||
}, | ||
); | ||
|
||
if (isLoading) { | ||
return ( | ||
<div> | ||
<Skeleton className="mt-2 w-[258px] rounded-md"> | ||
<div className="h-4" /> | ||
</Skeleton> | ||
<Skeleton className="mt-2 w-3/4 rounded-md"> | ||
<div className="h-4" /> | ||
</Skeleton> | ||
</div> | ||
); | ||
} | ||
|
||
if (!weatherData) return null; | ||
|
||
return ( | ||
<span className="text-tiny text-default-500"> | ||
You can expect a 👆 high of {weatherData.main.temp_max.toFixed()}º and a | ||
👇 low of {weatherData.main.temp_min.toFixed()}º with{" "} | ||
{getFormattedWeatherDescription(weatherData.weather[0]?.description)}{" "} | ||
today. | ||
</span> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
'use client'; | ||
|
||
import { useEffect, useState } from 'react'; | ||
|
||
export const useCoords = () => { | ||
const [coords, setCoords] = useState<{ | ||
latitude: number; | ||
longitude: number; | ||
} | null>(null); | ||
|
||
useEffect(() => { | ||
navigator.geolocation.getCurrentPosition((position) => { | ||
setCoords(position.coords); | ||
}); | ||
}, []); | ||
|
||
return coords; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
import { TRPCError } from "@trpc/server"; | ||
import fetch from "node-fetch"; | ||
import { z } from "zod"; | ||
|
||
import { env } from "@/env.mjs"; | ||
|
||
import { createTRPCRouter, protectedProcedure } from "../trpc"; | ||
|
||
type WeatherData = { | ||
main: { | ||
temp_max: number; | ||
temp_min: number; | ||
}; | ||
weather: { | ||
description: string; | ||
}[]; | ||
}; | ||
|
||
export const weatherRouter = createTRPCRouter({ | ||
getWeatherData: protectedProcedure | ||
.input( | ||
z.object({ | ||
latitude: z.number(), | ||
longitude: z.number(), | ||
}), | ||
) | ||
.query(async ({ input }) => { | ||
const { latitude, longitude } = input; | ||
|
||
const response = await fetch( | ||
`https://api.openweathermap.org/data/2.5/weather?lat=${latitude}&lon=${longitude}&appid=${env.OPENWEATHER_API_KEY}&units=metric`, | ||
); | ||
|
||
if (!response.ok) { | ||
throw new TRPCError({ | ||
code: "INTERNAL_SERVER_ERROR", | ||
message: "Failed to fetch weather data", | ||
}); | ||
} | ||
|
||
return response.json() as Promise<WeatherData>; | ||
}), | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
export function formatDate(date: Date) { | ||
const daysOfWeek = [ | ||
"Sunday", | ||
"Monday", | ||
"Tuesday", | ||
"Wednesday", | ||
"Thursday", | ||
"Friday", | ||
"Saturday", | ||
]; | ||
const months = [ | ||
"January", | ||
"February", | ||
"March", | ||
"April", | ||
"May", | ||
"June", | ||
"July", | ||
"August", | ||
"September", | ||
"October", | ||
"November", | ||
"December", | ||
]; | ||
|
||
const day = date.getDate(); | ||
let daySuffix = "th"; | ||
|
||
if (day === 1 || day === 21 || day === 31) { | ||
daySuffix = "st"; | ||
} else if (day === 2 || day === 22) { | ||
daySuffix = "nd"; | ||
} else if (day === 3 || day === 23) { | ||
daySuffix = "rd"; | ||
} | ||
|
||
const dayOfWeek = daysOfWeek[date.getDay()]; | ||
const month = months[date.getMonth()]; | ||
const year = date.getFullYear(); | ||
|
||
return `${dayOfWeek}, ${day}${daySuffix} of ${month} ${year}`; | ||
} |
Oops, something went wrong.