From 85a7b54a1331eeafae3e8e11200b731dd98552b1 Mon Sep 17 00:00:00 2001 From: Thomas Ruoff Date: Sun, 14 Feb 2021 22:47:44 +0100 Subject: [PATCH] drop some types in --- components/Button.tsx | 6 +++--- components/Header.tsx | 2 +- components/Input.tsx | 24 ++++++++++++++++++------ components/LatestList.tsx | 24 ++++++++++++++++++------ components/Layout.tsx | 4 ++-- components/LetterOptions.tsx | 7 ++++++- components/Preview.tsx | 20 ++++++++++++++------ components/Select.tsx | 20 +++++++++++++++----- components/TextAreaInput.tsx | 23 +++++++++++++++-------- components/apiHelper.tsx | 4 +++- components/index.tsx | 6 ------ interfaces/IDocProps.tsx | 15 +++++++++++++++ interfaces/ILatest.tsx | 6 ++++++ 13 files changed, 116 insertions(+), 45 deletions(-) delete mode 100644 components/index.tsx create mode 100644 interfaces/IDocProps.tsx create mode 100644 interfaces/ILatest.tsx diff --git a/components/Button.tsx b/components/Button.tsx index 1e42435..e647bfe 100644 --- a/components/Button.tsx +++ b/components/Button.tsx @@ -1,9 +1,9 @@ import React from 'react' -export default function (props) { +export default function Button({ children, onClick }: { children: React.ReactNode; onClick: () => void }) { return ( - ) } diff --git a/components/Header.tsx b/components/Header.tsx index 0bbadb6..6fb7149 100644 --- a/components/Header.tsx +++ b/components/Header.tsx @@ -1,6 +1,6 @@ import React from 'react' -export default function () { +export default function Header() { return (

PDFer

diff --git a/components/Input.tsx b/components/Input.tsx index 5002eae..8aeac7a 100644 --- a/components/Input.tsx +++ b/components/Input.tsx @@ -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 ( ) diff --git a/components/LatestList.tsx b/components/LatestList.tsx index 09cacb6..723b9d5 100644 --- a/components/LatestList.tsx +++ b/components/LatestList.tsx @@ -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 (
  • - props.onSelect(item)}> - {created.toLocaleString()} + onSelect(item)}> +
    {subject}
    +
    {created.toLocaleDateString()}
    - - +
  • ) }) diff --git a/components/Layout.tsx b/components/Layout.tsx index c1318b5..90a43b3 100644 --- a/components/Layout.tsx +++ b/components/Layout.tsx @@ -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 (
    -
    {props.children}
    +
    {children}
    ) } diff --git a/components/LetterOptions.tsx b/components/LetterOptions.tsx index eec156f..bb083bc 100644 --- a/components/LetterOptions.tsx +++ b/components/LetterOptions.tsx @@ -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', diff --git a/components/Preview.tsx b/components/Preview.tsx index 8e0cced..96bca0c 100644 --- a/components/Preview.tsx +++ b/components/Preview.tsx @@ -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
    Lade…
    } @@ -12,18 +20,18 @@ export default (props) => { borderRadius: '3px', } - if (props.pdfError) { + if (pdfError) { return (
    😢 {' '} - {props.pdfError} + {pdfError}
    ) } - if (!props.pdfUrl) { + if (!pdfUrl) { return
    Knopf drücken dann gibts hier was zu sehen!
    } @@ -32,5 +40,5 @@ export default (props) => { height: '1050px', } - return + return } diff --git a/components/Select.tsx b/components/Select.tsx index f14c694..2059c93 100644 --- a/components/Select.tsx +++ b/components/Select.tsx @@ -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 (