feat: RSS feed and config
Some checks failed
Playwright Tests / test (push) Has been cancelled

This commit is contained in:
Loic Coenen
2025-11-02 20:36:07 +01:00
parent 9e872ea8d9
commit 77113c83e2
23 changed files with 1006 additions and 443 deletions

View File

@@ -12,6 +12,10 @@ import {
loadGiteaIssueSuccess,
loadGiteaIssue,
setSelectedLocation,
setConfig,
loadRssFeeds,
loadRssFeedsSuccess,
loadRssFeedsError,
} from './consts'
import {
@@ -28,6 +32,10 @@ import {
type LoadGiteaIssueSuccess,
type LoadGiteaIssue,
type SetSelectedLocation,
type SetConfig,
type LoadRssFeeds,
type LoadRssFeedsSuccess,
type LoadRssFeedsError,
} from './types';
export const actions = {
@@ -83,4 +91,20 @@ export const actions = {
type: setSelectedLocation,
...args
} as SetSelectedLocation),
setConfig: (args: Omit<SetConfig, "type">) => ({
type: setConfig,
...args
} as SetConfig),
loadRSSFeeds: (args: Omit<LoadRssFeeds, "type">) => ({
type: loadRssFeeds,
...args
} as LoadRssFeeds),
loadRSSFeedsSuccess: (args: Omit<LoadRssFeedsSuccess, "type">) => ({
type: loadRssFeedsSuccess,
...args
} as LoadRssFeedsSuccess),
loadRSSFeedsError: (args: Omit<LoadRssFeedsError, "type">) => ({
type: loadRssFeedsError,
...args
} as LoadRssFeedsError),
}

View File

@@ -17,3 +17,9 @@ export const loadGiteaIssueSuccess: ActionType = 'loadGiteaIssueSuccess';
export const loadGiteaIssueError: ActionType = 'loadGiteaIssueError';
export const setSelectedLocation: ActionType = 'setSelectedLocation';
export const setConfig: ActionType = 'setConfig';
export const loadRssFeeds: ActionType = 'RssFeeds';
export const loadRssFeedsSuccess: ActionType = 'RssFeedsSuccess';
export const loadRssFeedsError: ActionType = 'RssFeedsError';

View File

@@ -5,6 +5,7 @@ import type {Article} from '../../types/article';
import type {IssuesResponse} from '../../types/issues';
import type { DepartureType } from '../../types/liveboard';
import type {WeatherData} from '../../types/weather';
import type {RSS} from '../state';
import {
loadTrainSchedule,
loadTrainScheduleError,
@@ -19,6 +20,10 @@ import {
loadGiteaIssueError,
loadGiteaIssue,
setSelectedLocation,
setConfig,
loadRssFeeds,
loadRssFeedsSuccess,
loadRssFeedsError,
} from './consts'
export type Action = {
@@ -88,3 +93,22 @@ export type SetSelectedLocation = {
location: string,
}
export type SetConfig = {
type: typeof setConfig,
setting: string,
value: string | number,
}
export type LoadRssFeeds = {
type: typeof loadRssFeeds,
}
export type LoadRssFeedsSuccess = {
type: typeof loadRssFeedsSuccess,
feeds: RSS[]
}
export type LoadRssFeedsError = {
type: typeof loadRssFeedsError,
feeds: RSS[]
}

View File

@@ -14,5 +14,14 @@ export const initialState: State = {
issuesError: undefined,
issuesLoading: false,
stations: undefined,
selectedLocation: 'Nivelles'
selectedLocation: 'Nivelles',
config: {
rssFollow: '',
trainCancelCompute: -180,
trainDelayCompute: 60,
trainScheduleShow: 120
},
rss: undefined,
rssLoading: false,
rssError: undefined
};

View File

@@ -24,6 +24,11 @@ import {
type LoadGiteaIssueError,
setSelectedLocation,
type SetSelectedLocation,
setConfig,
type LoadRssFeedsSuccess,
type SetConfig,
loadRssFeeds,
loadRssFeedsSuccess,
} from './actions';
@@ -108,6 +113,25 @@ export const reducerInner = (state: State, action: Action): State => {
issuesLoading: false,
}
}
else if(action.type === loadGiteaIssueError) {
return {
...state,
issuesLoading: false,
issuesError: (action as LoadGiteaIssueError).error,
}
}
else if(action.type === loadRssFeeds) {
return {
...state,
rssLoading: true,
}
}
else if(action.type === loadRssFeedsSuccess) {
return {
...state,
rss: (action as LoadRssFeedsSuccess).feeds,
}
}
else if(action.type === loadGiteaIssueError) {
return {
...state,
@@ -121,6 +145,15 @@ export const reducerInner = (state: State, action: Action): State => {
selectedLocation: (action as SetSelectedLocation).location,
}
}
else if(action.type === setConfig) {
return {
...state,
config: {
...state.config,
[(action as SetConfig).setting]: (action as SetConfig).value
}
}
}
return state;
}

View File

@@ -4,6 +4,18 @@ import type {IssuesResponse} from "../types/issues";
import type { DepartureType } from "../types/liveboard";
import type { WeatherData } from "../types/weather";
export type RSS = {
title: string,
link: string
}
export type Config = {
trainScheduleShow: number,
trainDelayCompute: number,
trainCancelCompute: number,
rssFollow: string,
}
export type State = {
trainScheduleLoading: boolean,
departures: DepartureType[] | undefined,
@@ -23,4 +35,10 @@ export type State = {
stations: undefined | Station[],
selectedLocation: string,
config: Config,
rss: RSS[] | undefined,
rssLoading: boolean,
rssError: Error | undefined,
}