Skip to content

Commit

Permalink
TodoMVC example doesn't put selected class on footer buttons (#107)
Browse files Browse the repository at this point in the history
* Add selected state to footer buttons based on route

* Reinstate filterItem
  • Loading branch information
deklanw authored and paldepind committed Aug 4, 2019
1 parent 4d69bb4 commit c82e53b
Showing 1 changed file with 20 additions and 8 deletions.
28 changes: 20 additions & 8 deletions examples/todo/src/TodoFooter.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import { Behavior, Stream, moment, combine } from "@funkia/hareactive";
import { Component, elements, modelView, fgo } from "../../../src";
import { elements, modelView, fgo } from "../../../src";
const { span, button, ul, li, a, footer, strong } = elements;
import { navigate, Router } from "@funkia/rudolph";
import { navigate, Router, routePath } from "@funkia/rudolph";

// import {mapTraverseFlat} from "./TodoApp";
import { Output as ItemOut } from "./Item";

export type Params = {
Expand All @@ -26,12 +25,15 @@ type FromView = {
const isEmpty = (list: any[]) => list.length === 0;
const formatRemainer = (value: number) => ` item${value === 1 ? "" : "s"} left`;

const filterItem = (name: string) =>
const filterItem = (name: string, selectedClass: Behavior<string>) =>
li(
a(
{
style: {
cursor: "pointer"
},
class: {
selected: selectedClass.map((s) => s === name)
}
},
name
Expand All @@ -58,20 +60,30 @@ const model = function*(
return { clearCompleted };
};

const view = ({}, { todosB, areAnyCompleted }: Params) => {
const view = ({ }: Out, { router, todosB, areAnyCompleted }: Params) => {
const hidden = todosB.map(isEmpty);
const itemsLeft = moment(
(at) => at(todosB).filter((t) => !at(t.completed)).length
);

const selectedClass = routePath(
{
active: () => "Active",
completed: () => "Completed",
"*": () => "All"
},
router
);

return footer({ class: ["footer", { hidden }] }, [
span({ class: "todo-count" }, [
strong(itemsLeft),
itemsLeft.map(formatRemainer)
]),
ul({ class: "filters" }, [
filterItem("All"),
filterItem("Active"),
filterItem("Completed")
filterItem("All", selectedClass),
filterItem("Active", selectedClass),
filterItem("Completed", selectedClass)
]),
button(
{
Expand Down

0 comments on commit c82e53b

Please sign in to comment.