Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Andrew Fryer Front end Task #28

Open
wants to merge 17 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
allow for selecting multiple tags
  • Loading branch information
Andrew-Fryer committed Feb 14, 2020
commit 4efd7fba15f0426b59a272afeb6306c02e6f539f
11 changes: 2 additions & 9 deletions src/components/todoApp.js
Original file line number Diff line number Diff line change
@@ -5,7 +5,6 @@ import {observer} from 'mobx-react';
import TodoEntry from './todoEntry';
import TodoOverview from './todoOverview';
import TodoFooter from './todoFooter';
import { ALL_TODOS, ACTIVE_TODOS, COMPLETED_TODOS, IMPORTANT_TODOS } from '../constants';

import DevTool from 'mobx-react-devtools';

@@ -29,14 +28,8 @@ export default class TodoApp extends React.Component {
componentDidMount() {
if (__CLIENT__) {
var { Router } = require('director/build/director');
var viewStore = this.props.viewStore;
var router = Router({
'/': function() { viewStore.todoFilter = ALL_TODOS; },
'/active': function() { viewStore.todoFilter = ACTIVE_TODOS; },
'/completed': function() { viewStore.todoFilter = COMPLETED_TODOS; },
'/important': function() { viewStore.todoFilter = IMPORTANT_TODOS; },
});
router.init('/');
var router = Router({});
router.init('/');
}
}
}
16 changes: 8 additions & 8 deletions src/components/todoFooter.js
Original file line number Diff line number Diff line change
@@ -20,10 +20,10 @@ export default class TodoFooter extends React.Component {
<strong>{todoStore.activeTodoCount}</strong> {activeTodoWord} left
</span>
<ul className="filters">
{this.renderFilterLink(ALL_TODOS, "", "All")}
{this.renderFilterLink(ACTIVE_TODOS, "active", "Active")}
{this.renderFilterLink(COMPLETED_TODOS, "completed", "Completed")}
{this.renderFilterLink(IMPORTANT_TODOS, "important", "Important")}
{this.renderFilterLink(ALL_TODOS, "All")}
{this.renderFilterLink(ACTIVE_TODOS, "Active")}
{this.renderFilterLink(COMPLETED_TODOS, "Completed")}
{this.renderFilterLink(IMPORTANT_TODOS, "Important")}
</ul>
{ todoStore.completedCount === 0
? null
@@ -37,12 +37,12 @@ export default class TodoFooter extends React.Component {
);
}

renderFilterLink(filterName, url, caption) {
renderFilterLink(filterName, caption) {
return (<li>
<a href={"#/" + url}
className={filterName === this.props.viewStore.todoFilter ? "selected" : ""}>
<button onClick={() => this.props.viewStore.toggleView(filterName)}
className={this.props.viewStore.todoFilters.includes(filterName) ? "selected" : ""}>
{caption}
</a>
</button>
{' '}
</li>)
}
30 changes: 21 additions & 9 deletions src/components/todoOverview.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React from 'react';
import PropTypes from 'prop-types';
import {observer} from 'mobx-react';
import { ACTIVE_TODOS, COMPLETED_TODOS, IMPORTANT_TODOS } from '../constants';
import { ACTIVE_TODOS, COMPLETED_TODOS, IMPORTANT_TODOS, ALL_TODOS } from '../constants';

import TodoItem from './todoItem';

@@ -34,16 +34,28 @@ export default class TodoOverview extends React.Component {

getVisibleTodos() {
return this.props.todoStore.todos.filter(todo => {
switch (this.props.viewStore.todoFilter) {
case ACTIVE_TODOS:
return !todo.completed;
case COMPLETED_TODOS:
return todo.completed;
case IMPORTANT_TODOS:
return todo.important;
default:
for(let i = 0; i < this.props.viewStore.todoFilters.length; i++) {
const filter = this.props.viewStore.todoFilters[i];
let res = null;
switch (filter) {
case ALL_TODOS:
res = true;
break;
case ACTIVE_TODOS:
res = !todo.completed;
break;
case COMPLETED_TODOS:
res = todo.completed;
break;
case IMPORTANT_TODOS:
res = todo.important;
break;
}
if(res) {
return true;
}
}
return false;
});
}

10 changes: 9 additions & 1 deletion src/stores/ViewStore.js
Original file line number Diff line number Diff line change
@@ -3,5 +3,13 @@ import { ALL_TODOS } from '../constants';

export default class ViewStore {
@observable todoBeingEdited = null;
@observable todoFilter= ALL_TODOS;
@observable todoFilters = [ALL_TODOS];

toggleView(filter) {
if(this.todoFilters.includes(filter)) {
this.todoFilters = this.todoFilters.filter(f => f !== filter);
} else {
this.todoFilters.push(filter);
}
}
}