-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
95 additions
and
17 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
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,11 @@ | ||
import styled from 'styled-components'; | ||
|
||
import { GlobalSize, Size } from '../utils/theme'; | ||
|
||
export const ImageContainer = styled.img` | ||
height: 100%; | ||
width: 100%; | ||
object-fit: cover; | ||
object-position: center; | ||
border-radius: calc(${GlobalSize.borderRadius} - ${Size.xs}); | ||
`; |
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
56 changes: 56 additions & 0 deletions
56
packages/client/src/components/widgets/WeatherCamWidget.tsx
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,56 @@ | ||
import React, { useEffect, useMemo, useState } from 'react'; | ||
import styled from 'styled-components'; | ||
|
||
import { Widget } from '../../layout/Widget'; | ||
import { WeatherCamConfig } from '../../types/widget.type'; | ||
import { useWidgetConfig } from '../../utils/useWidgetConfig'; | ||
import { ImageContainer } from '../ImageContainer'; | ||
|
||
const weatherImageSrc = 'https://ha5kfu.hu/idokep/kamera.php'; | ||
|
||
export function WeatherCamWidget() { | ||
const [camId, setCamId] = useState(1); | ||
const config = useWidgetConfig<WeatherCamConfig>('weathercam'); | ||
|
||
useEffect(() => { | ||
const interval = setInterval(() => { | ||
setCamId((prev) => (prev % 2) + 1); | ||
}, 5000); | ||
return () => clearInterval(interval); | ||
}, []); | ||
|
||
const src = useMemo(() => { | ||
const url = new URL(weatherImageSrc); | ||
url.searchParams.set('id', camId.toString()); | ||
url.searchParams.set('t', new Date().getTime().toString()); | ||
return url.toString(); | ||
}, [camId]); | ||
|
||
return ( | ||
<Widget grid={config.grid}> | ||
<ContentContainer> | ||
<ImageContainer src={src} alt='Nem sikerült betölteni az időjárás kamera képet' /> | ||
<SponsorText>Forrás: HA5KFU</SponsorText> | ||
</ContentContainer> | ||
</Widget> | ||
); | ||
} | ||
|
||
const ContentContainer = styled.div` | ||
height: 100%; | ||
width: 100%; | ||
position: relative; | ||
overflow: hidden; | ||
`; | ||
|
||
const SponsorText = styled.p` | ||
background-color: rgba(0, 0, 0, 0.5); | ||
color: white; | ||
border-top-left-radius: 10px; | ||
border-bottom-right-radius: 10px; | ||
padding: 5px; | ||
position: absolute; | ||
bottom: 0; | ||
right: 0; | ||
margin: 0; | ||
`; |
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