Skip to content

Commit

Permalink
chore: removed console logs
Browse files Browse the repository at this point in the history
  • Loading branch information
berenteb committed Mar 24, 2024
1 parent 2695e5d commit f688836
Show file tree
Hide file tree
Showing 7 changed files with 95 additions and 17 deletions.
13 changes: 10 additions & 3 deletions packages/admin/src/types/kiosk.types.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { ReactElement } from 'react';
import { TbAlignLeft, TbBike, TbBus, TbCup, TbPhoto, TbQrcode, TbSun } from 'react-icons/tb';
import { TbAlignLeft, TbBike, TbBus, TbCloudStorm, TbCup, TbPhoto, TbQrcode, TbSun } from 'react-icons/tb';

export type Kiosk = {
_id: string;
Expand Down Expand Up @@ -58,7 +58,7 @@ export type ColorModeColor = {
dark: string;
};

export type WidgetName = 'weather' | 'schpincer' | 'text' | 'image' | 'qr' | 'departures' | 'bike';
export type WidgetName = 'weather' | 'schpincer' | 'text' | 'image' | 'qr' | 'departures' | 'bike' | 'weathercam';

export const WidgetDisplay: Record<WidgetName, { name: string; icon: ReactElement }> = {
weather: { name: 'Időjárás', icon: TbSun({ size: 50 }) },
Expand All @@ -68,6 +68,7 @@ export const WidgetDisplay: Record<WidgetName, { name: string; icon: ReactElemen
qr: { name: 'QR Kód', icon: TbQrcode({ size: 50 }) },
departures: { name: 'Indulások', icon: TbBus({ size: 50 }) },
bike: { name: 'Bubi', icon: TbBike({ size: 50 }) },
weathercam: { name: 'Időjárás kamera', icon: TbCloudStorm({ size: 50 }) },
};

type WidgetConfigField = {
Expand All @@ -90,6 +91,7 @@ export const WidgetConfigFields: Record<WidgetName, WidgetConfigField[]> = {
{ name: 'title', type: 'text', label: 'Cím' },
{ name: 'subtitle', type: 'text', label: 'Alcím' },
],
weathercam: [],
};

export type WidgetConfigBase = {
Expand Down Expand Up @@ -133,6 +135,10 @@ export interface BikeConfig extends WidgetConfigBase {
name: 'bike';
}

export interface WeatherCamConfig extends WidgetConfigBase {
name: 'weathercam';
}

export type GridSettings = {
column: Axis;
row: Axis;
Expand All @@ -152,4 +158,5 @@ export type WidgetConfig =
| ImageConfig
| QRConfig
| DeparturesConfig
| BikeConfig;
| BikeConfig
| WeatherCamConfig;
9 changes: 7 additions & 2 deletions packages/backend/src/types/kiosk.types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,13 +53,17 @@ export type ColorModeColor = {
dark: string;
};

export type WidgetName = 'weather' | 'schpincer' | 'text' | 'image' | 'qr' | 'departures' | 'bike';
export type WidgetName = 'weather' | 'schpincer' | 'text' | 'image' | 'qr' | 'departures' | 'bike' | 'weathercam';

export type WidgetConfigBase = {
name: WidgetName;
grid: GridSettings;
};

export interface WeatherCamConfig extends WidgetConfigBase {
name: 'weathercam';
}

export interface WeatherConfig extends WidgetConfigBase {
name: 'weather';
apiKey: string;
Expand Down Expand Up @@ -113,7 +117,8 @@ export type WidgetConfig =
| ImageConfig
| QRConfig
| DeparturesConfig
| BikeConfig;
| BikeConfig
| WeatherCamConfig;

export enum KioskRoles {
VISITOR,
Expand Down
11 changes: 11 additions & 0 deletions packages/client/src/components/ImageContainer.tsx
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});
`;
11 changes: 1 addition & 10 deletions packages/client/src/components/widgets/ImageWidget.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
import React from 'react';
import styled from 'styled-components';

import { Widget } from '../../layout/Widget';
import { ImageConfig } from '../../types/widget.type';
import { GlobalSize, Size } from '../../utils/theme';
import { useWidgetConfig } from '../../utils/useWidgetConfig';
import { ImageContainer } from '../ImageContainer';

export function ImageWidget() {
const config = useWidgetConfig<ImageConfig>('image');
Expand All @@ -14,11 +13,3 @@ export function ImageWidget() {
</Widget>
);
}

const ImageContainer = styled.img`
height: 100%;
width: 100%;
object-fit: cover;
object-position: center;
border-radius: calc(${GlobalSize.borderRadius} - ${Size.xs});
`;
56 changes: 56 additions & 0 deletions packages/client/src/components/widgets/WeatherCamWidget.tsx
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;
`;
3 changes: 3 additions & 0 deletions packages/client/src/layout/WidgetDistributor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { ImageWidget } from '../components/widgets/ImageWidget';
import { QrWidget } from '../components/widgets/QrWidget';
import { SchPincerWidget } from '../components/widgets/SchPincerWidget';
import { TextWidget } from '../components/widgets/TextWidget';
import { WeatherCamWidget } from '../components/widgets/WeatherCamWidget';
import { WeatherWidget } from '../components/widgets/WeatherWidget';
import { WidgetConfig } from '../types/widget.type';

Expand All @@ -29,6 +30,8 @@ export function WidgetDistributor({ config }: WidgetDistributorProps) {
return <ImageWidget />;
case 'text':
return <TextWidget />;
case 'weathercam':
return <WeatherCamWidget />;
default:
return null;
}
Expand Down
9 changes: 7 additions & 2 deletions packages/client/src/types/widget.type.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export type WidgetName = 'weather' | 'schpincer' | 'text' | 'image' | 'qr' | 'departures' | 'bike';
export type WidgetName = 'weather' | 'schpincer' | 'text' | 'image' | 'qr' | 'departures' | 'bike' | 'weathercam';

export type WidgetConfigBase = {
name: WidgetName;
Expand Down Expand Up @@ -41,6 +41,10 @@ export interface BikeConfig extends WidgetConfigBase {
name: 'bike';
}

export interface WeatherCamConfig extends WidgetConfigBase {
name: 'weathercam';
}

export type GridSettings = {
column: Axis;
row: Axis;
Expand All @@ -58,4 +62,5 @@ export type WidgetConfig =
| ImageConfig
| QRConfig
| DeparturesConfig
| BikeConfig;
| BikeConfig
| WeatherCamConfig;

0 comments on commit f688836

Please sign in to comment.