-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
16 changed files
with
1,575 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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), | ||
), | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | ||
), | ||
) | ||
} |
Oops, something went wrong.