Stage 8 polish: profile validation, finished-game UI, badge + Safari fixes
Owner-review follow-up on the Stage 8 branch: - Friend code is copyable (📋 + toast). The lobby notification badge is fixed — it had inherited the hamburger-bar style — into a proper round count dot. - Safari: min-width:0 on flex text inputs (friend code, profile, chat) so they shrink instead of pushing the adjacent button off-screen. - Profile editing is validated on both the UI and the backend: display-name format (letters joined by single space/./_ separators, no leading/trailing/adjacent separators, <=32 runes), a UTC-offset timezone picker (account.ResolveZone parses ±HH:MM or a legacy IANA name), a 10-minute away grid capped at 12h (wrap-aware), and email format; Save is disabled and invalid fields red-bordered until valid. Language stays in Settings. - In a game, an "add to friends" menu item flips to a disabled "request sent"; chat send/nudge became ⬆️/🛎️ icon buttons. - A finished game drops its last-word highlight, hides Check word / Drop game, disables zoom, and draws an inert (greyed) footer instead of hiding it. Tests: account validators (name/away/zone), UI profileValidation, e2e for the finished-game footer/menu and the copy control. Docs (PLAN, ARCHITECTURE, FUNCTIONAL +ru, UI_DESIGN) updated for the display-name rule, UTC-offset timezone and the 12h away window.
This commit is contained in:
@@ -0,0 +1,56 @@
|
||||
package account
|
||||
|
||||
import (
|
||||
"regexp"
|
||||
"strconv"
|
||||
"time"
|
||||
)
|
||||
|
||||
// offsetZoneRe matches a fixed UTC offset like "+03:00" or "-05:30" — the form the
|
||||
// Stage 8 profile editor stores (an offset dropdown rather than an IANA name).
|
||||
var offsetZoneRe = regexp.MustCompile(`^([+-])(\d{2}):(\d{2})$`)
|
||||
|
||||
// parseOffsetZone parses a "±HH:MM" offset into a fixed-offset location, reporting
|
||||
// ok=false when name is not a well-formed offset within ±14:00.
|
||||
func parseOffsetZone(name string) (*time.Location, bool) {
|
||||
m := offsetZoneRe.FindStringSubmatch(name)
|
||||
if m == nil {
|
||||
return nil, false
|
||||
}
|
||||
h, _ := strconv.Atoi(m[2])
|
||||
min, _ := strconv.Atoi(m[3])
|
||||
if h > 14 || min > 59 || (h == 14 && min > 0) {
|
||||
return nil, false
|
||||
}
|
||||
secs := h*3600 + min*60
|
||||
if m[1] == "-" {
|
||||
secs = -secs
|
||||
}
|
||||
return time.FixedZone(name, secs), true
|
||||
}
|
||||
|
||||
// ResolveZone resolves a stored timezone — a fixed "±HH:MM" offset or an IANA name —
|
||||
// to a *time.Location, falling back to UTC when it is empty or unrecognised, so a
|
||||
// bad profile value never breaks the turn-timeout sweeper or the robot's sleep.
|
||||
func ResolveZone(name string) *time.Location {
|
||||
if name == "" {
|
||||
return time.UTC
|
||||
}
|
||||
if loc, ok := parseOffsetZone(name); ok {
|
||||
return loc
|
||||
}
|
||||
if loc, err := time.LoadLocation(name); err == nil {
|
||||
return loc
|
||||
}
|
||||
return time.UTC
|
||||
}
|
||||
|
||||
// validZone reports whether name is an acceptable timezone for a profile update —
|
||||
// either a "±HH:MM" offset or a loadable IANA location.
|
||||
func validZone(name string) bool {
|
||||
if _, ok := parseOffsetZone(name); ok {
|
||||
return true
|
||||
}
|
||||
_, err := time.LoadLocation(name)
|
||||
return err == nil
|
||||
}
|
||||
Reference in New Issue
Block a user