Skip to content

Commit

Permalink
Initial, Cant compile on windows
Browse files Browse the repository at this point in the history
  • Loading branch information
drekle committed Dec 19, 2017
1 parent 826d0ed commit d846ddb
Show file tree
Hide file tree
Showing 16 changed files with 1,575 additions and 0 deletions.
45 changes: 45 additions & 0 deletions rss/gopherjs/actions/actions.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package actions

import "github.com/drekle/go/rss/gopherjs/store/model"

// ReplaceItems is an action that replaces all items with the specified ones.
type ReplaceItems struct {
Items []*model.Item
}

// AddItem is an action which adds a single item with the specified title.
type AddItem struct {
Title string
}

// DestroyItem is an action which destroys the item specified by the index.
type DestroyItem struct {
Index int
}

// SetTitle is an action which specifies the title of an existing item.
type SetTitle struct {
Index int
Title string
}

// SetCompleted is an action which specifies the completed state of an existing
// item.
type SetCompleted struct {
Index int
Completed bool
}

// SetAllCompleted is an action which marks all existing items as being
// completed or not.
type SetAllCompleted struct {
Completed bool
}

// ClearCompleted is an action which clears the completed items.
type ClearCompleted struct{}

// SetFilter is an action which sets the filter for the viewed items.
type SetFilter struct {
Filter model.FilterState
}
42 changes: 42 additions & 0 deletions rss/gopherjs/components/filterbutton.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package components

import (
"github.com/drekle/go/rss/gopherjs/actions"
"github.com/drekle/go/rss/gopherjs/dispatcher"
"github.com/drekle/go/rss/gopherjs/store"
"github.com/drekle/go/rss/gopherjs/store/model"
"github.com/gopherjs/vecty"
"github.com/gopherjs/vecty/elem"
"github.com/gopherjs/vecty/event"
"github.com/gopherjs/vecty/prop"
)

// FilterButton is a vecty.Component which allows the user to select a filter
// state.
type FilterButton struct {
vecty.Core

Label string `vecty:"prop"`
Filter model.FilterState `vecty:"prop"`
}

func (b *FilterButton) onClick(event *vecty.Event) {
dispatcher.Dispatch(&actions.SetFilter{
Filter: b.Filter,
})
}

// Render implements the vecty.Component interface.
func (b *FilterButton) Render() vecty.ComponentOrHTML {
return elem.ListItem(
elem.Anchor(
vecty.Markup(
vecty.MarkupIf(store.Filter == b.Filter, vecty.Class("selected")),
prop.Href("#"),
event.Click(b.onClick).PreventDefault(),
),

vecty.Text(b.Label),
),
)
}
117 changes: 117 additions & 0 deletions rss/gopherjs/components/itemview.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
package components

import (
"github.com/drekle/go/rss/gopherjs/actions"
"github.com/drekle/go/rss/gopherjs/dispatcher"
"github.com/drekle/go/rss/gopherjs/store/model"
"github.com/gopherjs/vecty"
"github.com/gopherjs/vecty/elem"
"github.com/gopherjs/vecty/event"
"github.com/gopherjs/vecty/prop"
"github.com/gopherjs/vecty/style"
)

// ItemView is a vecty.Component which represents a single item in the TODO
// list.
type ItemView struct {
vecty.Core

Index int `vecty:"prop"`
Item *model.Item `vecty:"prop"`
editing bool
editTitle string
input *vecty.HTML
}

// Key implements the vecty.Keyer interface.
func (p *ItemView) Key() interface{} {
return p.Index
}

func (p *ItemView) onDestroy(event *vecty.Event) {
dispatcher.Dispatch(&actions.DestroyItem{
Index: p.Index,
})
}

func (p *ItemView) onToggleCompleted(event *vecty.Event) {
dispatcher.Dispatch(&actions.SetCompleted{
Index: p.Index,
Completed: event.Target.Get("checked").Bool(),
})
}

func (p *ItemView) onStartEdit(event *vecty.Event) {
p.editing = true
p.editTitle = p.Item.Title
vecty.Rerender(p)
p.input.Node().Call("focus")
}

func (p *ItemView) onEditInput(event *vecty.Event) {
p.editTitle = event.Target.Get("value").String()
vecty.Rerender(p)
}

func (p *ItemView) onStopEdit(event *vecty.Event) {
p.editing = false
vecty.Rerender(p)
dispatcher.Dispatch(&actions.SetTitle{
Index: p.Index,
Title: p.editTitle,
})
}

// Render implements the vecty.Component interface.
func (p *ItemView) Render() vecty.ComponentOrHTML {
p.input = elem.Input(
vecty.Markup(
vecty.Class("edit"),
prop.Value(p.editTitle),
event.Input(p.onEditInput),
),
)

return elem.ListItem(
vecty.Markup(
vecty.ClassMap{
"completed": p.Item.Completed,
"editing": p.editing,
},
),

elem.Div(
vecty.Markup(
vecty.Class("view"),
),

elem.Input(
vecty.Markup(
vecty.Class("toggle"),
prop.Type(prop.TypeCheckbox),
prop.Checked(p.Item.Completed),
event.Change(p.onToggleCompleted),
),
),
elem.Label(
vecty.Markup(
event.DoubleClick(p.onStartEdit),
),
vecty.Text(p.Item.Title),
),
elem.Button(
vecty.Markup(
vecty.Class("destroy"),
event.Click(p.onDestroy),
),
),
),
elem.Form(
vecty.Markup(
style.Margin(style.Px(0)),
event.Submit(p.onStopEdit).PreventDefault(),
),
p.input,
),
)
}
Loading

0 comments on commit d846ddb

Please sign in to comment.