mirror of
https://github.com/ajnart/homarr.git
synced 2025-11-08 06:25:48 +01:00
🚧 Set up the structure for the weather module
This commit is contained in:
@@ -2,3 +2,4 @@ export * from './date';
|
|||||||
export * from './calendar';
|
export * from './calendar';
|
||||||
export * from './search';
|
export * from './search';
|
||||||
export * from './ping';
|
export * from './ping';
|
||||||
|
export * from './weather';
|
||||||
|
|||||||
41
src/components/modules/weather/WeatherModule.tsx
Normal file
41
src/components/modules/weather/WeatherModule.tsx
Normal file
@@ -0,0 +1,41 @@
|
|||||||
|
import { Group, Text, Title } from '@mantine/core';
|
||||||
|
import dayjs from 'dayjs';
|
||||||
|
import { useEffect, useState } from 'react';
|
||||||
|
import { Clock, Cloud } from 'tabler-icons-react';
|
||||||
|
import { IModule } from '../modules';
|
||||||
|
|
||||||
|
export const WeatherModule: IModule = {
|
||||||
|
title: 'Weather',
|
||||||
|
description: 'Look up the current weather in your location',
|
||||||
|
icon: Cloud,
|
||||||
|
component: WeatherComponent,
|
||||||
|
};
|
||||||
|
|
||||||
|
export default function WeatherComponent(props: any) {
|
||||||
|
const [date, setDate] = useState(new Date());
|
||||||
|
const hours = date.getHours();
|
||||||
|
const minutes = date.getMinutes();
|
||||||
|
|
||||||
|
// Change date on minute change
|
||||||
|
// Note: Using 10 000ms instead of 1000ms to chill a little :)
|
||||||
|
useEffect(() => {
|
||||||
|
setInterval(() => {
|
||||||
|
setDate(new Date());
|
||||||
|
}, 10000);
|
||||||
|
}, []);
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Group p="sm" direction="column">
|
||||||
|
<Title>
|
||||||
|
{hours < 10 ? `0${hours}` : hours}:{minutes < 10 ? `0${minutes}` : minutes}
|
||||||
|
</Title>
|
||||||
|
<Text size="xl">
|
||||||
|
{
|
||||||
|
// Use dayjs to format the date
|
||||||
|
// https://day.js.org/en/getting-started/installation/
|
||||||
|
dayjs(date).format('dddd, MMMM D')
|
||||||
|
}
|
||||||
|
</Text>
|
||||||
|
</Group>
|
||||||
|
);
|
||||||
|
}
|
||||||
1
src/components/modules/weather/index.ts
Normal file
1
src/components/modules/weather/index.ts
Normal file
@@ -0,0 +1 @@
|
|||||||
|
export { WeatherModule } from './WeatherModule';
|
||||||
Reference in New Issue
Block a user