-
-
Notifications
You must be signed in to change notification settings - Fork 31
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Jo Vandeginste <[email protected]>
- Loading branch information
1 parent
8c14019
commit 4018783
Showing
14 changed files
with
188 additions
and
69 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
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
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
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
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,40 @@ | ||
package app | ||
|
||
import ( | ||
"github.com/vorlif/spreak/humanize" | ||
"github.com/vorlif/spreak/humanize/locale/nl" | ||
"golang.org/x/text/language" | ||
) | ||
|
||
var ( | ||
DefaultLanguage = "browser" | ||
|
||
DefaultTheme = Theme{Name: "System default", Code: "browser", Icon: "🌐"} | ||
DarkTheme = Theme{Name: "Dark theme", Code: "dark", Icon: "🌑"} | ||
) | ||
|
||
func translations() []interface{} { | ||
return []interface{}{ | ||
language.English, | ||
language.Dutch, | ||
} | ||
} | ||
|
||
func humanLocales() []*humanize.LocaleData { | ||
return []*humanize.LocaleData{ | ||
nl.New(), | ||
} | ||
} | ||
|
||
func themes() []Theme { | ||
return []Theme{ | ||
DefaultTheme, | ||
DarkTheme, | ||
} | ||
} | ||
|
||
type Theme struct { | ||
Code string | ||
Icon string | ||
Name string | ||
} |
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
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 app | ||
|
||
import ( | ||
"net/http" | ||
|
||
"github.com/jovandeginste/workout-tracker/pkg/database" | ||
"github.com/labstack/echo/v4" | ||
) | ||
|
||
func (a *App) userProfileHandler(c echo.Context) error { | ||
data := a.defaultData(c) | ||
return c.Render(http.StatusOK, "user_profile.html", data) | ||
} | ||
|
||
func (a *App) userProfileUpdateHandler(c echo.Context) error { | ||
u := a.getCurrentUser(c) | ||
p := &database.Profile{} | ||
|
||
if err := c.Bind(p); err != nil { | ||
return a.redirectWithError(c, a.echo.Reverse("user-profile"), err) | ||
} | ||
|
||
u.Profile.Language = p.Language | ||
u.Profile.Theme = p.Theme | ||
|
||
if err := u.Profile.Save(a.db); err != nil { | ||
return a.redirectWithError(c, a.echo.Reverse("user-profile"), err) | ||
} | ||
|
||
a.setNotice(c, "Profile updated") | ||
|
||
return c.Redirect(http.StatusFound, a.echo.Reverse("user-profile")) | ||
} | ||
|
||
func (a *App) userRefreshHandler(c echo.Context) error { | ||
u := a.getCurrentUser(c) | ||
|
||
if err := u.MarkWorkoutsDirty(a.db); err != nil { | ||
return a.redirectWithError(c, a.echo.Reverse("user-profile"), err) | ||
} | ||
|
||
a.setNotice(c, "All workouts will be refreshed in the coming minutes.") | ||
|
||
return c.Redirect(http.StatusFound, a.echo.Reverse("user-profile")) | ||
} |
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
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
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
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
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,16 @@ | ||
{{ define "user_profile_language" }} {{ $userLanguage := . }} | ||
<select id="language" name="language"> | ||
{{ $selected := "" }} {{ if eq $userLanguage "browser" }} {{ $selected = | ||
"selected" }}{{ end }} | ||
<option value="browser" {{ $selected }}>🌐 Browser language</option> | ||
{{ range supportedLanguages }} {{ $linf := .String | ToLanguageInformation }} | ||
{{ $selected := "" }} {{ if eq $linf.Code $userLanguage }} {{ $selected = | ||
"selected" }} {{ end }} | ||
<option value="{{ $linf.Code }}" {{ $selected }}> | ||
{{ $linf.Flag }} {{ $linf.LocalName }} {{ if ne $linf.EnglishName "" }} {{ | ||
if ne $linf.EnglishName $linf.LocalName }} ({{ $linf.EnglishName }}) {{ end | ||
}}{{ end }} | ||
</option> | ||
{{ end }} | ||
</select> | ||
{{ end }} |
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,8 @@ | ||
{{ define "user_profile_theme" }}{{ $userTheme := . }} | ||
<select id="theme" name="theme"> | ||
{{ range supportedThemes }} {{ $selected := "" }} {{ if eq .Code $userTheme }} | ||
{{ $selected = "selected" }} {{ end }} | ||
<option value="{{ .Code }}" {{ $selected }}>{{ .Icon }} {{ .Name }}</option> | ||
{{ end }} | ||
</select> | ||
{{ end }} |
Oops, something went wrong.