package templates
import (
"fmt"
"time"
g "alin.ovh/gomponents"
c "alin.ovh/gomponents/components"
. "alin.ovh/gomponents/html"
"vimagination.zapto.org/ics"
"alin.ovh/homestead/domain/calendar"
"alin.ovh/homestead/domain/web/templates"
)
func CalendarPage(site templates.SiteSettings, cal *calendar.Calendar) g.Node {
return templates.Layout(site, templates.PageSettings{
Title: "Calendar",
TitleAttrs: templates.Attrs{},
BodyAttrs: templates.Attrs{},
}, Calendar(site, cal))
}
func Calendar(site templates.SiteSettings, cal *calendar.Calendar) g.Node {
past := true
dates, err := cal.Availability(2)
if err != nil {
panic(err)
}
return Div(Class("calendar"),
H2(g.Text("Calendar")),
P(g.Text("Here you can roughly see when I'm busy in the next two weeks.")),
P(Class("only-small-portrait"), g.Text("Rotate to see calendar view and previous days.")),
Section(Class("calendar-grid"),
g.Map(dates, func(date *calendar.CalendarDate) g.Node {
if past && date.IsToday() {
past = false
}
return Section(c.Classes{
"day": true,
"past": past,
"today": date.IsToday(),
},
H3(
Time(
DateTime(date.Format(time.DateOnly)),
g.Text(date.Format("Mon _2"))),
),
g.Map(date.BusyPeriods, func(e *calendar.Busy) g.Node {
return Div(
c.Classes{
"event": true,
"tentative": e.Type == ics.FreeBusyTypeBusyTentative,
},
TitleAttr(
fmt.Sprintf(
"%sā%s",
e.StartTime.Format(time.RFC1123),
e.EndTime.Format(time.RFC1123),
),
),
g.If(e.StartTime.Before(date.BeginningOfDay()),
CTime(date.BeginningOfDay()),
CTime(e.StartTime),
),
g.Text("ā"),
g.If(e.EndTime.After(date.EndOfDay()),
CTime(date.EndOfDay()),
CTime(e.EndTime),
),
g.If(e.Type == ics.FreeBusyTypeBusyTentative,
g.Text("?"),
),
)
}),
)
}),
),
Footer(
P(g.Textf("Timezone is %s", site.Timezone.String())),
),
)
}
func CTime(date calendar.Date) g.Node {
return Time(
DateTime(date.Format(time.RFC3339)),
g.Text(date.Format("15:04")),
)
}
domain/calendar/templates/calendar.go (view raw)