Conversation
| readonly contacts: {}; | ||
| } | ||
|
|
||
| export const SimpleModal: React.SFC<Props> = ({firstName, lastName, email, phoneNumber, isOpen, handleClose}) => { |
There was a problem hiding this comment.
Soubor by se mel jmenovat jako komponenta, tedy SimpleModal.tsx
| import * as React from 'react'; | ||
| import {WithAdminProps} from '@client/with/withAdmin'; | ||
| import {Paper, Table, TableHead, TableRow, TableCell, TableBody, Button} from '../../../../node_modules/@material-ui/core'; | ||
| import AddIcon from '@material-ui/icons/Add'; |
There was a problem hiding this comment.
Ikony jdou importovat i takto:
import {Add, Delete as DeleteIcon} from '@material-ui/icons'| @@ -1,8 +1,107 @@ | |||
| import * as React from 'react'; | |||
| import {WithAdminProps} from '@client/with/withAdmin'; | |||
| import {Paper, Table, TableHead, TableRow, TableCell, TableBody, Button} from '../../../../node_modules/@material-ui/core'; | |||
There was a problem hiding this comment.
tady je spatne import, mel by byt:
import {...} from '@material-ui/core'| }, | ||
| }; | ||
| const initialState = { | ||
| contacts: [ |
There was a problem hiding this comment.
Tohle je fajn, akorat ti chybi datovy typ pro kontakty:
interface ContactModel {
id: number;
firstName: string;
lastName: string;
email: string;
// tady by teoreticky mohlo bbyt cislo i string; TS ma moznost napsat takto, ze promenna muze byt dvou datovych typu
phoneNumber: number | string;
}
const initialState = {
contacts: [...] as ContactModel[]
}| export class UsersIndexPage extends React.Component<WithAdminProps, typeof initialState> { | ||
| readonly state = initialState; | ||
|
|
||
| handleOpen = () => { |
There was a problem hiding this comment.
ty handle metody by mely byt psany jako: handleOn..., tedy handleOnOpen, handleOnClose, apod
| <Button variant="fab" color="primary" aria-label="Add" mini style={styles.button} onClick={this.handleOpen}> | ||
| <AddIcon /> | ||
| </Button> | ||
| <SimpleModal isOpen={isOpen} handleClose={this.handleClose} contacts={contacts} /> |
There was a problem hiding this comment.
Tohle ti hlasi chybu, protoze SimpleModal ma na props toto:
interface Props {
readonly isOpen: boolean;
readonly handleClose: () => void;
readonly firstName: string;
readonly lastName: string;
readonly email: string;
readonly phoneNumber: number;
readonly children?: React.ReactNode;
readonly contacts: {};
}V tom pripade bys tady musel mit toto:
<SimpleModal isOpen={isOpen} handleClose={this.handleClose} contacts={contacts} firstName="" lastName="" ... />Tedy dopsat ostatni. Ale lepsi je to udelat pres vnoreny objekt, viz komentar u modal.tsx u props
|
|
||
| export const SimpleModal: React.SFC<Props> = ({firstName, lastName, email, phoneNumber, isOpen, handleClose}) => { | ||
| return ( | ||
| <div> |
There was a problem hiding this comment.
Ten div uz tady nepotrebujes, pokud nepocitas, ze krome modal okna zde nebude jeste neco jineho
| import TextField from '../../../../node_modules/@material-ui/core/TextField'; | ||
| import Button from '../../../../node_modules/@material-ui/core/Button'; | ||
|
|
||
| interface Props { |
There was a problem hiding this comment.
Ten props bych napsal jinak. Mas tady rozebrane jednotlive atributy uzivatele, coz by se dalo napsat radeji takto:
interface Props {
readonly isOpen: boolean;
readonly handleClose: () => void;
// jednotlive atributy bych dal do vlastniho objektu
readonly firstName: string;
readonly lastName: string;
readonly email: string;
readonly phoneNumber: number;
// children uz nepotrebujes, pridava ho samotny typ React.SFC
readonly children?: React.ReactNode;
// ContactModel je v druhem souboru, takze bud to dat do vlastniho a nebo v nem musis mit export
readonly contacts: {};
}
// vysledek
interface UserModel {
readonly id: number;
readonly firstName: string;
readonly lastName: string;
readonly email: string;
readonly phoneNumber: number;
}
interface Props {
readonly isOpen: boolean;
readonly handleClose: () => void;
// pouzijes UserModel a Pick, ktery vynecha povinne ID, ktere tady nechces
readonly user: Pick<UserModel, 'id'>;
readonly contacts: ContactModel[];
}na strane JSX pouziti to bude takto:
<SimpleModal isOpen={isOpen} handleClose={this.handleClose} contacts={contacts} user={user} />ten user nekde musis inicializovat, takze bud tady a nebo az v SimpleModal, cimz ho pak nepotrebujes vubec jako atribut od parenta UsersIndexPage.tsx
| interface Props { | ||
| contacts: ContactModel[]; | ||
| deleteContact: (id: number) => () => void; | ||
| handleOnId: (id: number) => () => void; |
There was a problem hiding this comment.
Tenhle nazev moc nerika, co vlastne dela. Chtelo by to jiny. Navic se to pouziva tak, ze v props, coz jde do atributu je to takto: onClick, onClickEdit, onClickDelete, apod. V pripade implementace se pak pouziva nazev: handleOnClickDelete, apod.
|
|
||
| interface Props { | ||
| contact: ContactModel; | ||
| deleteContact: (id: number) => () => void; |
There was a problem hiding this comment.
Tady bys nemel potrebovat funkci, co vraci funkci
No description provided.