package templates // ShareRow is a single share grant shown in the UI, for either a calendar // or an address book (Kind distinguishes them for form targets). type ShareRow struct { ResourceName string SharedWith string Permission string // "read" or "write" } // ResourceCard describes one of the user's own calendars/address books // plus who it's currently shared with. type ResourceCard struct { Kind string // "calendar", "addressbook", or "ics" (read-only ICS subscription) Name string Color string // hex color like "#3b82f6"; only used for calendars/ics URL string // remote ICS/webcal URL; only used for kind "ics" Shares []ShareRow Virtual bool // true for computed calendars (e.g. birthdays): no delete/sharing, just a color picker } // SharedWithMeItem describes a resource another user has shared with the // current user. type SharedWithMeItem struct { Kind string Owner string Name string Permission string } templ Dashboard(username string, resources []ResourceCard, sharedWithMe []SharedWithMeItem) { @Layout("Dashboard", username) {

Your calendars & address books

@ResourceList(resources) if len(sharedWithMe) > 0 {

Shared with you

} } } // ResourceList renders the #resources container. It's re-rendered as a // whole after a create/delete (which changes the set of cards), whereas a // share update only swaps a single ResourceCardView. templ ResourceList(resources []ResourceCard) {
for _, r := range resources { @ResourceCardView(r) } if len(resources) == 0 {

You don't have any calendars or address books yet — add one above.

}
} templ ResourceCardView(r ResourceCard) {

if r.Kind == "calendar" || r.Kind == "ics" {
} { r.Name } { r.Kind } if r.Virtual { (computed from contacts) } if r.Kind == "ics" { (read-only subscription) }

if !r.Virtual { }
if r.Kind == "ics" {

{ r.URL }

} if !r.Virtual && r.Kind != "ics" {
}
} func colorEndpoint(r ResourceCard) string { if r.Virtual { return "/web/resources/birthdays/color" } if r.Kind == "ics" { return "/web/resources/ics/color" } return "/web/resources/calendar/color" } func shareEndpoint(kind string) string { if kind == "calendar" { return "/web/shares/calendar" } return "/web/shares/addressbook" } func shareVals(resource, sharedWith string) string { return `{"resource": "` + resource + `", "shared_with": "` + sharedWith + `"}` } func resourceEndpoint(kind string) string { switch kind { case "calendar": return "/web/resources/calendar" case "ics": return "/web/resources/ics" default: return "/web/resources/addressbook" } } func resourceVals(name string) string { return `{"name": "` + name + `"}` } func colorOrDefault(c string) string { if c == "" { return "#3b82f6" } return c }