{
data.map((city) => (
-
+
setSelectedLocation(city.name) }
+ >
{ city.name }
{ city.temp_c }°C
diff --git a/client/src/components/search-bar/result-list.tsx b/client/src/components/search-bar/result-list.tsx
index 04ef62c..af5d43a 100644
--- a/client/src/components/search-bar/result-list.tsx
+++ b/client/src/components/search-bar/result-list.tsx
@@ -3,7 +3,8 @@ import FavoriteButton from '@components/shared/favorite-button';
const ResultList: React.FC<{
searchQuery: string;
-}> = ({ searchQuery }) => {
+ setSelectedLocation: (loaction: string) => void;
+}> = ({ searchQuery, setSelectedLocation }) => {
const { data, isLoading } = trpc.searchLocations.useQuery(searchQuery);
if(isLoading) {
@@ -19,7 +20,10 @@ const ResultList: React.FC<{
{
data?.length ?
data.map((location) => (
-
console.error('Click')}>
+ setSelectedLocation(location.name) }
+ >
{ location.name }
diff --git a/client/src/components/search-bar/search-bar.tsx b/client/src/components/search-bar/search-bar.tsx
index ec78e15..c6efafc 100644
--- a/client/src/components/search-bar/search-bar.tsx
+++ b/client/src/components/search-bar/search-bar.tsx
@@ -2,7 +2,9 @@ import { useState } from 'react';
import ResultList from './result-list';
import { debounce } from '@utils/utility-functions';
-const SearchBar = () => {
+const SearchBar: React.FC<{
+ setSelectedLocation: (location: string) => void;
+}> = ({ setSelectedLocation }) => {
const [searchQuery, setSearchQuery] = useState('');
return (
@@ -16,7 +18,10 @@ const SearchBar = () => {
{
searchQuery && (
-
+
)
}
diff --git a/client/src/components/shared/weather-details.tsx b/client/src/components/shared/weather-details.tsx
new file mode 100644
index 0000000..e63a934
--- /dev/null
+++ b/client/src/components/shared/weather-details.tsx
@@ -0,0 +1,14 @@
+const WeatherDetails: React.FC<{
+ unit: string;
+ value: number | string;
+ icon: React.JSX.Element;
+}> = ({ unit, icon, value }) => {
+ return (
+
+ { icon }
+ { value + unit }
+
+ )
+}
+
+export default WeatherDetails;
diff --git a/client/src/components/weekly-forecast.tsx b/client/src/components/weekly-forecast.tsx
new file mode 100644
index 0000000..8ab8b7b
--- /dev/null
+++ b/client/src/components/weekly-forecast.tsx
@@ -0,0 +1,46 @@
+type Forecast = {
+ date: string;
+ icon_code: number;
+ max_temp_c: number;
+ min_temp_c: number;
+ condition: string;
+}[];
+
+const WeeklyForecast: React.FC<{
+ forecast: Forecast;
+}> = ({ forecast }) => {
+
+ return (
+
+
Forecast
+
+
+ {
+ forecast.map((day) => {
+ const formattedDate = new Date(day.date).toLocaleDateString('en-US', {
+ weekday: 'short',
+ month: 'short',
+ day: 'numeric',
+ });
+
+ return (
+ -
+
+
+
+ { Math.round(day.max_temp_c) }° / { Math.round(day.min_temp_c) }°
+
+
+
+ { formattedDate }
+
+
+ )
+ })
+ }
+
+
+ );
+};
+
+export default WeeklyForecast;
diff --git a/client/src/utils/tabs.ts b/client/src/utils/tabs.ts
index e9db9a4..b7a3531 100644
--- a/client/src/utils/tabs.ts
+++ b/client/src/utils/tabs.ts
@@ -8,7 +8,10 @@ export type Tab = {
id: string;
label: string;
icon: IconType;
- component: React.FC;
+ component: React.FC<{
+ selectedLocation: string;
+ setSelectedLocation: React.Dispatch
>
+ }>;
};
const tabs: Tab[] = [
diff --git a/client/src/utils/utility-functions.ts b/client/src/utils/utility-functions.ts
index 4a2a646..e63e448 100644
--- a/client/src/utils/utility-functions.ts
+++ b/client/src/utils/utility-functions.ts
@@ -11,3 +11,12 @@ export const debounce = any>(
timer = setTimeout(() => fn(...args), ms);
};
};
+
+export const getHours = (localtime: string) => {
+ const date = new Date(localtime);
+
+ const hours = date.getHours().toString().padStart(2, '0');
+ const minutes = date.getMinutes().toString().padStart(2, '0');
+
+ return `${ hours }:${ minutes }`;
+}
diff --git a/server/utils/fetchers/fetchers.ts b/server/utils/fetchers/fetchers.ts
index 278b83e..0c4b38b 100644
--- a/server/utils/fetchers/fetchers.ts
+++ b/server/utils/fetchers/fetchers.ts
@@ -30,6 +30,7 @@ export const fetchForecast = async (query: string) => {
lat: location.lat,
lng: location.lon,
name: location.name,
+ localtime: location.localtime,
},
current: {
uv: current.uv,