Skip to content

Commit

Permalink
Specify more types
Browse files Browse the repository at this point in the history
This replaces some `any` types with more specific
ones. No functional changes.
  • Loading branch information
Arnei committed Jan 16, 2024
1 parent 59f74b8 commit ec807c9
Show file tree
Hide file tree
Showing 9 changed files with 60 additions and 58 deletions.
4 changes: 2 additions & 2 deletions src/i18n/config.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import i18next from 'i18next';
import i18next, { InitOptions } from 'i18next';
import { initReactI18next } from 'react-i18next';
import LanguageDetector from 'i18next-browser-languagedetector';

import locales from './locales/locales.json';

const debug = Boolean(new URLSearchParams(window.location.search).get('debug'));

const resources: any = {};
const resources: InitOptions["resources"] = {};
for (const lang of locales) {
const code = lang.replace(/\..*$/, '');
const short = code.replace(/-.*$/, '');
Expand Down
20 changes: 10 additions & 10 deletions src/main/SubtitleListEditor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ const SubtitleListSegment = React.memo((props: subtitleListSegmentProps) => {
}
}, [cue.idInternal, dispatch, focusId2, focusTriggered2])

const updateCueText = (event: { target: { value: any } }) => {
const updateCueText = (event: React.ChangeEvent<HTMLTextAreaElement>) => {
dispatch(setCueAtIndex({
identifier: identifier,
cueIndex: props.index,
Expand All @@ -219,22 +219,22 @@ const SubtitleListSegment = React.memo((props: subtitleListSegmentProps) => {
}))
};

const updateCueStart = (event: { target: { value: any } }) => {
const updateCueStart = (value: number) => {
dispatch(setCueAtIndex({
identifier: identifier,
cueIndex: props.index,
newCue: {
id: cue.id,
idInternal: cue.idInternal,
text: cue.text,
startTime: event.target.value,
startTime: value,
endTime: cue.endTime,
tree: cue.tree
}
}))
};

const updateCueEnd = (event: { target: { value: any } }) => {
const updateCueEnd = (value: number) => {
dispatch(setCueAtIndex({
identifier: identifier,
cueIndex: props.index,
Expand All @@ -243,7 +243,7 @@ const SubtitleListSegment = React.memo((props: subtitleListSegmentProps) => {
idInternal: cue.idInternal,
text: cue.text,
startTime: cue.startTime,
endTime: event.target.value,
endTime: value,
tree: cue.tree
}
}))
Expand Down Expand Up @@ -461,8 +461,8 @@ const SubtitleListSegment = React.memo((props: subtitleListSegmentProps) => {
const FunctionButton : React.FC<{
tooltip: string,
tooltipAria: string,
onClick: any,
onKeyDown: any,
onClick: React.MouseEventHandler,
onKeyDown: React.KeyboardEventHandler,
Icon: IconType
}> = ({
tooltip,
Expand Down Expand Up @@ -502,7 +502,7 @@ const FunctionButton : React.FC<{
*/
const TimeInput : React.FC<{
value: number,
changeCallback: any,
changeCallback: (value: number) => void,
generalFieldStyle: SerializedStyles[],
tooltip: string,
tooltipAria: string,
Expand Down Expand Up @@ -531,7 +531,7 @@ const TimeInput : React.FC<{
};

// Update state in redux
const onBlur = (event: { target: { value: any; }; }) => {
const onBlur = (event: React.FocusEvent<HTMLInputElement>) => {
setParsingError(false)

// Parse value and pass it to parent
Expand All @@ -541,7 +541,7 @@ const TimeInput : React.FC<{
setParsingError(true)
return
}
changeCallback({ target: { value: milliseconds } });
changeCallback(milliseconds);

// Make sure to set state to the parsed value
const time = toHHMMSSMS(milliseconds);
Expand Down
3 changes: 2 additions & 1 deletion src/main/SubtitleSelect.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import { ThemeProvider } from '@mui/material/styles';
import { ThemedTooltip } from "./Tooltip";
import { languageCodeToName } from "../util/utilityFunctions";
import { v4 as uuidv4 } from 'uuid';
import { TFunction } from "i18next";

/**
* Displays buttons that allow the user to select the subtitle they want to edit
Expand Down Expand Up @@ -312,7 +313,7 @@ const SubtitleAddButton: React.FC<{
/**
* Generates a title for the buttons from the tags
*/
export function generateButtonTitle(tags: string[], t: any) {
export function generateButtonTitle(tags: string[], t: TFunction<"translation", undefined>) {
let lang = tags.find(e => e.startsWith('lang:'))
lang = lang ? lang.split(':')[1].trim() : undefined
lang = languageCodeToName(lang?.trim()) ?? lang
Expand Down
12 changes: 6 additions & 6 deletions src/main/SubtitleTimeline.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ import {
import { useDispatch, useSelector } from "react-redux";
import useResizeObserver from "use-resize-observer";
import { selectDuration } from "../redux/videoSlice";
import Draggable, { DraggableEvent } from "react-draggable";
import Draggable, { DraggableEventHandler } from "react-draggable";
import { SubtitleCue } from "../types";
import { Resizable } from "react-resizable";
import { Resizable, ResizableProps } from "react-resizable";
import "react-resizable/css/styles.css";
import ScrollContainer, { ScrollEvent } from "react-indiana-drag-scroll";
import { useTheme } from "../themes";
Expand Down Expand Up @@ -262,7 +262,7 @@ const TimelineSubtitleSegment: React.FC<{
// Resizable does not support resizing in the west/north directions out of the box,
// so additional calculations are necessary.
// Adapted from Resizable example code
const onResizeAbsolute = (_event: any, {size, handle}: any) => {
const onResizeAbsolute: ResizableProps["onResize"] = (_event, {size, handle}) => {
// Possible TODO: Find a way to stop resizing a segment beyond 0ms here instead of later
let newLeft = absoluteLeft;
let newTop = absoluteTop;
Expand All @@ -286,7 +286,7 @@ const TimelineSubtitleSegment: React.FC<{
};

// Update redux state based on the resize
const onResizeStop = (_event: any, {handle}: any) => {
const onResizeStop: ResizableProps["onResizeStop"] = (_event, {handle}) => {
// Calc new width, factoring in offset
const newWidth = absoluteWidth

Expand Down Expand Up @@ -315,11 +315,11 @@ const TimelineSubtitleSegment: React.FC<{
setAbsoluteTop(0)
}

const onStartDrag = (_e: DraggableEvent) => {
const onStartDrag: DraggableEventHandler = _e => {
setIsGrabbed(true)
}

const onStopDrag = (_e: DraggableEvent, position: any) => {
const onStopDrag: DraggableEventHandler = (_e, position) => {
// Update position and thereby start/end times in redux
const {x} = position
dispatchNewTimes(
Expand Down
56 changes: 28 additions & 28 deletions src/main/Thumbnail.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ const Thumbnail : React.FC = () => {
};

const discardThumbnail = (id: string) => {
dispatch(setThumbnail({ id: id, uri: originalThumbnails.find((e: any) => e.id === id)?.uri }))
dispatch(setThumbnail({ id: id, uri: originalThumbnails.find(e => e.id === id)?.uri }))
}

const thumbnailStyle = css({
Expand Down Expand Up @@ -138,11 +138,11 @@ const Thumbnail : React.FC = () => {
* A table for displaying thumbnails and associated actions
*/
const ThumbnailTable : React.FC<{
inputRefs: any,
generate: any,
upload: any,
uploadCallback: any,
discard: any,
inputRefs: React.MutableRefObject<(HTMLInputElement | null)[]>,
generate: (track: Track, index: number) => void,
upload: (index: number) => void,
uploadCallback: (event: React.ChangeEvent<HTMLInputElement>, track: Track) => void,
discard: (id: string) => void,
}> = ({inputRefs, generate, upload, uploadCallback, discard}) => {

const videoTracks = useSelector(selectVideos)
Expand Down Expand Up @@ -206,11 +206,11 @@ const ThumbnailTable : React.FC<{
const ThumbnailTableRow: React.FC<{
track: Track,
index: number,
inputRefs: any,
generate: any,
upload: any,
uploadCallback: any,
discard: any,
inputRefs: React.MutableRefObject<(HTMLInputElement | null)[]>,
generate: (track: Track, index: number) => void,
upload: (index: number) => void,
uploadCallback: (event: React.ChangeEvent<HTMLInputElement>, track: Track) => void,
discard: (id: string) => void,
}> = ({track, index, inputRefs, generate, upload, uploadCallback, discard}) => {

const { t } = useTranslation()
Expand Down Expand Up @@ -301,11 +301,11 @@ const ThumbnailDisplayer : React.FC<{track: Track}> = ({track}) => {
const ThumbnailButtons : React.FC<{
track: Track,
index: number,
inputRefs: any,
generate: any,
upload: any,
uploadCallback: any,
discard: any,
inputRefs: React.MutableRefObject<(HTMLInputElement | null)[]>,
generate: (track: Track, index: number) => void,
upload: (index: number) => void,
uploadCallback: (event: React.ChangeEvent<HTMLInputElement>, track: Track) => void,
discard: (id: string) => void,
}> = ({track, index, inputRefs, generate, upload, uploadCallback, discard}) => {

const { t } = useTranslation()
Expand Down Expand Up @@ -384,7 +384,7 @@ const ThumbnailButtons : React.FC<{
}

const ThumbnailButton : React.FC<{
handler: any,
handler: () => void,
text: string
tooltipText: string,
ariaLabel: string,
Expand Down Expand Up @@ -426,7 +426,7 @@ const ThumbnailButton : React.FC<{
*/
const AffectAllRow : React.FC<{
tracks: Track[]
generate: any
generate: (track: Track, index: number) => void
}> = ({generate, tracks}) => {

const { t } = useTranslation()
Expand Down Expand Up @@ -487,11 +487,11 @@ const AffectAllRow : React.FC<{
const ThumbnailTableSingleRow: React.FC<{
track: Track,
index: number,
inputRefs: any,
generate: any,
upload: any,
uploadCallback: any,
discard: any,
inputRefs: React.MutableRefObject<(HTMLInputElement | null)[]>,
generate: (track: Track, index: number) => void,
upload: (index: number) => void,
uploadCallback: (event: React.ChangeEvent<HTMLInputElement>, track: Track) => void,
discard: (id: string) => void,
}> = ({track, index, inputRefs, generate, upload, uploadCallback, discard}) => {
const { t } = useTranslation();
const theme = useTheme();
Expand Down Expand Up @@ -523,11 +523,11 @@ const ThumbnailTableSingleRow: React.FC<{
const ThumbnailButtonsSimple : React.FC<{
track: Track,
index: number,
inputRefs: any,
generate: any,
upload: any,
uploadCallback: any,
discard: any,
inputRefs: React.MutableRefObject<(HTMLInputElement | null)[]>,
generate: (track: Track, index: number) => void,
upload: (index: number) => void,
uploadCallback: (event: React.ChangeEvent<HTMLInputElement>, track: Track) => void,
discard: (id: string) => void,
}> = ({track, index, generate, inputRefs, upload, uploadCallback, discard}) => {

const { t } = useTranslation()
Expand Down
8 changes: 4 additions & 4 deletions src/main/Timeline.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React, { useState, useRef, useEffect } from 'react'

import Draggable from 'react-draggable';
import Draggable, { DraggableEventHandler } from 'react-draggable';

import { css } from '@emotion/react'

Expand Down Expand Up @@ -144,7 +144,7 @@ export const Scrubber: React.FC<{
}, [timelineWidth])

// Callback for when the scrubber gets dragged by the user
const onControlledDrag = (_e: any, position: any) => {
const onControlledDrag: DraggableEventHandler = (_e, position) => {
// Update position
const {x} = position
dispatch(setCurrentlyAt((x / timelineWidth) * (duration)))
Expand All @@ -155,7 +155,7 @@ export const Scrubber: React.FC<{
setControlledPosition({x: (currentlyAt / duration) * (timelineWidth), y: 0});
};

const onStartDrag = () => {
const onStartDrag: DraggableEventHandler = () => {
setIsGrabbed(true)

// Halt video playback
Expand All @@ -167,7 +167,7 @@ export const Scrubber: React.FC<{
}
}

const onStopDrag = (_e: any, position: any) => {
const onStopDrag: DraggableEventHandler = (_e, position) => {
// Update position
const {x} = position;
setControlledPosition({x, y: 0});
Expand Down
2 changes: 1 addition & 1 deletion src/main/TrackSelection.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ const TrackItem: React.FC<{track: Track, enabledCount: number}> = ({track, enabl
}

interface selectButtonInterface {
handler: any,
handler: () => void,
text: string,
Icon: IconType | React.FunctionComponent,
tooltip: string,
Expand Down
7 changes: 4 additions & 3 deletions src/main/VideoPlayers.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,9 @@ import { ActionCreatorWithPayload } from "@reduxjs/toolkit";
import { useTheme } from "../themes";

import { backgroundBoxStyle, flexGapReplacementStyle } from '../cssStyles'
import { BaseReactPlayerProps } from "react-player/base";

const VideoPlayers: React.FC<{refs: any, widthInPercent?: number}> = ({refs, widthInPercent = 100}) => {
const VideoPlayers: React.FC<{refs?: React.MutableRefObject<any>, widthInPercent?: number}> = ({refs, widthInPercent = 100}) => {

const videoURLs = useSelector(selectVideoURL)
const videoCount = useSelector(selectVideoCount)
Expand Down Expand Up @@ -102,7 +103,7 @@ export const VideoPlayer = React.forwardRef(
setIsPlaying: ActionCreatorWithPayload<boolean, string>,
setPreviewTriggered: ActionCreatorWithPayload<any, string>,
setClickTriggered: ActionCreatorWithPayload<any, string>,
setCurrentlyAt: any,
setCurrentlyAt: ActionCreatorWithPayload<number, string>,
setAspectRatio: ActionCreatorWithPayload<{dataKey: number} & {width: number, height: number}, string>,
},
forwardRefThing
Expand Down Expand Up @@ -200,7 +201,7 @@ export const VideoPlayer = React.forwardRef(
}
}

const onErrorCallback = (_e: any) => {
const onErrorCallback: BaseReactPlayerProps["onError"] = _e => {
setError(true)
}

Expand Down
6 changes: 3 additions & 3 deletions src/redux/subtitleSlice.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Segment, SubtitleCue, SubtitlesInEditor } from './../types';
import { createSlice, Dispatch, nanoid, PayloadAction } from '@reduxjs/toolkit'
import { createSlice, nanoid, PayloadAction } from '@reduxjs/toolkit'
import { roundToDecimalPlace } from '../util/utilityFunctions';
import type { RootState } from '../redux/store'
import type { AppDispatch, RootState } from '../redux/store'
import { video } from './videoSlice';

export interface subtitle {
Expand Down Expand Up @@ -228,7 +228,7 @@ export const selectHasChanges = (state: { subtitleState: { hasChanges: subtitle[
* mode is active.
*/
export function setCurrentlyAtAndTriggerPreview(milliseconds: number) {
return (dispatch: Dispatch, getState: any) => {
return (dispatch: AppDispatch, getState: () => RootState) => {
milliseconds = roundToDecimalPlace(milliseconds, 0);

if (milliseconds < 0) {
Expand Down

0 comments on commit ec807c9

Please sign in to comment.