Fixed for mobile?
All checks were successful
Docker Build & Publish / Build Docker (push) Successful in 1m9s
All checks were successful
Docker Build & Publish / Build Docker (push) Successful in 1m9s
This commit is contained in:
parent
fb27c8b367
commit
83b337db03
@ -17,7 +17,7 @@ export default function Home() {
|
|||||||
|
|
||||||
return (
|
return (
|
||||||
<main>
|
<main>
|
||||||
<div className='mx-auto max-w-3xl text-center'>
|
<div className='mx-auto max-w-xs sm:max-w-md md:max-w-xl text-center'>
|
||||||
<LocationContext.Provider value={contextValue}>
|
<LocationContext.Provider value={contextValue}>
|
||||||
<LocationSearch />
|
<LocationSearch />
|
||||||
<WeatherNow />
|
<WeatherNow />
|
||||||
|
20
components/DailyCard/CardContainer.tsx
Normal file
20
components/DailyCard/CardContainer.tsx
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
import { Forecast } from "@/types/types";
|
||||||
|
import DailyCard from "./DailyCard";
|
||||||
|
|
||||||
|
export default function CardContainer(props: {weather: Forecast}) {
|
||||||
|
const weather = props.weather;
|
||||||
|
return (
|
||||||
|
<div className="flex overflow-scroll justify-center">
|
||||||
|
{weather.daily && weather.daily.apparent_temperature_max.map((temp, index) => (
|
||||||
|
index > 0 &&
|
||||||
|
index < 7 && // Ensure we only render the next 6 days
|
||||||
|
<DailyCard
|
||||||
|
key={index}
|
||||||
|
temperature={temp}
|
||||||
|
weatherCode={weather.daily.weather_code[index]}
|
||||||
|
time={weather.daily.time[index]}
|
||||||
|
/>
|
||||||
|
))}
|
||||||
|
</div>
|
||||||
|
)
|
||||||
|
};
|
@ -8,7 +8,7 @@ export default function DailyCard(props: DailyCardPropType) {
|
|||||||
const weatherCode = props.weatherCode
|
const weatherCode = props.weatherCode
|
||||||
const temperature = props.temperature
|
const temperature = props.temperature
|
||||||
return (
|
return (
|
||||||
<div className="m-2 text-center shadow-md border-slate-200 border-2 rounded">
|
<div className="m-1 p-2 text-center shadow-md border-slate-200 border-2 rounded">
|
||||||
<WeatherIcon weatherCode={weatherCode}/>
|
<WeatherIcon weatherCode={weatherCode}/>
|
||||||
<DailyTemp temperature={temperature} />
|
<DailyTemp temperature={temperature} />
|
||||||
<DailyTime time={time} />
|
<DailyTime time={time} />
|
||||||
|
@ -2,6 +2,6 @@
|
|||||||
export default function DailyTemp(props: {temperature: number;}) {
|
export default function DailyTemp(props: {temperature: number;}) {
|
||||||
const feels = props.temperature;
|
const feels = props.temperature;
|
||||||
return (
|
return (
|
||||||
<p className="my-2">{feels}°C</p>
|
<p className="">{feels}°C</p>
|
||||||
)
|
)
|
||||||
}
|
}
|
@ -1,7 +1,9 @@
|
|||||||
import { headers } from "next/headers";
|
import weekday from "@/utils/functions/weekday"
|
||||||
|
|
||||||
|
|
||||||
export default function DailyTime(props: {time: string}) {
|
export default function DailyTime(props: {time: string}) {
|
||||||
|
const day = weekday(props.time);
|
||||||
return(
|
return(
|
||||||
<p>{props.time}</p>
|
<p className="text-sm">{day}</p>
|
||||||
)
|
)
|
||||||
}
|
}
|
@ -7,6 +7,6 @@ export default function Temperature() {
|
|||||||
const { weather } = useContext(WeatherContext)
|
const { weather } = useContext(WeatherContext)
|
||||||
const feels = weather.current.apparent_temperature;
|
const feels = weather.current.apparent_temperature;
|
||||||
return (
|
return (
|
||||||
<p>{feels}°C</p>
|
<p className="text-2xl mt-2">{feels}°C</p>
|
||||||
)
|
)
|
||||||
}
|
}
|
@ -85,7 +85,7 @@ export default function WeatherHero() {
|
|||||||
const weatherCode = weather.current.weather_code;
|
const weatherCode = weather.current.weather_code;
|
||||||
return(
|
return(
|
||||||
<>
|
<>
|
||||||
<Image className="h-64 mx-auto" src={getCurrentWeatherIcon(weatherCode)} alt="Weather icon"/>
|
<Image className="h-64 w-auto mx-auto" src={getCurrentWeatherIcon(weatherCode)} alt="Weather icon"/>
|
||||||
</>
|
</>
|
||||||
)
|
)
|
||||||
};
|
};
|
@ -81,8 +81,8 @@ function getCurrentWeatherIcon(weatherCode: number) {
|
|||||||
export default function WeatherIcon(props: {weatherCode: number}) {
|
export default function WeatherIcon(props: {weatherCode: number}) {
|
||||||
const weatherCode = props.weatherCode
|
const weatherCode = props.weatherCode
|
||||||
return (
|
return (
|
||||||
<div className="p-2 h-16">
|
<div className="h-12">
|
||||||
<Image className="h-12" src={getCurrentWeatherIcon(weatherCode)} alt="Weather icon"/>
|
<Image className="mt-2 max-h-12 mx-auto w-auto" src={getCurrentWeatherIcon(weatherCode)} alt="Weather icon"/>
|
||||||
</div>
|
</div>
|
||||||
)
|
)
|
||||||
};
|
};
|
@ -8,6 +8,7 @@ import { defaultHourlyForecast } from "@/app/defaultState";
|
|||||||
import { LocationContext } from "@/context/LocationContext";
|
import { LocationContext } from "@/context/LocationContext";
|
||||||
import WeatherHero from "./WeatherHero";
|
import WeatherHero from "./WeatherHero";
|
||||||
import DailyCard from "./DailyCard/DailyCard";
|
import DailyCard from "./DailyCard/DailyCard";
|
||||||
|
import CardContainer from "./DailyCard/CardContainer";
|
||||||
|
|
||||||
export const WeatherContext = createContext<WeatherContextType>({
|
export const WeatherContext = createContext<WeatherContextType>({
|
||||||
weather: defaultHourlyForecast,
|
weather: defaultHourlyForecast,
|
||||||
@ -42,19 +43,8 @@ export default function WeatherNow() {
|
|||||||
<WeatherContext.Provider value={contextValue}>
|
<WeatherContext.Provider value={contextValue}>
|
||||||
<WeatherHero />
|
<WeatherHero />
|
||||||
<Temperature />
|
<Temperature />
|
||||||
<h2 className="mt-4 text-xl">And the forecast for the coming week</h2>
|
<h2 className="mt-2 text-xl">And the forecast for the coming week</h2>
|
||||||
<div className="flex h-full">
|
<CardContainer weather={weather}/>
|
||||||
{weather.daily && weather.daily.apparent_temperature_max.map((temp, index) => (
|
|
||||||
index > 0 &&
|
|
||||||
index < 7 && // Ensure we only render the next 6 days
|
|
||||||
<DailyCard
|
|
||||||
key={index}
|
|
||||||
temperature={temp}
|
|
||||||
weatherCode={weather.daily.weather_code[index]}
|
|
||||||
time={weather.daily.time[index]}
|
|
||||||
/>
|
|
||||||
))}
|
|
||||||
</div>
|
|
||||||
</WeatherContext.Provider>
|
</WeatherContext.Provider>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
|
6
utils/functions/weekday.ts
Normal file
6
utils/functions/weekday.ts
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
export default function weekday(date: string): string {
|
||||||
|
const newDate = new Date(date);
|
||||||
|
const dayNumber = newDate.getDay();
|
||||||
|
const weekdays = ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday'];
|
||||||
|
return weekdays[dayNumber]; // Directly return the weekday string
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user