Skip to content

Commit

Permalink
refactor: Updated types
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelkoelle committed Oct 27, 2021
1 parent 337414b commit 4b47576
Show file tree
Hide file tree
Showing 34 changed files with 120 additions and 83 deletions.
2 changes: 1 addition & 1 deletion app/autocorrection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ export default class AutoCorrection {
);
});

ipcMain.on(AUTOCORRECTION_CANCEL, (event: IpcMainEvent, arg) => {
ipcMain.on(AUTOCORRECTION_CANCEL, (event: IpcMainEvent) => {
const { sender } = event;
this.cancelRequest = true;
sender.send(AUTOCORRECTION_CANCEL_PENDING);
Expand Down
11 changes: 7 additions & 4 deletions app/components/ConditionalCommentSettings.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,14 @@
/* eslint-disable @typescript-eslint/no-empty-interface */
/* eslint-disable react/jsx-props-no-spreading */
import React from 'react';
import { Theme, withStyles } from '@material-ui/core/styles';
import AddCircleIcon from '@material-ui/icons/AddCircle';
import Typography from '@material-ui/core/Typography';
import {
Fade,
Grid,
IconButton,
Paper,
Slider,
Tooltip,
Theme,
useTheme,
} from '@material-ui/core';
import { useDispatch, useSelector } from 'react-redux';
Expand All @@ -22,7 +20,12 @@ import {
settingsUpdateConditionalCommentValue,
} from '../model/SettingsSlice';

function ValueLabelComponent(props: any) {
function ValueLabelComponent(props: {
children;
value: number;
comments: string[];
theme: Theme;
}) {
const { children, value, comments, theme } = props;
return (
<>
Expand Down
1 change: 0 additions & 1 deletion app/components/ConditionalCommentTextInput.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
/* eslint-disable react/prop-types */
import { IconButton, TextField } from '@material-ui/core';
import CancelIcon from '@material-ui/icons/Cancel';
import { relative } from 'path';
import React, { useState } from 'react';
import { useDispatch } from 'react-redux';
import ConditionalComment from '../model/ConditionalComment';
Expand Down
7 changes: 6 additions & 1 deletion app/components/LoadingItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,12 @@ import { Grid, CircularProgress, Typography } from '@material-ui/core';
import React from 'react';
import DoneIcon from '@material-ui/icons/Done';

export default function LoadingItem(props: any): JSX.Element {
export type LoadingItemProps = {
complete: boolean;
message: string;
};

export default function LoadingItem(props: LoadingItemProps): JSX.Element {
const { complete, message } = props;
const loadingIcon = complete ? (
<DoneIcon style={{ fill: 'black' }} />
Expand Down
16 changes: 10 additions & 6 deletions app/components/LoadingItemList.tsx
Original file line number Diff line number Diff line change
@@ -1,16 +1,20 @@
import { List, ListItem } from '@material-ui/core';
import React from 'react';
import LoadingItem from './LoadingItem';
import LoadingItem, { LoadingItemProps } from './LoadingItem';

export default function LoadingItemList(props: any): JSX.Element {
type LoadingItemListProps = {
progress: (LoadingItemProps & { active: boolean })[];
};

export default function LoadingItemList(
props: LoadingItemListProps
): JSX.Element {
const { progress } = props;
const activeItems = progress.filter(
(item: { active: boolean }) => item.active
);
const activeItems = progress.filter((item) => item.active);

return (
<List>
{activeItems.map((item: { message: string; complete: boolean }) => {
{activeItems.map((item) => {
return (
<ListItem key={item.message}>
<LoadingItem message={item.message} complete={item.complete} />
Expand Down
2 changes: 1 addition & 1 deletion app/containers/CorrectionViewPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ import {
} from '../model/Selectors';

import Sheet from '../model/Sheet';
import { sheetsUpsertOne } from '../model/SheetSlice';
import { serializeTerm } from '../utils/Formatter';
import './SplitPane.css';

Expand Down Expand Up @@ -64,6 +63,7 @@ export default function CorrectionViewPage() {
);
}
};
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [index]);

function handleCloseDialog() {
Expand Down
2 changes: 1 addition & 1 deletion app/containers/OverviewPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@
import React from 'react';
import Overview from '../features/overview/Overview';

export default function OverviewPage(props: any) {
export default function OverviewPage(props) {
return <Overview {...props} />;
}
1 change: 1 addition & 0 deletions app/containers/Root.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { AnyAction, EnhancedStore } from '@reduxjs/toolkit';
import Providers from './Providers';

type Props = {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
store: EnhancedStore<any, AnyAction, any[]>;
history: History;
};
Expand Down
3 changes: 2 additions & 1 deletion app/containers/TitleBar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { useSelector } from 'react-redux';
import { useTheme, Snackbar } from '@material-ui/core';
import { remote } from 'electron';
import { Alert } from '@material-ui/lab';
import { MenuItem } from 'frameless-titlebar/dist/title-bar/typings';
import {
selectRecentPaths,
selectWorkspacePath,
Expand Down Expand Up @@ -109,7 +110,7 @@ export default function TitleBar(props: TitleBarProps) {
recentPaths,
setOpenFileError,
setReload
) as any
) as MenuItem[] | undefined
}
theme={{
bar: {
Expand Down
1 change: 1 addition & 0 deletions app/features/correction/CorrectionOverview.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ export default function CorrectionOverview(props: CorrectionOverviewProps) {
correction.status === Status.Marked
)
);
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [index]);

const handleClick = () => {
Expand Down
6 changes: 4 additions & 2 deletions app/features/media-viewer/PDFViewer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,10 @@ export default function PDFViewer(props: ViewerProps) {
const textLayers = document.querySelectorAll(
'.react-pdf__Page__textContent'
);
textLayers.forEach((layer: any) => {
const { style } = layer;
textLayers.forEach((layer) => {
const { style } = (layer as unknown) as {
style: { top: string; left: string; transform: string };
};
style.top = '0';
style.left = '0';
style.transform = '';
Expand Down
1 change: 1 addition & 0 deletions app/features/media-viewer/ViewerToolbar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ export default function ViewerToolbar(props: ViewerToolbarProps) {
return () => {
window.removeEventListener('wheel', handleScrollEvent);
};
// eslint-disable-next-line react-hooks/exhaustive-deps
}, []);

return (
Expand Down
5 changes: 0 additions & 5 deletions app/menu.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,6 @@ export default class MenuBuilder {
this.setupDevelopmentEnvironment();
}

const template =
process.platform === 'darwin'
? this.buildDarwinTemplate()
: this.buildDefaultTemplate();

const menu = Menu.buildFromTemplate([]);
Menu.setApplicationMenu(menu);

Expand Down
5 changes: 3 additions & 2 deletions app/modals/AutoCorrectionModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ const AutoCorrectionModal: FC<AutoCorrectionModalProps> = ({ ...props }) => {
) => {
setAutoCorrectionProgress(progress);
};
const handleAutoCorrectionCancelPending = (_event: IpcRendererEvent) => {
const handleAutoCorrectionCancelPending = () => {
setAutoCorrectionState(AutoCorrectionState.AUTOCORRECTION_CANCEL_PENDING);
};

Expand Down Expand Up @@ -236,9 +236,10 @@ const AutoCorrectionModal: FC<AutoCorrectionModalProps> = ({ ...props }) => {
handleProgress
);
};
// eslint-disable-next-line react-hooks/exhaustive-deps
}, []);

let content;
let content: JSX.Element | null;

switch (autoCorrectionState) {
case AutoCorrectionState.AUTOCORRECTION_STARTED:
Expand Down
1 change: 1 addition & 0 deletions app/modals/ImportModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@ const ImportModal: FC<ImportModalProps> = ({ ...props }) => {
ipcRenderer.removeListener(ImportIPC.IMPORT_FAILED, handleImportFailed);
ipcRenderer.removeListener(ImportIPC.IMPORT_PROGRESS, handleProgress);
};
// eslint-disable-next-line react-hooks/exhaustive-deps
}, []);

let content;
Expand Down
3 changes: 2 additions & 1 deletion app/modals/ModalProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,9 @@ const ModalContext = createContext<

export default function ModalProvider(props: ModalProviderProps) {
const { children } = props;
// eslint-disable-next-line @typescript-eslint/no-explicit-any
const [Modal, setModal] = useState<any>(null);
const [modalOptions, setModalOptions] = useState<any>(null);
const [modalOptions, setModalOptions] = useState<unknown>(null);

const openModal = <T extends unknown>(
component: FC<T & ModalProps>,
Expand Down
1 change: 1 addition & 0 deletions app/modals/ReleaseNotesModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ const ReleaseNotesModal: FC<ReleaseNotesModalProps> = ({ ...props }) => {
.catch(() => {
setLoading(false);
});
// eslint-disable-next-line react-hooks/exhaustive-deps
}, []);

let content: JSX.Element;
Expand Down
6 changes: 4 additions & 2 deletions app/model/AnnotationSlice.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ const slice = createSlice({
adapter.upsertMany(state, action.payload.annotations);
}
},
[deleteEntities.type]: (state, action) => {
[deleteEntities.type]: (state) => {
adapter.removeAll(state);
},
},
Expand All @@ -53,6 +53,8 @@ export const {
selectEntities: selectAnnotationEntities,
selectAll: selectAllAnnotations,
selectTotal: selectTotalAnnotations,
} = adapter.getSelectors((state: any) => state.annotations);
} = adapter.getSelectors(
(state: { annotations: EntityState<Annotation> }) => state.annotations
);

export default slice.reducer;
10 changes: 8 additions & 2 deletions app/model/CommentSlice.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
/* eslint-disable import/no-cycle */
import { createEntityAdapter, createSlice } from '@reduxjs/toolkit';
import {
createEntityAdapter,
createSlice,
EntityState,
} from '@reduxjs/toolkit';
import CommentEntity from './CommentEntity';
import { loadCorrections, deleteEntities } from './CorrectionsSlice';

Expand Down Expand Up @@ -49,6 +53,8 @@ export const {
selectEntities: selectCommentsEntities,
selectAll: selectAllComments,
selectTotal: selectTotalComments,
} = adapter.getSelectors((state: any) => state.comments);
} = adapter.getSelectors(
(state: { comments: EntityState<CommentEntity> }) => state.comments
);

export default slice.reducer;
5 changes: 4 additions & 1 deletion app/model/CorrectionsSlice.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import {
createAction,
createEntityAdapter,
createSlice,
EntityState,
} from '@reduxjs/toolkit';
import { normalize } from 'normalizr';
import Correction from './Correction';
Expand Down Expand Up @@ -56,7 +57,9 @@ export const {
selectEntities: selectCorrectionEntities,
selectAll: selectAllCorrections,
selectTotal: selectTotalCorrections,
} = adapter.getSelectors((state: any) => state.corrections);
} = adapter.getSelectors(
(state: { corrections: EntityState<CorrectionEntity> }) => state.corrections
);

export function upsertCorrection(correction: Correction) {
return (dispatch) => {
Expand Down
6 changes: 4 additions & 2 deletions app/model/CorrectorSlice.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ const slice = createSlice({
[loadCorrections.type]: (state, action) => {
adapter.upsertMany(state, action.payload.correctors);
},
[deleteEntities.type]: (state, action) => {
[deleteEntities.type]: (state) => {
adapter.removeAll(state);
},
},
Expand All @@ -41,7 +41,9 @@ export const {
selectEntities: selectCorrectorEntities,
selectAll: selectAllCorrectors,
selectTotal: selectTotalCorrectors,
} = adapter.getSelectors((state: any) => state.correctors);
} = adapter.getSelectors(
(state: { correctors: EntityState<Corrector> }) => state.correctors
);

export const {
correctorsAddOne,
Expand Down
6 changes: 4 additions & 2 deletions app/model/CourseSlice.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ const slice = createSlice({
[loadCorrections.type]: (state, action) => {
adapter.upsertMany(state, action.payload.courses);
},
[deleteEntities.type]: (state, action) => {
[deleteEntities.type]: (state) => {
adapter.removeAll(state);
},
},
Expand All @@ -41,7 +41,9 @@ export const {
selectEntities: selectCourseEntities,
selectAll: selectAllCourses,
selectTotal: selectTotalCourses,
} = adapter.getSelectors((state: any) => state.courses);
} = adapter.getSelectors(
(state: { courses: EntityState<Course> }) => state.courses
);

export const {
coursesAddOne,
Expand Down
6 changes: 4 additions & 2 deletions app/model/LocationSlice.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ const slice = createSlice({
adapter.upsertMany(state, action.payload.locations);
}
},
[deleteEntities.type]: (state, action) => {
[deleteEntities.type]: (state) => {
adapter.removeAll(state);
},
},
Expand All @@ -43,7 +43,9 @@ export const {
selectEntities: selectLocationEntities,
selectAll: selectAllLocations,
selectTotal: selectTotalLocations,
} = adapter.getSelectors((state: any) => state.locations);
} = adapter.getSelectors(
(state: { locations: EntityState<Location> }) => state.locations
);

export const {
locationsAddOne,
Expand Down
4 changes: 2 additions & 2 deletions app/model/NoteSlice.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ const slice = createSlice({
adapter.upsertMany(state, action.payload.notes);
}
},
[deleteEntities.type]: (state, action) => {
[deleteEntities.type]: (state) => {
adapter.removeAll(state);
},
},
Expand All @@ -53,6 +53,6 @@ export const {
selectEntities: selectNoteEntities,
selectAll: selectAllNotes,
selectTotal: selectTotalNotes,
} = adapter.getSelectors((state: any) => state.notes);
} = adapter.getSelectors((state: { notes: EntityState<Note> }) => state.notes);

export default slice.reducer;
7 changes: 4 additions & 3 deletions app/model/RatingSlice.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import {
createEntityAdapter,
createSlice,
EntityState,
PayloadAction,
} from '@reduxjs/toolkit';
import { loadCorrections, deleteEntities } from './CorrectionsSlice';
import RatingEntity from './RatingEntity';
Expand Down Expand Up @@ -32,7 +31,7 @@ const slice = createSlice({
adapter.upsertMany(state, action.payload.ratings);
}
},
[deleteEntities.type]: (state, action) => {
[deleteEntities.type]: (state) => {
adapter.removeAll(state);
},
},
Expand All @@ -44,7 +43,9 @@ export const {
selectEntities: selectRatingEntities,
selectAll: selectAllRatings,
selectTotal: selectTotalRatings,
} = adapter.getSelectors((state: any) => state.ratings);
} = adapter.getSelectors(
(state: { ratings: EntityState<RatingEntity> }) => state.ratings
);

export const {
ratingsAddOne,
Expand Down
Loading

0 comments on commit 4b47576

Please sign in to comment.