Compare commits
2 Commits
a0fb254846
...
9e872ea8d9
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
9e872ea8d9 | ||
|
|
4013ae24b2 |
271
dist/assets/index-Bvsyeuyp.js
vendored
271
dist/assets/index-Bvsyeuyp.js
vendored
File diff suppressed because one or more lines are too long
383
dist/assets/index-ByYsxaaM.js
vendored
Normal file
383
dist/assets/index-ByYsxaaM.js
vendored
Normal file
File diff suppressed because one or more lines are too long
@@ -1 +1 @@
|
|||||||
:root{font-family:system-ui,Avenir,Helvetica,Arial,sans-serif;line-height:1.5;font-weight:400;color-scheme:light dark;color:#ffffffde;background-color:#242424;font-synthesis:none;text-rendering:optimizeLegibility;-webkit-font-smoothing:antialiased;-moz-osx-font-smoothing:grayscale}a{font-weight:500;color:#646cff;text-decoration:inherit}a:hover{color:#535bf2}body{margin:0;display:flex;place-items:center;min-width:320px;min-height:100vh}h1{font-size:3.2em;line-height:1.1}button{border-radius:8px;border:1px solid transparent;padding:.6em 1.2em;font-size:1em;font-weight:500;font-family:inherit;background-color:#1a1a1a;cursor:pointer;transition:border-color .25s}button:hover{border-color:#646cff}button:focus,button:focus-visible{outline:4px auto -webkit-focus-ring-color}@media(prefers-color-scheme:light){:root{color:#213547;background-color:#fff}a:hover{color:#747bff}button{background-color:#f9f9f9}}#root{max-width:1280px;margin:0 auto;padding:2rem;text-align:center}.logo{height:6em;padding:1.5em;will-change:filter;transition:filter .3s}.logo:hover{filter:drop-shadow(0 0 2em #646cffaa)}.logo.react:hover{filter:drop-shadow(0 0 2em #61dafbaa)}@keyframes logo-spin{0%{transform:rotate(0)}to{transform:rotate(360deg)}}@media(prefers-reduced-motion:no-preference){a:nth-of-type(2) .logo{animation:logo-spin infinite 20s linear}}.card{padding:2em}.read-the-docs{color:#888}
|
:root{font-family:system-ui,Avenir,Helvetica,Arial,sans-serif;line-height:1.5;font-weight:400;color-scheme:light dark;color:#ffffffde;background-color:#242424;font-synthesis:none;text-rendering:optimizeLegibility;-webkit-font-smoothing:antialiased;-moz-osx-font-smoothing:grayscale}a{font-weight:500;color:#646cff;text-decoration:inherit}a:hover{color:#535bf2}body{margin:0;display:flex;place-items:center;min-width:320px;min-height:100vh}h1{font-size:3.2em;line-height:1.1}button{border-radius:8px;border:1px solid transparent;padding:.6em 1.2em;font-size:1em;font-weight:500;font-family:inherit;background-color:#1a1a1a;cursor:pointer;transition:border-color .25s}button:hover{border-color:#646cff}button:focus,button:focus-visible{outline:4px auto -webkit-focus-ring-color}@media(prefers-color-scheme:light){:root{color:#213547;background-color:#fff}a:hover{color:#747bff}button{background-color:#f9f9f9}}#root{max-width:1280px;margin:0 auto;padding:2rem;text-align:center}import "@react-ui-org/react-ui/dist/react-ui.css";{}
|
||||||
4
dist/index.html
vendored
4
dist/index.html
vendored
@@ -5,8 +5,8 @@
|
|||||||
<link rel="icon" type="image/svg+xml" href="/vite.svg" />
|
<link rel="icon" type="image/svg+xml" href="/vite.svg" />
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||||
<title>trainhour</title>
|
<title>trainhour</title>
|
||||||
<script type="module" crossorigin src="/assets/index-Bvsyeuyp.js"></script>
|
<script type="module" crossorigin src="/assets/index-ByYsxaaM.js"></script>
|
||||||
<link rel="stylesheet" crossorigin href="/assets/index-COcDBgFa.css">
|
<link rel="stylesheet" crossorigin href="/assets/index-DeyVbdfU.css">
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<div id="root"></div>
|
<div id="root"></div>
|
||||||
|
|||||||
@@ -10,6 +10,7 @@
|
|||||||
"preview": "vite preview"
|
"preview": "vite preview"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
|
"@chakra-ui/react": "^3.28.0",
|
||||||
"@types/lodash": "^4.17.20",
|
"@types/lodash": "^4.17.20",
|
||||||
"axios": "^1.13.1",
|
"axios": "^1.13.1",
|
||||||
"lodash": "^4.17.21",
|
"lodash": "^4.17.21",
|
||||||
|
|||||||
1159
pnpm-lock.yaml
generated
1159
pnpm-lock.yaml
generated
File diff suppressed because it is too large
Load Diff
33
src/App.css
33
src/App.css
@@ -5,38 +5,5 @@
|
|||||||
text-align: center;
|
text-align: center;
|
||||||
}
|
}
|
||||||
|
|
||||||
.logo {
|
|
||||||
height: 6em;
|
|
||||||
padding: 1.5em;
|
|
||||||
will-change: filter;
|
|
||||||
transition: filter 300ms;
|
|
||||||
}
|
|
||||||
.logo:hover {
|
|
||||||
filter: drop-shadow(0 0 2em #646cffaa);
|
|
||||||
}
|
|
||||||
.logo.react:hover {
|
|
||||||
filter: drop-shadow(0 0 2em #61dafbaa);
|
|
||||||
}
|
|
||||||
|
|
||||||
@keyframes logo-spin {
|
|
||||||
from {
|
|
||||||
transform: rotate(0deg);
|
|
||||||
}
|
|
||||||
to {
|
|
||||||
transform: rotate(360deg);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@media (prefers-reduced-motion: no-preference) {
|
|
||||||
a:nth-of-type(2) .logo {
|
|
||||||
animation: logo-spin infinite 20s linear;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
.card {
|
|
||||||
padding: 2em;
|
|
||||||
}
|
|
||||||
|
|
||||||
.read-the-docs {
|
|
||||||
color: #888;
|
|
||||||
}
|
|
||||||
|
|||||||
59
src/App.tsx
59
src/App.tsx
@@ -1,13 +1,19 @@
|
|||||||
import { useReducer } from 'react'
|
import { useReducer, useState } from 'react'
|
||||||
|
|
||||||
import { useLoadTrainSchedule } from './hooks/useLoadTrainSchedule'
|
import { useLoadTrainSchedule } from './hooks/useLoadTrainSchedule'
|
||||||
|
|
||||||
import { initialState, reducer } from './state'
|
import { actions, initialState, reducer } from './state'
|
||||||
|
|
||||||
import './App.css'
|
import './App.css'
|
||||||
import { NewsWidget, TrainSchedule, WeatherWidget } from './containers';
|
import { NewsWidget, TrainSchedule, WeatherWidget } from './containers';
|
||||||
import {useNewsApi, useWeatherApi} from './hooks';
|
import {useGiteaApi, useNewsApi, useWeatherApi} from './hooks';
|
||||||
import styled from 'styled-components';
|
import styled from 'styled-components';
|
||||||
|
import {IssueWidget} from './containers/IssuesWidget';
|
||||||
|
import {IoSettingsSharp} from 'react-icons/io5';
|
||||||
|
import type {Station} from './types';
|
||||||
|
//import {NativeSelectRoot} from '@chakra-ui/react';
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
const Container = styled.div`
|
const Container = styled.div`
|
||||||
display: flex;
|
display: flex;
|
||||||
@@ -23,25 +29,54 @@ const Pane = styled.div`
|
|||||||
|
|
||||||
function App() {
|
function App() {
|
||||||
|
|
||||||
const [state, dispatch] = useReducer( reducer, initialState,);
|
const [state, dispatch] = useReducer( reducer, initialState, );
|
||||||
|
const [settingOpened, setSettingOpened] = useState(false);
|
||||||
|
|
||||||
useLoadTrainSchedule(state, dispatch);
|
|
||||||
useNewsApi({state, dispatch});
|
|
||||||
useWeatherApi({state, dispatch});
|
|
||||||
|
|
||||||
return (
|
const { reloadTrainSchedule } = useLoadTrainSchedule(state, dispatch);
|
||||||
<Container>
|
const { reloadNews } = useNewsApi({state, dispatch});
|
||||||
|
const { reloadWeather } = useWeatherApi({state, dispatch});
|
||||||
|
const { reloadIssues } = useGiteaApi({state, dispatch})
|
||||||
|
|
||||||
|
const { selectedLocation } = state;
|
||||||
|
const setSelectedLocation = (location: string) => {
|
||||||
|
dispatch(actions.setSelectedLocation({ location }))
|
||||||
|
reloadNews();
|
||||||
|
reloadWeather();
|
||||||
|
reloadIssues();
|
||||||
|
reloadTrainSchedule();
|
||||||
|
}
|
||||||
|
|
||||||
|
const mainContent = <>
|
||||||
<Pane>
|
<Pane>
|
||||||
<h1>Next trains</h1>
|
<h2>Next trains in {state.selectedLocation}</h2>
|
||||||
<TrainSchedule {...{ state, dispatch }} />
|
<TrainSchedule {...{ state, dispatch }} />
|
||||||
</Pane>
|
</Pane>
|
||||||
<Pane>
|
<Pane>
|
||||||
<h1>Weather</h1>
|
<h2>Weather</h2>
|
||||||
<WeatherWidget {...{ state, dispatch }} />
|
<WeatherWidget {...{ state, dispatch }} />
|
||||||
<h1>News</h1>
|
<h2>Issues</h2>
|
||||||
|
<IssueWidget {...{ state, dispatch }} />
|
||||||
|
<h2>News</h2>
|
||||||
<NewsWidget {...{ state, dispatch }} />
|
<NewsWidget {...{ state, dispatch }} />
|
||||||
</Pane>
|
</Pane>
|
||||||
|
</>
|
||||||
|
|
||||||
|
const settingContent = <>
|
||||||
|
<Pane>
|
||||||
|
<select value={selectedLocation} onChange={e => setSelectedLocation(e.target.value)}>
|
||||||
|
{state.stations?.map((option: Station) => <option value={option.name}>{option.name}</option>)}
|
||||||
|
</select>
|
||||||
|
</Pane>
|
||||||
|
</>
|
||||||
|
|
||||||
|
return (
|
||||||
|
<>
|
||||||
|
<Container>
|
||||||
|
<div onClick={() => setSettingOpened(!settingOpened)}><IoSettingsSharp size={40}/></div>
|
||||||
|
{settingOpened ? settingContent: mainContent}
|
||||||
</Container>
|
</Container>
|
||||||
|
</>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -31,8 +31,8 @@ export const InfoStyled = styled.div`
|
|||||||
`;
|
`;
|
||||||
|
|
||||||
export const DestinationStyled = styled.div`
|
export const DestinationStyled = styled.div`
|
||||||
font-size: 1.2rem;
|
font-size: 1rem;
|
||||||
font-weight: 600;
|
font-weight: 400;
|
||||||
`;
|
`;
|
||||||
|
|
||||||
export const DelayStyled = styled.div`
|
export const DelayStyled = styled.div`
|
||||||
|
|||||||
26
src/components/Issue.tsx
Normal file
26
src/components/Issue.tsx
Normal file
@@ -0,0 +1,26 @@
|
|||||||
|
import type { IssueType } from "../types/issues"
|
||||||
|
|
||||||
|
import styled from 'styled-components';
|
||||||
|
import {TitleLink} from "./NewsArticle";
|
||||||
|
|
||||||
|
|
||||||
|
export const IssueHeader = styled.div`
|
||||||
|
display: flex;
|
||||||
|
justify-content: space-between;
|
||||||
|
align-items: flex-start;
|
||||||
|
margin-bottom: 0.75rem;
|
||||||
|
`;
|
||||||
|
|
||||||
|
|
||||||
|
export const Issue = ({ issue }: { issue: IssueType }) => {
|
||||||
|
return (
|
||||||
|
<IssueHeader>
|
||||||
|
<a href={`https://git.boomjacky.art/boomjacky/trainhour/issues/${issue.id}`}>
|
||||||
|
<TitleLink>
|
||||||
|
{issue.title}
|
||||||
|
|
||||||
|
</TitleLink>
|
||||||
|
</a>
|
||||||
|
</IssueHeader>
|
||||||
|
);
|
||||||
|
};
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
import React from "react";
|
import React from "react";
|
||||||
import styled from "styled-components";
|
import styled from "styled-components";
|
||||||
import {accentColor} from "../styles";
|
import { accentColor } from "../styles";
|
||||||
|
|
||||||
|
|
||||||
const Container = styled.div`
|
const Container = styled.div`
|
||||||
@@ -12,8 +12,8 @@ const Container = styled.div`
|
|||||||
`;
|
`;
|
||||||
|
|
||||||
const Dot = styled.button<{ $active: boolean }>`
|
const Dot = styled.button<{ $active: boolean }>`
|
||||||
width: 12px;
|
width: 20px;
|
||||||
height: 12px;
|
height: 20px;
|
||||||
padding: 0;
|
padding: 0;
|
||||||
margin: 0;
|
margin: 0;
|
||||||
border: none;
|
border: none;
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
export * from './Departure';
|
export * from './Departure';
|
||||||
export * from './NewsArticle';
|
export * from './NewsArticle';
|
||||||
export * from './NowTime';
|
export * from './NowTime';
|
||||||
|
export * from './Issue';
|
||||||
|
|||||||
39
src/containers/IssuesWidget.tsx
Normal file
39
src/containers/IssuesWidget.tsx
Normal file
@@ -0,0 +1,39 @@
|
|||||||
|
import type { Dispatch } from "react"
|
||||||
|
import styled from "styled-components";
|
||||||
|
import { SpinnerDiamond } from "spinners-react";
|
||||||
|
|
||||||
|
import type { Action, State } from "../state"
|
||||||
|
import { Issue } from "../components";
|
||||||
|
|
||||||
|
export const IssueContainer = styled.div`
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
justify-content: space-between;
|
||||||
|
align-items: stretch;
|
||||||
|
background: #0b0c10;
|
||||||
|
color: #fff;
|
||||||
|
padding: 1rem 1.5rem;
|
||||||
|
border-radius: 12px;
|
||||||
|
box-shadow: 0 6px 20px rgba(0, 0, 0, 0.4);
|
||||||
|
font-family: "Inter", sans-serif;
|
||||||
|
max-width: 600px;
|
||||||
|
margin: 1rem auto;
|
||||||
|
`;
|
||||||
|
|
||||||
|
|
||||||
|
type IssueDispatchProps = {
|
||||||
|
state: State;
|
||||||
|
dispatch: Dispatch<Action>;
|
||||||
|
};
|
||||||
|
|
||||||
|
export const IssueWidget = ({ state }: IssueDispatchProps) => {
|
||||||
|
return state.issuesLoading
|
||||||
|
? <SpinnerDiamond />
|
||||||
|
: state.issuesError
|
||||||
|
? <em>{state.issuesError?.message}</em>
|
||||||
|
: (
|
||||||
|
<IssueContainer>
|
||||||
|
{state.issues?.slice(0,3)?.map(issue => <Issue issue={issue} />)}
|
||||||
|
</IssueContainer>
|
||||||
|
);
|
||||||
|
};
|
||||||
@@ -1,3 +1,4 @@
|
|||||||
export * from './useLoadTrainSchedule';
|
export * from './useLoadTrainSchedule';
|
||||||
export * from './useNewsApi';
|
export * from './useNewsApi';
|
||||||
export * from './useWeatherApi';
|
export * from './useWeatherApi';
|
||||||
|
export * from './useGiteaApi';
|
||||||
|
|||||||
31
src/hooks/useGiteaApi.tsx
Normal file
31
src/hooks/useGiteaApi.tsx
Normal file
@@ -0,0 +1,31 @@
|
|||||||
|
import { useEffect, type Dispatch } from "react";
|
||||||
|
import { actions, type Action, type State } from "../state";
|
||||||
|
import type {IssuesResponse} from "../types/issues";
|
||||||
|
|
||||||
|
const apiKey = 'a70bbe6b9f70747278ba3ec7a701b2b279be2efc';
|
||||||
|
|
||||||
|
export const useGiteaApi = ({ dispatch }: { state : State, dispatch: Dispatch<Action> }) => {
|
||||||
|
const reloadIssues = (async () => {
|
||||||
|
try {
|
||||||
|
dispatch(actions.loadGiteaIssue({}));
|
||||||
|
const answer = await fetch(`https://git.boomjacky.art/api/v1/repos/boomjacky/trainhour/issues?state=all`, {
|
||||||
|
method: "GET",
|
||||||
|
headers: {
|
||||||
|
"Authorization": `token ${apiKey}`,
|
||||||
|
"Accept": "application/json"
|
||||||
|
}
|
||||||
|
})
|
||||||
|
const data = await answer.json() as IssuesResponse;
|
||||||
|
dispatch(actions.loadGiteaIssueSuccess({ data }));
|
||||||
|
} catch(error) {
|
||||||
|
dispatch(actions.loadGiteaIssueError({ error: error as Error }));
|
||||||
|
}
|
||||||
|
|
||||||
|
})
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
reloadIssues();
|
||||||
|
}, [])
|
||||||
|
|
||||||
|
return { reloadIssues }
|
||||||
|
}
|
||||||
@@ -4,13 +4,13 @@ import { flatten, range } from 'lodash';
|
|||||||
|
|
||||||
import axios from 'axios';
|
import axios from 'axios';
|
||||||
import type { LiveBoard } from "../types/liveboard";
|
import type { LiveBoard } from "../types/liveboard";
|
||||||
|
import type {StationsRoot} from "../types/station";
|
||||||
|
|
||||||
const irailApiUrl = 'https://api.irail.be';
|
const irailApiUrl = 'https://api.irail.be';
|
||||||
const lookahead = 3;
|
const lookahead = 3;
|
||||||
|
|
||||||
export const useLoadTrainSchedule = (_: State, dispatch: Dispatch<Action>) => {
|
export const useLoadTrainSchedule = (state: State, dispatch: Dispatch<Action>) => {
|
||||||
useEffect(() => {
|
const reloadTrainSchedule = (async () => {
|
||||||
(async () => {
|
|
||||||
try {
|
try {
|
||||||
dispatch(actions.loadTrainSchedule({}))
|
dispatch(actions.loadTrainSchedule({}))
|
||||||
const now = new Date();
|
const now = new Date();
|
||||||
@@ -29,19 +29,23 @@ export const useLoadTrainSchedule = (_: State, dispatch: Dispatch<Action>) => {
|
|||||||
const minutes = pad(now.getMinutes());
|
const minutes = pad(now.getMinutes());
|
||||||
const time = `${hours}${minutes}`
|
const time = `${hours}${minutes}`
|
||||||
|
|
||||||
const answer = await axios.get(`${irailApiUrl}/liveboard?station=Nivelles&date=${date}&time=${time}&format=json&lang=en&alerts=true`)
|
const answer = await axios.get(`${irailApiUrl}/liveboard?station=${state.selectedLocation}&date=${date}&time=${time}&format=json&lang=en&alerts=true`)
|
||||||
|
|
||||||
const liveboard = answer.data as LiveBoard;
|
const liveboard = answer.data as LiveBoard;
|
||||||
|
|
||||||
return liveboard.departures.departure;
|
return liveboard.departures.departure;
|
||||||
})))
|
})))
|
||||||
|
|
||||||
|
const answer = await axios.get(`${irailApiUrl}/stations?format=json&lang=en&alerts=true`);
|
||||||
|
const stations = (answer.data as StationsRoot).station;
|
||||||
|
|
||||||
|
dispatch(actions.loadTrainScheduleSuccess({ departures, stations }))
|
||||||
dispatch(actions.loadTrainScheduleSuccess({ departures }))
|
|
||||||
} catch(error) {
|
} catch(error) {
|
||||||
dispatch(actions.loadTrainScheduleError({ error: error as Error}))
|
dispatch(actions.loadTrainScheduleError({ error: error as Error}))
|
||||||
}
|
}
|
||||||
})()
|
})
|
||||||
|
useEffect(() => {
|
||||||
|
reloadTrainSchedule()
|
||||||
}, [])
|
}, [])
|
||||||
|
return { reloadTrainSchedule }
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -10,8 +10,7 @@ export type UseNewsApiProps = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export const useNewsApi = ({dispatch}: UseNewsApiProps) => {
|
export const useNewsApi = ({dispatch}: UseNewsApiProps) => {
|
||||||
useEffect(() => {
|
const reloadNews = (async () => {
|
||||||
(async () => {
|
|
||||||
try {
|
try {
|
||||||
dispatch(actions.loadNews({}));
|
dispatch(actions.loadNews({}));
|
||||||
const answer = await fetch(newsUrl);
|
const answer = await fetch(newsUrl);
|
||||||
@@ -20,6 +19,10 @@ export const useNewsApi = ({dispatch}: UseNewsApiProps) => {
|
|||||||
} catch(error) {
|
} catch(error) {
|
||||||
dispatch(actions.loadNewsError({ error: error as Error}));
|
dispatch(actions.loadNewsError({ error: error as Error}));
|
||||||
}
|
}
|
||||||
})()
|
})
|
||||||
|
useEffect(() => {
|
||||||
|
reloadNews()
|
||||||
}, [])
|
}, [])
|
||||||
|
|
||||||
|
return { reloadNews }
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,17 +2,17 @@ import { useEffect, type Dispatch } from "react"
|
|||||||
import { actions, type Action, type State } from "../state"
|
import { actions, type Action, type State } from "../state"
|
||||||
import type {WeatherData} from "../types/weather";
|
import type {WeatherData} from "../types/weather";
|
||||||
|
|
||||||
const weatherApiUrl = `https://api.weatherapi.com/v1/current.json?key=176d6e98c8894466aa6205455253010&q=Nivelles&aqi=no`;
|
|
||||||
|
|
||||||
export type UseWeatherApiProps = {
|
export type UseWeatherApiProps = {
|
||||||
dispatch: Dispatch<Action>,
|
dispatch: Dispatch<Action>,
|
||||||
state: State
|
state: State
|
||||||
}
|
}
|
||||||
|
|
||||||
export const useWeatherApi = ({ dispatch}: UseWeatherApiProps) => {
|
export const useWeatherApi = ({ dispatch, state }: UseWeatherApiProps) => {
|
||||||
useEffect(() => {
|
|
||||||
(async () => {
|
const reloadWeather = (async () => {
|
||||||
try {
|
try {
|
||||||
|
const weatherApiUrl = `https://api.weatherapi.com/v1/current.json?key=176d6e98c8894466aa6205455253010&q=${state.selectedLocation}&aqi=no`;
|
||||||
|
|
||||||
dispatch(actions.loadWeather({}));
|
dispatch(actions.loadWeather({}));
|
||||||
const answer = await fetch(weatherApiUrl);
|
const answer = await fetch(weatherApiUrl);
|
||||||
const weather = await answer.json() as WeatherData;
|
const weather = await answer.json() as WeatherData;
|
||||||
@@ -20,6 +20,9 @@ export const useWeatherApi = ({ dispatch}: UseWeatherApiProps) => {
|
|||||||
} catch(error) {
|
} catch(error) {
|
||||||
dispatch(actions.loadWeatherError({ error: error as Error }));
|
dispatch(actions.loadWeatherError({ error: error as Error }));
|
||||||
}
|
}
|
||||||
})()
|
});
|
||||||
|
useEffect(() => {
|
||||||
|
reloadWeather();
|
||||||
}, [])
|
}, [])
|
||||||
|
return { reloadWeather }
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,6 +8,10 @@ import {
|
|||||||
loadNewsError,
|
loadNewsError,
|
||||||
loadNewsSuccess,
|
loadNewsSuccess,
|
||||||
loadNews,
|
loadNews,
|
||||||
|
loadGiteaIssueError,
|
||||||
|
loadGiteaIssueSuccess,
|
||||||
|
loadGiteaIssue,
|
||||||
|
setSelectedLocation,
|
||||||
} from './consts'
|
} from './consts'
|
||||||
|
|
||||||
import {
|
import {
|
||||||
@@ -20,6 +24,10 @@ import {
|
|||||||
type LoadNewsError,
|
type LoadNewsError,
|
||||||
type LoadNewsSuccess,
|
type LoadNewsSuccess,
|
||||||
type LoadNews,
|
type LoadNews,
|
||||||
|
type LoadGiteaIssueError,
|
||||||
|
type LoadGiteaIssueSuccess,
|
||||||
|
type LoadGiteaIssue,
|
||||||
|
type SetSelectedLocation,
|
||||||
} from './types';
|
} from './types';
|
||||||
|
|
||||||
export const actions = {
|
export const actions = {
|
||||||
@@ -59,4 +67,20 @@ export const actions = {
|
|||||||
type: loadWeatherError,
|
type: loadWeatherError,
|
||||||
...args
|
...args
|
||||||
} as LoadWeatherError),
|
} as LoadWeatherError),
|
||||||
|
loadGiteaIssue: (args: Omit<LoadGiteaIssue, "type">) => ({
|
||||||
|
type: loadGiteaIssue,
|
||||||
|
...args
|
||||||
|
} as LoadGiteaIssue),
|
||||||
|
loadGiteaIssueSuccess: (args: Omit<LoadGiteaIssueSuccess, "type">) => ({
|
||||||
|
type: loadGiteaIssueSuccess,
|
||||||
|
...args
|
||||||
|
} as LoadGiteaIssueSuccess),
|
||||||
|
loadGiteaIssueError: (args: Omit<LoadGiteaIssueError, "type">) => ({
|
||||||
|
type: loadGiteaIssueError,
|
||||||
|
...args
|
||||||
|
} as LoadGiteaIssueError),
|
||||||
|
setSelectedLocation: (args: Omit<SetSelectedLocation, "type">) => ({
|
||||||
|
type: setSelectedLocation,
|
||||||
|
...args
|
||||||
|
} as SetSelectedLocation),
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -11,3 +11,9 @@ export const loadNewsError: ActionType = 'loadNewsError';
|
|||||||
export const loadWeather: ActionType = 'loadWeather';
|
export const loadWeather: ActionType = 'loadWeather';
|
||||||
export const loadWeatherSuccess: ActionType = 'loadWeatherSuccess';
|
export const loadWeatherSuccess: ActionType = 'loadWeatherSuccess';
|
||||||
export const loadWeatherError: ActionType = 'loadWeatherError';
|
export const loadWeatherError: ActionType = 'loadWeatherError';
|
||||||
|
|
||||||
|
export const loadGiteaIssue: ActionType = 'loadGiteaIssue';
|
||||||
|
export const loadGiteaIssueSuccess: ActionType = 'loadGiteaIssueSuccess';
|
||||||
|
export const loadGiteaIssueError: ActionType = 'loadGiteaIssueError';
|
||||||
|
|
||||||
|
export const setSelectedLocation: ActionType = 'setSelectedLocation';
|
||||||
|
|||||||
@@ -1,6 +1,8 @@
|
|||||||
export type ActionType = string;
|
export type ActionType = string;
|
||||||
|
|
||||||
|
import type {Station} from '../../types';
|
||||||
import type {Article} from '../../types/article';
|
import type {Article} from '../../types/article';
|
||||||
|
import type {IssuesResponse} from '../../types/issues';
|
||||||
import type { DepartureType } from '../../types/liveboard';
|
import type { DepartureType } from '../../types/liveboard';
|
||||||
import type {WeatherData} from '../../types/weather';
|
import type {WeatherData} from '../../types/weather';
|
||||||
import {
|
import {
|
||||||
@@ -13,6 +15,10 @@ import {
|
|||||||
loadWeather,
|
loadWeather,
|
||||||
loadWeatherError,
|
loadWeatherError,
|
||||||
loadWeatherSuccess,
|
loadWeatherSuccess,
|
||||||
|
loadGiteaIssueSuccess,
|
||||||
|
loadGiteaIssueError,
|
||||||
|
loadGiteaIssue,
|
||||||
|
setSelectedLocation,
|
||||||
} from './consts'
|
} from './consts'
|
||||||
|
|
||||||
export type Action = {
|
export type Action = {
|
||||||
@@ -25,7 +31,8 @@ export type LoadTrainSchedule = {
|
|||||||
|
|
||||||
export type LoadTrainScheduleSuccess = {
|
export type LoadTrainScheduleSuccess = {
|
||||||
type: typeof loadTrainScheduleSuccess,
|
type: typeof loadTrainScheduleSuccess,
|
||||||
departures: DepartureType[]
|
departures: DepartureType[],
|
||||||
|
stations: Station[]
|
||||||
}
|
}
|
||||||
|
|
||||||
export type LoadTrainScheduleError = {
|
export type LoadTrainScheduleError = {
|
||||||
@@ -62,3 +69,22 @@ export type LoadWeatherError = {
|
|||||||
error: Error
|
error: Error
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export type LoadGiteaIssue = {
|
||||||
|
type: typeof loadGiteaIssue,
|
||||||
|
}
|
||||||
|
|
||||||
|
export type LoadGiteaIssueSuccess = {
|
||||||
|
type: typeof loadGiteaIssueSuccess,
|
||||||
|
data: IssuesResponse
|
||||||
|
}
|
||||||
|
|
||||||
|
export type LoadGiteaIssueError = {
|
||||||
|
type: typeof loadGiteaIssueError,
|
||||||
|
error: Error
|
||||||
|
}
|
||||||
|
|
||||||
|
export type SetSelectedLocation = {
|
||||||
|
type: typeof setSelectedLocation,
|
||||||
|
location: string,
|
||||||
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -10,4 +10,9 @@ export const initialState: State = {
|
|||||||
weather: undefined,
|
weather: undefined,
|
||||||
weatherError: undefined,
|
weatherError: undefined,
|
||||||
weatherLoading: false,
|
weatherLoading: false,
|
||||||
|
issues: undefined,
|
||||||
|
issuesError: undefined,
|
||||||
|
issuesLoading: false,
|
||||||
|
stations: undefined,
|
||||||
|
selectedLocation: 'Nivelles'
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -17,6 +17,13 @@ import {
|
|||||||
type LoadWeatherSuccess,
|
type LoadWeatherSuccess,
|
||||||
type LoadNewsError,
|
type LoadNewsError,
|
||||||
type LoadNewsSuccess,
|
type LoadNewsSuccess,
|
||||||
|
loadGiteaIssueSuccess,
|
||||||
|
loadGiteaIssue,
|
||||||
|
type LoadGiteaIssueSuccess,
|
||||||
|
loadGiteaIssueError,
|
||||||
|
type LoadGiteaIssueError,
|
||||||
|
setSelectedLocation,
|
||||||
|
type SetSelectedLocation,
|
||||||
} from './actions';
|
} from './actions';
|
||||||
|
|
||||||
|
|
||||||
@@ -34,6 +41,7 @@ export const reducerInner = (state: State, action: Action): State => {
|
|||||||
return {
|
return {
|
||||||
...state,
|
...state,
|
||||||
departures: (action as LoadTrainScheduleSuccess).departures,
|
departures: (action as LoadTrainScheduleSuccess).departures,
|
||||||
|
stations: (action as LoadTrainScheduleSuccess).stations,
|
||||||
trainScheduleLoading: false,
|
trainScheduleLoading: false,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -85,6 +93,33 @@ export const reducerInner = (state: State, action: Action): State => {
|
|||||||
weatherError: (action as LoadWeatherError).error,
|
weatherError: (action as LoadWeatherError).error,
|
||||||
weatherLoading: false,
|
weatherLoading: false,
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
else if(action.type === loadGiteaIssue) {
|
||||||
|
return {
|
||||||
|
...state,
|
||||||
|
issuesError: undefined,
|
||||||
|
issuesLoading: true,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if(action.type === loadGiteaIssueSuccess) {
|
||||||
|
return {
|
||||||
|
...state,
|
||||||
|
issues: (action as LoadGiteaIssueSuccess).data,
|
||||||
|
issuesLoading: false,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if(action.type === loadGiteaIssueError) {
|
||||||
|
return {
|
||||||
|
...state,
|
||||||
|
issuesLoading: false,
|
||||||
|
issuesError: (action as LoadGiteaIssueError).error,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if(action.type === setSelectedLocation) {
|
||||||
|
return {
|
||||||
|
...state,
|
||||||
|
selectedLocation: (action as SetSelectedLocation).location,
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return state;
|
return state;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,6 @@
|
|||||||
|
import type {Station} from "../types";
|
||||||
import type { Article } from "../types/article";
|
import type { Article } from "../types/article";
|
||||||
|
import type {IssuesResponse} from "../types/issues";
|
||||||
import type { DepartureType } from "../types/liveboard";
|
import type { DepartureType } from "../types/liveboard";
|
||||||
import type { WeatherData } from "../types/weather";
|
import type { WeatherData } from "../types/weather";
|
||||||
|
|
||||||
@@ -14,4 +16,11 @@ export type State = {
|
|||||||
news: Article[] | undefined,
|
news: Article[] | undefined,
|
||||||
newsLoading: boolean,
|
newsLoading: boolean,
|
||||||
newsError: Error | undefined,
|
newsError: Error | undefined,
|
||||||
|
|
||||||
|
issues: IssuesResponse | undefined,
|
||||||
|
issuesLoading: boolean,
|
||||||
|
issuesError: Error | undefined,
|
||||||
|
|
||||||
|
stations: undefined | Station[],
|
||||||
|
selectedLocation: string,
|
||||||
}
|
}
|
||||||
|
|||||||
64
src/types/issues.tsx
Normal file
64
src/types/issues.tsx
Normal file
@@ -0,0 +1,64 @@
|
|||||||
|
interface User {
|
||||||
|
id: number;
|
||||||
|
login: string;
|
||||||
|
login_name: string;
|
||||||
|
source_id: number;
|
||||||
|
full_name: string;
|
||||||
|
email: string;
|
||||||
|
avatar_url: string;
|
||||||
|
html_url: string;
|
||||||
|
language: string;
|
||||||
|
is_admin: boolean;
|
||||||
|
last_login: string;
|
||||||
|
created: string;
|
||||||
|
restricted: boolean;
|
||||||
|
active: boolean;
|
||||||
|
prohibit_login: boolean;
|
||||||
|
location: string;
|
||||||
|
website: string;
|
||||||
|
description: string;
|
||||||
|
visibility: string;
|
||||||
|
followers_count: number;
|
||||||
|
following_count: number;
|
||||||
|
starred_repos_count: number;
|
||||||
|
username: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
interface Repository {
|
||||||
|
id: number;
|
||||||
|
name: string;
|
||||||
|
owner: string;
|
||||||
|
full_name: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface IssueType {
|
||||||
|
id: number;
|
||||||
|
url: string;
|
||||||
|
html_url: string;
|
||||||
|
number: number;
|
||||||
|
user: User;
|
||||||
|
original_author: string;
|
||||||
|
original_author_id: number;
|
||||||
|
title: string;
|
||||||
|
body: string;
|
||||||
|
ref: string;
|
||||||
|
assets: any[];
|
||||||
|
labels: string[];
|
||||||
|
milestone: any | null;
|
||||||
|
assignee: any | null;
|
||||||
|
assignees: any | null;
|
||||||
|
state: string;
|
||||||
|
is_locked: boolean;
|
||||||
|
comments: number;
|
||||||
|
created_at: string;
|
||||||
|
updated_at: string;
|
||||||
|
closed_at: string | null;
|
||||||
|
due_date: string | null;
|
||||||
|
time_estimate: number;
|
||||||
|
pull_request: any | null;
|
||||||
|
repository: Repository;
|
||||||
|
pin_order: number;
|
||||||
|
}
|
||||||
|
|
||||||
|
export type IssuesResponse = IssueType[];
|
||||||
|
|
||||||
15
src/types/station.tsx
Normal file
15
src/types/station.tsx
Normal file
@@ -0,0 +1,15 @@
|
|||||||
|
export interface StationsRoot {
|
||||||
|
version: string
|
||||||
|
timestamp: string
|
||||||
|
station: Station[]
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface Station {
|
||||||
|
"@id": string
|
||||||
|
id: string
|
||||||
|
name: string
|
||||||
|
locationX: string
|
||||||
|
locationY: string
|
||||||
|
standardname: string
|
||||||
|
}
|
||||||
|
|
||||||
Reference in New Issue
Block a user