mirror of
https://github.com/muety/wakapi.git
synced 2023-08-10 21:12:56 +03:00
Read the persisted summary interval from a cookie
This cookie will be read only if the `interval` or `from` query params are not set. If the cookie is also unset, it will still default to the "today" interval. TODO: The cookie still needs to be set on the client with a `Set-Cookie` response header.
This commit is contained in:
parent
ba81c07345
commit
e89ce076fd
@ -12,9 +12,10 @@ import (
|
||||
)
|
||||
|
||||
const (
|
||||
UserKey = "user"
|
||||
ImprintKey = "imprint"
|
||||
AuthCookieKey = "wakapi_auth"
|
||||
UserKey = "user"
|
||||
ImprintKey = "imprint"
|
||||
AuthCookieKey = "wakapi_auth"
|
||||
PersistentIntervalKey = "wakapi_summary_interval"
|
||||
)
|
||||
|
||||
type MigrationFunc func(db *gorm.DB) error
|
||||
|
@ -43,8 +43,14 @@ func (h *SummaryHandler) GetIndex(w http.ResponseWriter, r *http.Request) {
|
||||
rawQuery := r.URL.RawQuery
|
||||
q := r.URL.Query()
|
||||
if q.Get("interval") == "" && q.Get("from") == "" {
|
||||
q.Set("interval", "today")
|
||||
if intervalCookie, _ := r.Cookie(models.PersistentIntervalKey); intervalCookie != nil {
|
||||
q.Set("interval", intervalCookie.Value)
|
||||
} else {
|
||||
q.Set("interval", "today")
|
||||
}
|
||||
r.URL.RawQuery = q.Encode()
|
||||
} else {
|
||||
// TODO: Add a `Set-Cookie: interval` header to persit it on the front-end
|
||||
}
|
||||
|
||||
summaryParams, _ := utils.ParseSummaryParams(r)
|
||||
|
Loading…
Reference in New Issue
Block a user