mirror of
https://github.com/tomru/pdfer.git
synced 2026-03-03 06:27:19 +01:00
fix some type errors
This commit is contained in:
@@ -13,7 +13,7 @@ class App extends Component {
|
||||
}
|
||||
|
||||
render() {
|
||||
const state = this.state || {}
|
||||
const state: Record<string, unknown> = this.state || {}
|
||||
|
||||
return (
|
||||
<div className="home">
|
||||
|
||||
@@ -1,19 +0,0 @@
|
||||
import * as React from 'react'
|
||||
import ListItem from './ListItem'
|
||||
import { User } from '../interfaces'
|
||||
|
||||
type Props = {
|
||||
items: User[]
|
||||
}
|
||||
|
||||
const List = ({ items }: Props) => (
|
||||
<ul>
|
||||
{items.map((item) => (
|
||||
<li key={item.id}>
|
||||
<ListItem data={item} />
|
||||
</li>
|
||||
))}
|
||||
</ul>
|
||||
)
|
||||
|
||||
export default List
|
||||
@@ -1,16 +0,0 @@
|
||||
import * as React from 'react'
|
||||
|
||||
import { User } from '../interfaces'
|
||||
|
||||
type ListDetailProps = {
|
||||
item: User
|
||||
}
|
||||
|
||||
const ListDetail = ({ item: user }: ListDetailProps) => (
|
||||
<div>
|
||||
<h1>Detail for {user.name}</h1>
|
||||
<p>ID: {user.id}</p>
|
||||
</div>
|
||||
)
|
||||
|
||||
export default ListDetail
|
||||
@@ -1,18 +0,0 @@
|
||||
import React from 'react'
|
||||
import Link from 'next/link'
|
||||
|
||||
import { User } from '../interfaces'
|
||||
|
||||
type Props = {
|
||||
data: User
|
||||
}
|
||||
|
||||
const ListItem = ({ data }: Props) => (
|
||||
<Link href="/users/[id]" as={`/users/${data.id}`}>
|
||||
<a>
|
||||
{data.id}: {data.name}
|
||||
</a>
|
||||
</Link>
|
||||
)
|
||||
|
||||
export default ListItem
|
||||
@@ -1,12 +1,10 @@
|
||||
function checkStatus(res) {
|
||||
function checkStatus(res: Response) {
|
||||
if (res.status < 200 || res.status >= 400) {
|
||||
throw new Error(`Something went wrong (Status ${res.status}) - I do feel very sorry!`)
|
||||
}
|
||||
|
||||
return res
|
||||
}
|
||||
|
||||
export function generatePdf(state) {
|
||||
export async function generatePdf(state: Record<string, string>) {
|
||||
const options = {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
@@ -15,17 +13,19 @@ export function generatePdf(state) {
|
||||
body: JSON.stringify(state),
|
||||
}
|
||||
|
||||
return fetch('/api/pdf/generate/brief', options)
|
||||
.then(checkStatus)
|
||||
.then((res) => res.json())
|
||||
const response = await fetch('/api/pdf/generate/brief', options)
|
||||
checkStatus(response)
|
||||
return response.json()
|
||||
}
|
||||
|
||||
export function getLatest() {
|
||||
return fetch('/api/pdf/latest')
|
||||
.then(checkStatus)
|
||||
.then((res) => res.json())
|
||||
export async function getLatest() {
|
||||
const response = await fetch('/api/pdf/latest')
|
||||
checkStatus(response)
|
||||
return response.json()
|
||||
}
|
||||
|
||||
export function removeLatest(item) {
|
||||
return fetch(`/api/pdf/latest/${item.id}`, { method: 'DELETE' }).then(checkStatus)
|
||||
export async function removeLatest(item: { id: string }) {
|
||||
const response = await fetch(`/api/pdf/latest/${item.id}`, { method: 'DELETE' })
|
||||
checkStatus(response)
|
||||
return response
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user