Skip to content

Commit

Permalink
fixup! client: Fix more type check issues
Browse files Browse the repository at this point in the history
  • Loading branch information
jtojnar committed May 31, 2024
1 parent 3146af4 commit 78d2233
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 10 deletions.
28 changes: 22 additions & 6 deletions client/js/templates/Source.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -278,12 +278,24 @@ function daysAgo(date: Date): number {
return Math.floor((today - old) / MS_PER_DAY);
}

export type Source = {
id: number;
title: string;
spout: string;
tags: string;
filter: string;
params: { [name: string]: string };
icon: string;
lastentry: number;
error: string;
};

type SourceEditFormProps = {
source: object;
source: Source;
sourceElem: object;
sourceError?: string;
setSources: React.Dispatch<React.SetStateAction<Array<object>>>;
spouts: object;
spouts: Spout[];
setSpouts: React.Dispatch<React.SetStateAction<Array<object>>>;
setEditedSource: React.Dispatch<React.SetStateAction<object>>;
sourceActionLoading: boolean;
Expand Down Expand Up @@ -585,13 +597,17 @@ function SourceEditForm(props: SourceEditFormProps) {
);
}

type Spout = {};

type SourceProps = {
source: object;
setSources: React.Dispatch<React.SetStateAction<Array<object>>>;
spouts: object;
source: Source;
setSources: React.Dispatch<React.SetStateAction<Array<Source>>>;
spouts: { [className: string]: Spout };
setSpouts: React.Dispatch<React.SetStateAction<object>>;
dirty: boolean;
setDirtySources: React.Dispatch<React.SetStateAction<boolean>>;
setDirtySources: React.Dispatch<
React.SetStateAction<{ [id: number]: boolean }>
>;
};

export default function Source(props: SourceProps) {
Expand Down
20 changes: 17 additions & 3 deletions client/js/templates/SourceParam.tsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,27 @@
import React, { useCallback, useContext } from 'react';
import { LocalizationContext } from '../helpers/i18n';
import { Source } from './Source';

type SpoutParam = {
title: string;
default: string;
} & (
| {
type: 'text' | 'url' | 'password' | 'checkbox';
}
| {
type: 'select';
values: { [s: string]: string };
}
);

type SourceParamProps = {
spoutParamName: string;
spoutParam: object;
params: object;
spoutParam: SpoutParam;
params: { [index: string]: string };
sourceErrors: { [index: string]: string };
sourceId: number;
setEditedSource: React.Dispatch<React.SetStateAction<object | null>>;
setEditedSource: React.Dispatch<React.SetStateAction<Source | null>>;
setDirty: React.Dispatch<React.SetStateAction<boolean>>;
};

Expand Down
4 changes: 3 additions & 1 deletion client/js/templates/SourcesPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,9 @@ export default function SourcesPage(): React.JSX.Element {

const _ = useContext(LocalizationContext);

const [dirtySources, setDirtySources] = useState({});
const [dirtySources, setDirtySources] = useState<{ [id: number]: boolean }>(
{},
);
const isDirty = useMemo(
() => Object.values(dirtySources).includes(true),
[dirtySources],
Expand Down

0 comments on commit 78d2233

Please sign in to comment.