Skip to content

Commit 25c78e1

Browse files
committed
client: Fix more type check issues
1 parent 2ae62c6 commit 25c78e1

16 files changed

+189
-55
lines changed

client/js/helpers/hooks.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { useEffect, useState } from 'react';
2-
import { useLocation } from 'react-router-dom';
32
import { useMediaMatch } from 'rooks';
3+
import { useLocation } from '../templates/App';
44
import { ValueListenable } from './ValueListenable';
55

66
/**

client/js/helpers/uri.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { generatePath } from 'react-router-dom';
2-
import { Location } from 'history';
2+
import { Location } from '../templates/App';
33
import { FilterType } from '../Filter';
44

55
/**

client/js/requests/items.ts

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,28 @@ type StatusUpdate = {
132132

133133
type SyncParams = {
134134
updatedStatuses: Array<StatusUpdate>;
135+
since?: Date;
136+
itemsNotBefore?: Date;
137+
};
138+
139+
export type EntryStatus = {
140+
id: number;
141+
unread: boolean;
142+
starred: boolean;
143+
};
144+
145+
export type NavTag = { tag: string; unread: number };
146+
147+
export type NavSource = { id: number; unread: number };
148+
149+
export type Stats = { all: number; unread: number; starred: number };
150+
151+
type SyncResponse = {
152+
entries: Array<EnrichedResponseItem>;
153+
stats?: Stats;
154+
tags?: NavTag[];
155+
sources?: NavSource[];
156+
itemUpdates?: EntryStatus[];
135157
};
136158

137159
/**
@@ -140,7 +162,7 @@ type SyncParams = {
140162
export function sync(
141163
updatedStatuses: Array<StatusUpdate>,
142164
syncParams: SyncParams,
143-
): { controller: AbortController; promise: Promise<GetItemsResponse> } {
165+
): { controller: AbortController; promise: Promise<SyncResponse> } {
144166
const params = {
145167
...syncParams,
146168
updatedStatuses: syncParams.updatedStatuses

client/js/selfoss-base.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import { ValueListenable } from './helpers/ValueListenable';
66
import { HttpError, TimeoutError } from './errors';
77
import { Configuration } from './model/Configuration';
88
import { LoadingState } from './requests/LoadingState';
9-
import { App, createApp } from './templates/App';
9+
import { App, History, createApp } from './templates/App';
1010
import dbOnline from './selfoss-db-online';
1111
import dbOffline from './selfoss-db-offline';
1212
import db from './selfoss-db';
@@ -39,6 +39,7 @@ class selfoss {
3939
public static db = db;
4040
public static dbOnline = dbOnline;
4141
public static dbOffline = dbOffline;
42+
static history: History;
4243

4344
/**
4445
* initialize application

client/js/templates/App.tsx

Lines changed: 29 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,17 @@
1+
import {
2+
History as HistoryGeneric,
3+
Location as LocationGeneric,
4+
} from 'history';
15
import React, { useCallback, useContext, useEffect, useState } from 'react';
26
import {
37
BrowserRouter as Router,
48
Switch,
59
Route,
610
Link,
711
Redirect,
8-
useHistory,
9-
useLocation,
12+
useHistory as useHistoryGeneric,
13+
useLocation as useLocationGeneric,
14+
useParams as useParamsGeneric,
1015
} from 'react-router-dom';
1116
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';
1217
import { Collapse } from '@kunukn/react-collapse';
@@ -29,6 +34,26 @@ import { Configuration, ConfigurationContext } from '../model/Configuration';
2934
import { LoadingState } from '../requests/LoadingState';
3035
import * as sourceRequests from '../requests/sources';
3136
import locales from '../locales';
37+
import { NavSource, NavTag } from '../requests/items';
38+
import { FilterType } from '../Filter';
39+
40+
export type LocationState = {
41+
error?: string;
42+
returnLocation?: string;
43+
forceReload?: number;
44+
};
45+
export type Params = {
46+
filter?: FilterType;
47+
category?: string;
48+
id?: string;
49+
};
50+
51+
export type History = HistoryGeneric<LocationState>;
52+
export type Location = LocationGeneric<LocationState>;
53+
54+
export const useHistory = useHistoryGeneric<LocationState>;
55+
export const useParams = useParamsGeneric<Params>;
56+
export const useLocation = useLocationGeneric<LocationState>;
3257

3358
type MessageAction = {
3459
label: string;
@@ -391,13 +416,13 @@ type AppState = {
391416
/**
392417
* tag repository
393418
*/
394-
tags: Array<Tag>;
419+
tags: Array<NavTag>;
395420
tagsState: LoadingState;
396421

397422
/**
398423
* source repository
399424
*/
400-
sources: Array<Source>;
425+
sources: Array<NavSource>;
401426
sourcesState: LoadingState;
402427

403428
/**

client/js/templates/EntriesPage.tsx

Lines changed: 28 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,15 @@ import React, {
55
useMemo,
66
useState,
77
} from 'react';
8-
import { Link, useLocation, useParams } from 'react-router-dom';
8+
import { Link } from 'react-router-dom';
99
import { useOnline } from 'rooks';
1010
import { useStateWithDeps } from 'use-state-with-deps';
11+
import { Location, useLocation, useParams } from './App';
1112
import selfoss from '../selfoss-base';
1213
import Item from './Item';
1314
import { FilterType } from '../Filter';
1415
import * as itemsRequests from '../requests/items';
16+
import { EntryStatus } from '../requests/items';
1517
import * as sourceRequests from '../requests/sources';
1618
import { LoadingState } from '../requests/LoadingState';
1719
import { Spinner, SpinnerBig } from './Spinner';
@@ -24,7 +26,7 @@ import { autoScroll, Direction } from '../helpers/navigation';
2426
import { LocalizationContext } from '../helpers/i18n';
2527
import { useShouldReload } from '../helpers/hooks';
2628
import { forceReload, makeEntriesLinkLocation } from '../helpers/uri';
27-
import { ConfigurationContext } from '../model/Configuration';
29+
import { Configuration, ConfigurationContext } from '../model/Configuration';
2830
import { HttpError } from '../errors';
2931

3032
function reloadList({
@@ -535,18 +537,33 @@ const initialState = {
535537
loadingState: LoadingState.INITIAL,
536538
};
537539

540+
type Match = {
541+
params: {
542+
category?: string;
543+
filter: FilterType;
544+
};
545+
};
546+
538547
type StateHolderProps = {
539-
configuration: object;
540-
location: object;
541-
match: object;
548+
configuration: Configuration;
549+
location: Location;
550+
match: Match;
542551
setNavExpanded: React.Dispatch<React.SetStateAction<boolean>>;
543552
navSourcesExpanded: boolean;
544553
setGlobalUnreadCount: React.Dispatch<React.SetStateAction<number>>;
545554
unreadItemsCount: number;
546555
};
547556

557+
type Entry = {
558+
id: number;
559+
unread: boolean;
560+
starred: boolean;
561+
tags: string[];
562+
source: number;
563+
};
564+
548565
type StateHolderState = {
549-
entries: Array<object>;
566+
entries: Array<Entry>;
550567
hasMore: boolean;
551568
/**
552569
* Currently selected entry.
@@ -691,7 +708,7 @@ export default class StateHolder extends React.Component<
691708
const autoMarkAsRead =
692709
selfoss.isAllowedToWrite() &&
693710
this.props.configuration.autoMarkAsRead &&
694-
entry.unread == 1;
711+
entry.unread;
695712
if (autoMarkAsRead) {
696713
this.markEntryRead(id, true);
697714
}
@@ -735,7 +752,7 @@ export default class StateHolder extends React.Component<
735752
);
736753
}
737754

738-
refreshEntryStatuses(entryStatuses) {
755+
refreshEntryStatuses(entryStatuses: EntryStatus[]) {
739756
this.state.entries.forEach((entry) => {
740757
const { id } = entry;
741758
const newStatus = entryStatuses.find(
@@ -799,9 +816,9 @@ export default class StateHolder extends React.Component<
799816
* Mark all visible items as read
800817
*/
801818
markVisibleRead(): void {
802-
const ids = [];
803-
const tagUnreadDiff = {};
804-
const sourceUnreadDiff = {};
819+
const ids: number[] = [];
820+
const tagUnreadDiff: { [index: string]: number } = {};
821+
const sourceUnreadDiff: { [index: string]: number } = {};
805822

806823
let markedEntries = this.state.entries.map((entry) => {
807824
if (!entry.unread) {

client/js/templates/HashPassword.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import React, { useCallback, useEffect, useState } from 'react';
2-
import { useHistory } from 'react-router-dom';
2+
import { useHistory } from './App';
33
import { useInput } from 'rooks';
44
import { LoadingState } from '../requests/LoadingState';
55
import { HttpError } from '../errors';

0 commit comments

Comments
 (0)