Skip to content

Commit

Permalink
Setup placeholders with queries
Browse files Browse the repository at this point in the history
  • Loading branch information
timmo001 committed Sep 2, 2024
1 parent 2167978 commit 212a057
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 7 deletions.
22 changes: 17 additions & 5 deletions src/app/_components/forecast-hourly.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,31 @@ import { CloudSun } from "lucide-react";

import { getLocationFromLocalStorage } from "~/lib/localStorage";

const forecast12Hour = [
22.1, 21.9, 21.6, 21.4, 21.2, 21.1, 21.0, 20.9, 20.8, 20.7, 20.6, 20.5,
];

export function ForecastHourly() {
const location = useQuery({
queryKey: ["location"],
queryFn: getLocationFromLocalStorage,
});

const forecast = useQuery({
queryKey: ["forecast", location.data],
queryFn: async () => {
return [
22.1, 21.9, 21.6, 21.4, 21.2, 21.1, 21.0, 20.9, 20.8, 20.7, 20.6, 20.5,
];
},
});

if (location.isLoading) return <span>Loading location...</span>;
if (location.isError) return <span>Error loading location...</span>;
if (forecast.isLoading) return <span>Loading forecast...</span>;
if (forecast.isError) return <span>Error loading forecast...</span>;
if (!forecast.data || !Array.isArray(forecast.data))
return <span>No forecast data.</span>;

return (
<div className="flex max-w-screen-md select-none flex-row gap-4 overflow-y-auto">
{forecast12Hour.map((temp, index) => (
{forecast.data.map((temp, index) => (
<div key={index} className="flex flex-col items-stretch gap-1">
<div className="flex flex-row items-center gap-1">
<CloudSun className="h-16 w-16" />
Expand Down
15 changes: 14 additions & 1 deletion src/app/_components/forecast-now.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,26 @@ export function ForecastNow() {
queryFn: getLocationFromLocalStorage,
});

const forecast = useQuery({
queryKey: ["forecast", location.data],
queryFn: async () => {
return { temp: 22.2 };
},
});

if (location.isLoading) return <span>Loading location...</span>;
if (location.isError) return <span>Error loading location...</span>;
if (forecast.isLoading) return <span>Loading forecast...</span>;
if (forecast.isError) return <span>Error loading forecast...</span>;
if (!forecast.data) return <span>No forecast data.</span>;

return (
<div className="flex select-none flex-row items-stretch gap-6">
<div className="flex flex-row items-center gap-1">
<CloudSun className="h-24 w-24" />
</div>
<div className="flex flex-row items-center gap-1">
<span className="text-4xl font-bold">22.2</span>
<span className="text-4xl font-bold">{forecast.data.temp}</span>
<span className="text-2xl font-semibold">°C</span>
</div>
</div>
Expand Down
2 changes: 1 addition & 1 deletion src/app/_components/location-form.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ export function LocationForm() {
}

if (form.formState.isLoading) {
return <span>Loading...</span>;
return <span>Loading location...</span>;
}

return (
Expand Down

0 comments on commit 212a057

Please sign in to comment.