clean up step 2-2

This commit is contained in:
Ken
2019-02-15 13:49:22 -08:00
parent 0d8d7e0e24
commit 2bac3b5245
8 changed files with 28 additions and 36 deletions

View File

@@ -6,7 +6,7 @@ import { TodoList } from './TodoList';
export const TodoApp = (props: {}) => ( export const TodoApp = (props: {}) => (
<Stack horizontalAlign="center"> <Stack horizontalAlign="center">
<Stack style={{ width: 400 }} verticalGap={25}> <Stack style={{ width: 400 }} gap={25}>
<TodoHeader /> <TodoHeader />
<TodoList /> <TodoList />
<TodoFooter /> <TodoFooter />

View File

@@ -23,7 +23,7 @@ class TodoList extends React.Component<TodoListProps> {
}); });
return ( return (
<Stack verticalGap={10}> <Stack gap={10}>
{filteredTodos.map(id => ( {filteredTodos.map(id => (
<TodoListItem key={id} id={id} /> <TodoListItem key={id} id={id} />
))} ))}

View File

@@ -1,13 +1,18 @@
import { namedConst, namedFn, namedObj } from './named'; import { namedConst, namedFn, namedObj, namedConstBracket, namedConst as c } from './named';
import * as named from './named'; import * as named from './named';
// Print out the exports
console.log(namedConst); console.log(namedConst);
console.log(c);
console.log(namedFn()); console.log(namedFn());
console.log(namedObj); console.log(namedObj);
console.log(namedConstBracket);
// Print out exports through module level import
console.log(named.namedConst); console.log(named.namedConst);
console.log(named.namedFn()); console.log(named.namedFn());
console.log(named.namedObj); console.log(named.namedObj);
console.log(named.namedConstBracket);
import DefaultClass from './default'; import DefaultClass from './default';

View File

@@ -7,3 +7,6 @@ export function namedFn() {
export const namedObj = { export const namedObj = {
hello: 'world' hello: 'world'
}; };
const namedConstBracket = 10;
export { namedConstBracket };

View File

@@ -19,7 +19,7 @@ export class TodoApp extends React.Component<any, Store> {
const { filter, todos } = this.state; const { filter, todos } = this.state;
return ( return (
<Stack horizontalAlign="center"> <Stack horizontalAlign="center">
<Stack style={{ width: 400 }} verticalGap={25}> <Stack style={{ width: 400 }} gap={25}>
<TodoHeader addTodo={this._addTodo} setFilter={this._setFilter} filter={filter} /> <TodoHeader addTodo={this._addTodo} setFilter={this._setFilter} filter={filter} />
<TodoList complete={this._complete} todos={todos} filter={filter} remove={this._remove} edit={this._edit} /> <TodoList complete={this._complete} todos={todos} filter={filter} remove={this._remove} edit={this._edit} />
<TodoFooter clear={this._clear} todos={todos} /> <TodoFooter clear={this._clear} todos={todos} />

View File

@@ -11,19 +11,17 @@ interface TodoListProps {
edit: (id: string, label: string) => void; edit: (id: string, label: string) => void;
} }
export class TodoList extends React.Component<TodoListProps> { export const TodoList = (props: TodoListProps) => {
render() { const { filter, todos, complete, remove, edit } = this.props;
const { filter, todos, complete, remove, edit } = this.props; const filteredTodos = Object.keys(todos).filter(id => {
const filteredTodos = Object.keys(todos).filter(id => { return filter === 'all' || (filter === 'completed' && todos[id].completed) || (filter === 'active' && !todos[id].completed);
return filter === 'all' || (filter === 'completed' && todos[id].completed) || (filter === 'active' && !todos[id].completed); });
});
return ( return (
<Stack verticalGap={10}> <Stack gap={10}>
{filteredTodos.map(id => ( {filteredTodos.map(id => (
<TodoListItem key={id} id={id} todos={todos} complete={complete} remove={remove} edit={edit} /> <TodoListItem key={id} id={id} todos={todos} complete={complete} remove={remove} edit={edit} />
))} ))}
</Stack> </Stack>
); );
} };
}

View File

@@ -1,6 +1,5 @@
import React from 'react'; import React from 'react';
import { Stack, Checkbox, IconButton, TextField, DefaultButton } from 'office-ui-fabric-react'; import { Stack, Checkbox, IconButton, TextField, DefaultButton } from 'office-ui-fabric-react';
import { mergeStyles } from '@uifabric/styling';
import { Store } from '../store'; import { Store } from '../store';
interface TodoListItemProps { interface TodoListItemProps {
@@ -16,21 +15,7 @@ interface TodoListItemState {
editLabel: string; editLabel: string;
} }
const className = mergeStyles({
selectors: {
'.clearButton': {
visibility: 'hidden'
},
'&:hover .clearButton': {
visibility: 'visible'
}
}
});
export class TodoListItem extends React.Component<TodoListItemProps, TodoListItemState> { export class TodoListItem extends React.Component<TodoListItemProps, TodoListItemState> {
/**
*
*/
constructor(props: TodoListItemProps) { constructor(props: TodoListItemProps) {
super(props); super(props);
this.state = { editing: false, editLabel: undefined }; this.state = { editing: false, editLabel: undefined };
@@ -41,7 +26,7 @@ export class TodoListItem extends React.Component<TodoListItemProps, TodoListIte
const item = todos[id]; const item = todos[id];
return ( return (
<Stack horizontal className={className} verticalAlign="center" horizontalAlign="space-between"> <Stack horizontal verticalAlign="center" horizontalAlign="space-between">
{!this.state.editing && ( {!this.state.editing && (
<> <>
<Checkbox label={item.label} checked={item.completed} onChange={() => complete(id)} /> <Checkbox label={item.label} checked={item.completed} onChange={() => complete(id)} />
@@ -53,7 +38,7 @@ export class TodoListItem extends React.Component<TodoListItemProps, TodoListIte
)} )}
{this.state.editing && ( {this.state.editing && (
<Stack.Item fillHorizontal> <Stack.Item grow>
<Stack horizontal> <Stack horizontal>
<Stack.Item grow> <Stack.Item grow>
<TextField value={this.state.editLabel} onChange={this.onChange} /> <TextField value={this.state.editLabel} onChange={this.onChange} />

View File

@@ -37,6 +37,7 @@ module.exports = Object.keys(entries).map(entryPoint => {
}), }),
new ForkTsCheckerWebpackPlugin({ new ForkTsCheckerWebpackPlugin({
silent: true, silent: true,
async: false,
useTypescriptIncrementalApi: true useTypescriptIncrementalApi: true
}) })
], ],