mirror of
https://github.com/tomru/pdfer.git
synced 2026-03-03 06:27:19 +01:00
drop some types in
This commit is contained in:
@@ -1,9 +1,9 @@
|
||||
import React from 'react'
|
||||
|
||||
export default function (props) {
|
||||
export default function Button({ children, onClick }: { children: React.ReactNode; onClick: () => void }) {
|
||||
return (
|
||||
<button className="p-button" onClick={props.onClick}>
|
||||
{props.children}
|
||||
<button className="p-button" onClick={onClick}>
|
||||
{children}
|
||||
</button>
|
||||
)
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import React from 'react'
|
||||
|
||||
export default function () {
|
||||
export default function Header() {
|
||||
return (
|
||||
<header className="header">
|
||||
<h1>PDFer</h1>
|
||||
|
||||
@@ -1,15 +1,27 @@
|
||||
import React from 'react'
|
||||
|
||||
export default function (props) {
|
||||
export default function Input({
|
||||
text,
|
||||
name,
|
||||
value,
|
||||
placeholder,
|
||||
onchange,
|
||||
}: {
|
||||
text: string
|
||||
name: string
|
||||
value: string
|
||||
placeholder: string
|
||||
onchange: () => void
|
||||
}) {
|
||||
return (
|
||||
<label>
|
||||
{props.text}
|
||||
{text}
|
||||
<input
|
||||
className={props.name}
|
||||
className={name}
|
||||
type="text"
|
||||
placeholder={props.placeholder}
|
||||
onChange={props.onchange.bind(null, props.name)}
|
||||
value={props.value}
|
||||
placeholder={placeholder}
|
||||
onChange={onchange.bind(null, name)}
|
||||
value={value}
|
||||
/>
|
||||
</label>
|
||||
)
|
||||
|
||||
@@ -1,18 +1,30 @@
|
||||
import React from 'react'
|
||||
import { ILatest } from '../interfaces/ILatest'
|
||||
import Button from './Button'
|
||||
|
||||
export default function (props) {
|
||||
const latest = props.latest || []
|
||||
export default function LatestList({
|
||||
latest,
|
||||
onSelect,
|
||||
onRemove,
|
||||
}: {
|
||||
latest: ILatest[]
|
||||
onSelect: (l: ILatest) => void
|
||||
onRemove: (l: ILatest) => void
|
||||
}) {
|
||||
if (!latest || !latest.length) {
|
||||
return null
|
||||
}
|
||||
const latestElements = latest.map((item) => {
|
||||
const created = new Date(item.created)
|
||||
const subject = item.subject
|
||||
const hrefId = `#item-${item.id}`
|
||||
return (
|
||||
<li key={item.id}>
|
||||
<a href={hrefId} onClick={() => props.onSelect(item)}>
|
||||
{created.toLocaleString()}
|
||||
<a href={hrefId} onClick={() => onSelect(item)}>
|
||||
<div>{subject}</div>
|
||||
<div>{created.toLocaleDateString()}</div>
|
||||
</a>
|
||||
<span> </span>
|
||||
<Button onClick={() => props.onRemove(item)}>Remove</Button>
|
||||
<Button onClick={() => onRemove(item)}>Remove</Button>
|
||||
</li>
|
||||
)
|
||||
})
|
||||
|
||||
@@ -2,11 +2,11 @@ import React from 'react'
|
||||
|
||||
import Header from './Header'
|
||||
|
||||
export default function (props) {
|
||||
export default function Layout({ children }: { children: React.ReactNode }) {
|
||||
return (
|
||||
<div id="app">
|
||||
<Header />
|
||||
<div id="content">{props.children}</div>
|
||||
<div id="content">{children}</div>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
@@ -4,12 +4,17 @@ import Collapsible from 'react-collapsible'
|
||||
import Input from './Input'
|
||||
import TextAreaInput from './TextAreaInput'
|
||||
import Select from './Select'
|
||||
import { IDocProps } from '../interfaces/IDocProps'
|
||||
|
||||
//import './LetterOptions.css';
|
||||
|
||||
const EXAMPLE_ADDRESS = 'Max Mustermann\nMusterstr. 73\n12345 Musterstadt'
|
||||
|
||||
export default function (props) {
|
||||
interface IProps extends IDocProps {
|
||||
onChange: () => void
|
||||
}
|
||||
|
||||
export default function LetterOptions(props: IProps) {
|
||||
const templateTypeOptions = [
|
||||
{
|
||||
value: 'brief-fam',
|
||||
|
||||
@@ -1,7 +1,15 @@
|
||||
import React from 'react'
|
||||
|
||||
export default (props) => {
|
||||
if (props.pdfIsLoading) {
|
||||
export default function Preview({
|
||||
pdfIsLoading,
|
||||
pdfError,
|
||||
pdfUrl,
|
||||
}: {
|
||||
pdfIsLoading: boolean
|
||||
pdfError: string
|
||||
pdfUrl: string
|
||||
}) {
|
||||
if (pdfIsLoading) {
|
||||
return <div>Lade…</div>
|
||||
}
|
||||
|
||||
@@ -12,18 +20,18 @@ export default (props) => {
|
||||
borderRadius: '3px',
|
||||
}
|
||||
|
||||
if (props.pdfError) {
|
||||
if (pdfError) {
|
||||
return (
|
||||
<div style={errorStyles}>
|
||||
<span role="img" aria-label="Crying Man">
|
||||
😢
|
||||
</span>{' '}
|
||||
{props.pdfError}
|
||||
{pdfError}
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
if (!props.pdfUrl) {
|
||||
if (!pdfUrl) {
|
||||
return <div>Knopf drücken dann gibts hier was zu sehen!</div>
|
||||
}
|
||||
|
||||
@@ -32,5 +40,5 @@ export default (props) => {
|
||||
height: '1050px',
|
||||
}
|
||||
|
||||
return <embed src={props.pdfUrl} style={styles} type="application/pdf" />
|
||||
return <embed src={pdfUrl} style={styles} type="application/pdf" />
|
||||
}
|
||||
|
||||
@@ -1,12 +1,22 @@
|
||||
import React from 'react'
|
||||
|
||||
export default (props) => {
|
||||
const { options = [] } = props
|
||||
|
||||
export default function Select({
|
||||
name,
|
||||
text,
|
||||
value,
|
||||
onchange,
|
||||
options = [],
|
||||
}: {
|
||||
name: string
|
||||
text: string
|
||||
value: string
|
||||
onchange: () => void
|
||||
options: { name: string; value: string }[]
|
||||
}) {
|
||||
return (
|
||||
<label>
|
||||
{props.text}
|
||||
<select className={props.name} onChange={props.onchange.bind(null, props.name)} value={props.value}>
|
||||
{text}
|
||||
<select className={name} onChange={onchange.bind(null, name)} value={value}>
|
||||
{options.map((option) => (
|
||||
<option value={option.value} key={option.value}>
|
||||
{option.name}
|
||||
|
||||
@@ -1,15 +1,22 @@
|
||||
import React from 'react'
|
||||
|
||||
export default function (props) {
|
||||
export default function TextAreaInput({
|
||||
text,
|
||||
name,
|
||||
placeholder,
|
||||
onchange,
|
||||
value,
|
||||
}: {
|
||||
text: string
|
||||
name: string
|
||||
placeholder: string
|
||||
onchange: () => void
|
||||
value: string
|
||||
}) {
|
||||
return (
|
||||
<label>
|
||||
{props.text}
|
||||
<textarea
|
||||
className={props.name}
|
||||
placeholder={props.placeholder}
|
||||
onChange={props.onchange.bind(null, props.name)}
|
||||
value={props.value}
|
||||
/>
|
||||
{text}
|
||||
<textarea className={name} placeholder={placeholder} onChange={onchange.bind(null, name)} value={value} />
|
||||
</label>
|
||||
)
|
||||
}
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
import { ILatest } from '../interfaces/ILatest'
|
||||
|
||||
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!`)
|
||||
@@ -18,7 +20,7 @@ export async function generatePdf(state: Record<string, string>) {
|
||||
return response.json()
|
||||
}
|
||||
|
||||
export async function getLatest() {
|
||||
export async function getLatest(): Promise<ILatest[]> {
|
||||
const response = await fetch('/api/pdf/latest')
|
||||
checkStatus(response)
|
||||
return response.json()
|
||||
|
||||
@@ -1,6 +0,0 @@
|
||||
import React from 'react'
|
||||
import ReactDOM from 'react-dom'
|
||||
import App from './App'
|
||||
import './index.css'
|
||||
|
||||
ReactDOM.render(<App />, document.getElementById('root'))
|
||||
Reference in New Issue
Block a user