Skip to content

Commit

Permalink
Remove redundant type annotations
Browse files Browse the repository at this point in the history
The types are now inferred correctly by the compiler, so the annotations are no longer necessary.
  • Loading branch information
markborkum committed Feb 12, 2025
1 parent 214c679 commit 075c048
Show file tree
Hide file tree
Showing 10 changed files with 92 additions and 141 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,7 @@ const InstallationListGroup: React.FC<InstallationListGroupProps> = ({
children,
}) => {
const handleEdit = useCallback(
async (
event: React.MouseEvent<HTMLButtonElement>,
): Promise<boolean> => {
async (event: React.MouseEvent<HTMLButtonElement>) => {
event.stopPropagation()
event.preventDefault()

Expand All @@ -31,9 +29,7 @@ const InstallationListGroup: React.FC<InstallationListGroupProps> = ({
)

const handleDelete = useCallback(
async (
event: React.MouseEvent<HTMLButtonElement>,
): Promise<boolean> => {
async (event: React.MouseEvent<HTMLButtonElement>) => {
event.stopPropagation()
event.preventDefault()

Expand Down
17 changes: 6 additions & 11 deletions src/components/views/projects/list/export_document.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,9 @@ import { Button } from 'react-bootstrap'
import { TfiImport } from 'react-icons/tfi'

import { useDatabase } from '../../../../providers/database_provider'
import { type Base, type Project } from '../../../../types/database.types'
import { sendBlob } from '../../../../utilities/blob_utils'
import { getProject } from '../../../../utilities/database_utils'
import {
type JSONDocument,
JSON_DOCUMENT_CONTENT_TYPE,
JSON_DOCUMENT_FILE_EXTENSION,
exportJSONDocument,
Expand All @@ -19,25 +17,22 @@ interface ExportDocProps {
}

const ExportDoc: React.FC<ExportDocProps> = ({ projectId }) => {
const db: PouchDB.Database<Base> = useDatabase()
const db = useDatabase()

const handleClick = useCallback(
async (
event: React.MouseEvent<HTMLButtonElement>,
): Promise<boolean> => {
async (event: React.MouseEvent<HTMLButtonElement>) => {
event.stopPropagation()
event.preventDefault()

const projectDoc: PouchDB.Core.Document<Project> &
PouchDB.Core.GetMeta = await getProject(db, projectId)
const projectDoc = await getProject(db, projectId)

const data: JSONDocument = await exportJSONDocument(db, projectId)
const data = await exportJSONDocument(db, projectId)

const blob: Blob = new Blob([JSON.stringify(data)], {
const blob = new Blob([JSON.stringify(data)], {
type: JSON_DOCUMENT_CONTENT_TYPE,
})

const fileName: string = `${projectDoc.metadata_.doc_name} ${new Date().toUTCString()}${JSON_DOCUMENT_FILE_EXTENSION}`
const fileName = `${projectDoc.metadata_.doc_name} ${new Date().toUTCString()}${JSON_DOCUMENT_FILE_EXTENSION}`

sendBlob(blob, fileName)

Expand Down
17 changes: 7 additions & 10 deletions src/components/views/projects/list/import_document.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import React, { useCallback, useMemo, useRef, useState } from 'react'
import { Button } from 'react-bootstrap'

import { useDatabase } from '../../../../providers/database_provider'
import { type Base } from '../../../../types/database.types'
import {
type JSONDocument,
JSON_DOCUMENT_FILE_EXTENSION,
Expand All @@ -16,22 +15,20 @@ interface ImportDocProps {
}

const ImportDoc: React.FC<ImportDocProps> = ({ label, onImport }) => {
const db: PouchDB.Database<Base> = useDatabase()
const db = useDatabase()

const ref = useRef<HTMLInputElement>(null)

const [error, setError] = useState<string | undefined>(undefined)

const reader = useMemo<FileReader>(() => {
const _reader: FileReader = new FileReader()
const _reader = new FileReader()

_reader.onload = async (
event: ProgressEvent<FileReader>,
): Promise<void> => {
const text: string = (event.target as FileReader).result as string
_reader.onload = async (event: ProgressEvent<FileReader>) => {
const text = (event.target as FileReader).result as string

try {
const data: JSONDocument = JSON.parse(text)
const data = JSON.parse(text)

try {
const [projectResponse, installationResponses] =
Expand All @@ -56,9 +53,9 @@ const ImportDoc: React.FC<ImportDocProps> = ({ label, onImport }) => {
}, [])

const handleChange = useCallback(
async (event: React.ChangeEvent<HTMLInputElement>): Promise<void> => {
async (event: React.ChangeEvent<HTMLInputElement>) => {
if (event.target.files) {
const file: File = event.target.files[0]
const file = event.target.files[0]

if (file) {
if (file.name.endsWith(JSON_DOCUMENT_FILE_EXTENSION)) {
Expand Down
12 changes: 3 additions & 9 deletions src/components/views/projects/list/project_list_group.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,7 @@ const ProjectListGroup: React.FC<ProjectListGroupProps> = ({
onSelect,
}) => {
const handleEdit = useCallback(
async (
event: React.MouseEvent<HTMLButtonElement>,
): Promise<boolean> => {
async (event: React.MouseEvent<HTMLButtonElement>) => {
event.stopPropagation()
event.preventDefault()

Expand All @@ -36,9 +34,7 @@ const ProjectListGroup: React.FC<ProjectListGroupProps> = ({
)

const handleDelete = useCallback(
async (
event: React.MouseEvent<HTMLButtonElement>,
): Promise<boolean> => {
async (event: React.MouseEvent<HTMLButtonElement>) => {
event.stopPropagation()
event.preventDefault()

Expand All @@ -50,9 +46,7 @@ const ProjectListGroup: React.FC<ProjectListGroupProps> = ({
)

const handleSelect = useCallback(
async (
event: React.MouseEvent<HTMLButtonElement>,
): Promise<boolean> => {
async (event: React.MouseEvent<HTMLButtonElement>) => {
event.stopPropagation()
event.preventDefault()

Expand Down
6 changes: 3 additions & 3 deletions src/components/views/projects/show/templates_list_group.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,17 +32,17 @@ const TemplatesListGroup: React.FC<TemplatesListGroupProps> = ({
}, new Map())
}, [installations])

const workflowNames: Array<keyof typeof TEMPLATES> = Object.keys(TEMPLATES)
const workflowNames = Object.keys(TEMPLATES)

if (workflowNames.length === 0) {
return null
} else {
return (
<ListGroup>
{workflowNames.map(workflowName => {
const workflowTitle: string = TEMPLATES[workflowName].title
const workflowTitle = TEMPLATES[workflowName].title

const installationDocsCount: number =
const installationDocsCount =
installationsByWorkflowName.get(workflowName)?.length ??
0

Expand Down
10 changes: 3 additions & 7 deletions src/components/views/shared/delete_confirmation_modal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,7 @@ const DeleteConfirmationModal: React.FC<DeleteConfirmationModalProps> = ({
onHide,
}) => {
const handleCancel = useCallback(
async (
event: React.MouseEvent<HTMLButtonElement>,
): Promise<boolean> => {
async (event: React.MouseEvent<HTMLButtonElement>) => {
event.stopPropagation()
event.preventDefault()

Expand All @@ -31,9 +29,7 @@ const DeleteConfirmationModal: React.FC<DeleteConfirmationModalProps> = ({
)

const handleConfirm = useCallback(
async (
event: React.MouseEvent<HTMLButtonElement>,
): Promise<boolean> => {
async (event: React.MouseEvent<HTMLButtonElement>) => {
event.stopPropagation()
event.preventDefault()

Expand All @@ -44,7 +40,7 @@ const DeleteConfirmationModal: React.FC<DeleteConfirmationModalProps> = ({
[onConfirm],
)

const handleHide = useCallback(async (): Promise<void> => {
const handleHide = useCallback(async () => {
onHide && (await onHide())
}, [onHide])

Expand Down
14 changes: 5 additions & 9 deletions src/components/views/shared/string_input_modal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,7 @@ const StringInputModal: React.FC<StringInputModalProps> = ({
}, [value, validators])

const handleCancel = useCallback(
async (
event: React.MouseEvent<HTMLButtonElement>,
): Promise<boolean> => {
async (event: React.MouseEvent<HTMLButtonElement>) => {
event.stopPropagation()
event.preventDefault()

Expand All @@ -49,16 +47,14 @@ const StringInputModal: React.FC<StringInputModalProps> = ({
)

const handleChange = useCallback(
async (event: React.ChangeEvent<HTMLInputElement>): Promise<void> => {
async (event: React.ChangeEvent<HTMLInputElement>) => {
onChange && (await onChange(event.target.value))
},
[onChange],
)

const handleConfirm = useCallback(
async (
event: React.MouseEvent<HTMLButtonElement>,
): Promise<boolean> => {
async (event: React.MouseEvent<HTMLButtonElement>) => {
event.stopPropagation()
event.preventDefault()

Expand All @@ -69,12 +65,12 @@ const StringInputModal: React.FC<StringInputModalProps> = ({
[onConfirm],
)

const handleHide = useCallback(async (): Promise<void> => {
const handleHide = useCallback(async () => {
onHide && (await onHide())
}, [onHide])

const handleKeyUp = useCallback(
async (event: React.KeyboardEvent<HTMLInputElement>): Promise<void> => {
async (event: React.KeyboardEvent<HTMLInputElement>) => {
if (event.key === 'Enter' && errorMessages.length === 0) {
onConfirm && (await onConfirm())
}
Expand Down
2 changes: 1 addition & 1 deletion src/utilities/blob_utils.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
export function sendBlob(blob: Blob, fileName: string): void {
const url: string = URL.createObjectURL(blob)
const url = URL.createObjectURL(blob)

const el: HTMLAnchorElement = document.createElement('a')

Expand Down
32 changes: 12 additions & 20 deletions src/utilities/comparison_utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,41 +14,33 @@ export function comparator<T extends Base>(
case 'created_at':
switch (order) {
case 'asc':
return (a: T, b: T): number => {
const aDate: Date = new Date(a.metadata_.created_at)
const bDate: Date = new Date(b.metadata_.created_at)
return (a, b) => {
const aDate = new Date(a.metadata_.created_at)
const bDate = new Date(b.metadata_.created_at)

return aDate.getTime() - bDate.getTime()
}
case 'desc':
return (a: T, b: T): number => {
const aDate: Date = new Date(a.metadata_.created_at)
const bDate: Date = new Date(b.metadata_.created_at)
return (a, b) => {
const aDate = new Date(a.metadata_.created_at)
const bDate = new Date(b.metadata_.created_at)

return bDate.getTime() - aDate.getTime()
}
}
case 'last_modified_at':
switch (order) {
case 'asc':
return (a: T, b: T): number => {
const aDate: Date = new Date(
a.metadata_.last_modified_at,
)
const bDate: Date = new Date(
b.metadata_.last_modified_at,
)
return (a, b) => {
const aDate = new Date(a.metadata_.last_modified_at)
const bDate = new Date(b.metadata_.last_modified_at)

return aDate.getTime() - bDate.getTime()
}
case 'desc':
return (a: T, b: T): number => {
const aDate: Date = new Date(
a.metadata_.last_modified_at,
)
const bDate: Date = new Date(
b.metadata_.last_modified_at,
)
return (a, b) => {
const aDate = new Date(a.metadata_.last_modified_at)
const bDate = new Date(b.metadata_.last_modified_at)

return bDate.getTime() - aDate.getTime()
}
Expand Down
Loading

0 comments on commit 075c048

Please sign in to comment.