Self-hosted fitness tracker. Log workouts, track nutrition, and monitor progress. Docker deployment, mobile-friendly.
Add server configuration UI to login/register pages
Cawlummd82ab8324022
diff --git a/web/src/pages/Login.tsx b/web/src/pages/Login.tsxindex db7854e..655e4a3 100644--- a/web/src/pages/Login.tsx+++ b/web/src/pages/Login.tsx@@ -1,17 +1,28 @@import { useState } from 'react'import { useNavigate, Link } from 'react-router-dom'-import { AlertCircle, Zap, Dumbbell, Apple, TrendingUp, LogIn } from 'lucide-react'+import { AlertCircle, Zap, Dumbbell, Apple, TrendingUp, LogIn, ChevronDown, Server } from 'lucide-react'import { useAuthStore } from '../stores/auth'+import { useServerStore } from '../stores/server'import Logo from '../components/Logo'export default function Login() {- const [email, setEmail] = useState('')- const [password, setPassword] = useState('')- const [error, setError] = useState('')- const [isLoading, setLoading] = useState(false)+ const [email, setEmail] = useState('')+ const [password, setPassword] = useState('')+ const [error, setError] = useState('')+ const [isLoading, setLoading] = useState(false)+ const [showServerSettings, setShowServerSettings] = useState(false)+ const [serverInput, setServerInput] = useState('')const navigate = useNavigate()const { login } = useAuthStore()+ const { serverUrl, setServerUrl } = useServerStore()++ const handleServerUrlChange = () => {+ if (serverInput.trim()) {+ setServerUrl(serverInput)+ setServerInput('')+ }+ }const handleSubmit = async (e: React.FormEvent) => {e.preventDefault()@@ -113,6 +124,48 @@ export default function Login() {</p></div>+ {/* Server settings toggle */}+ <button+ onClick={() => setShowServerSettings(!showServerSettings)}+ className="flex items-center gap-2 px-3 py-2 mb-4 text-xs text-tx-muted hover:text-tx-secondary rounded-lg hover:bg-surface-muted/40 transition-colors"+ >+ <Server className="w-3.5 h-3.5" />+ <span>Server settings</span>+ <ChevronDown className={`w-3 h-3 ml-auto transition-transform ${showServerSettings ? 'rotate-180' : ''}`} />+ </button>++ {/* Server settings panel */}+ {showServerSettings && (+ <div className="mb-4 p-3 bg-surface-muted/30 border border-surface-border rounded-lg space-y-2">+ <label className="block text-xs font-medium text-tx-secondary uppercase tracking-wider">Server URL</label>+ <input+ type="text"+ value={serverInput || serverUrl}+ onChange={e => setServerInput(e.target.value)}+ placeholder="http://localhost:3000"+ className="input text-sm"+ />+ <div className="flex gap-2 pt-1">+ <button+ onClick={handleServerUrlChange}+ disabled={!serverInput.trim()}+ className="flex-1 px-2 py-1.5 text-xs bg-brand-500 hover:bg-brand-600 disabled:opacity-40 disabled:cursor-not-allowed text-white font-medium rounded-lg transition-colors"+ >+ Save+ </button>+ <button+ onClick={() => setShowServerSettings(false)}+ className="flex-1 px-2 py-1.5 text-xs bg-surface-border text-tx-secondary hover:bg-surface-border/80 rounded-lg transition-colors"+ >+ Close+ </button>+ </div>+ {serverUrl !== 'http://localhost:3000' && (+ <p className="text-xs text-tx-muted pt-1">Current: {serverUrl}</p>+ )}+ </div>+ )}+{/* Form */}<form onSubmit={handleSubmit} className="space-y-4">{/* Email */}diff --git a/web/src/pages/Register.tsx b/web/src/pages/Register.tsxindex 0be0bb8..d77273c 100644--- a/web/src/pages/Register.tsx+++ b/web/src/pages/Register.tsx@@ -1,7 +1,8 @@import { useState } from 'react'import { useNavigate, Link } from 'react-router-dom'-import { AlertCircle, Dumbbell, Apple, TrendingUp, UserPlus } from 'lucide-react'+import { AlertCircle, Dumbbell, Apple, TrendingUp, UserPlus, ChevronDown, Server } from 'lucide-react'import { useAuthStore } from '../stores/auth'+import { useServerStore } from '../stores/server'import Logo from '../components/Logo'export default function Register() {@@ -10,9 +11,19 @@ export default function Register() {const [passwordConfirm, setPasswordConfirm] = useState('')const [error, setError] = useState('')const [isLoading, setLoading] = useState(false)+ const [showServerSettings, setShowServerSettings] = useState(false)+ const [serverInput, setServerInput] = useState('')const navigate = useNavigate()const { register } = useAuthStore()+ const { serverUrl, setServerUrl } = useServerStore()++ const handleServerUrlChange = () => {+ if (serverInput.trim()) {+ setServerUrl(serverInput)+ setServerInput('')+ }+ }const handleSubmit = async (e: React.FormEvent) => {e.preventDefault()@@ -104,6 +115,48 @@ export default function Register() {</p></div>+ {/* Server settings toggle */}+ <button+ onClick={() => setShowServerSettings(!showServerSettings)}+ className="flex items-center gap-2 px-3 py-2 mb-4 text-xs text-tx-muted hover:text-tx-secondary rounded-lg hover:bg-surface-muted/40 transition-colors"+ >+ <Server className="w-3.5 h-3.5" />+ <span>Server settings</span>+ <ChevronDown className={`w-3 h-3 ml-auto transition-transform ${showServerSettings ? 'rotate-180' : ''}`} />+ </button>++ {/* Server settings panel */}+ {showServerSettings && (+ <div className="mb-4 p-3 bg-surface-muted/30 border border-surface-border rounded-lg space-y-2">+ <label className="block text-xs font-medium text-tx-secondary uppercase tracking-wider">Server URL</label>+ <input+ type="text"+ value={serverInput || serverUrl}+ onChange={e => setServerInput(e.target.value)}+ placeholder="http://localhost:3000"+ className="input text-sm"+ />+ <div className="flex gap-2 pt-1">+ <button+ onClick={handleServerUrlChange}+ disabled={!serverInput.trim()}+ className="flex-1 px-2 py-1.5 text-xs bg-brand-500 hover:bg-brand-600 disabled:opacity-40 disabled:cursor-not-allowed text-white font-medium rounded-lg transition-colors"+ >+ Save+ </button>+ <button+ onClick={() => setShowServerSettings(false)}+ className="flex-1 px-2 py-1.5 text-xs bg-surface-border text-tx-secondary hover:bg-surface-border/80 rounded-lg transition-colors"+ >+ Close+ </button>+ </div>+ {serverUrl !== 'http://localhost:3000' && (+ <p className="text-xs text-tx-muted pt-1">Current: {serverUrl}</p>+ )}+ </div>+ )}+{/* Form */}<form onSubmit={handleSubmit} className="space-y-4">{/* Email */}diff --git a/web/src/services/api.ts b/web/src/services/api.tsindex 4f91c5a..f5242db 100644--- a/web/src/services/api.ts+++ b/web/src/services/api.ts@@ -1,7 +1,12 @@import axios, { AxiosInstance } from 'axios'import * as types from '../types'-const API_BASE = (import.meta.env.VITE_API_URL as string) || 'http://localhost:3000/api/v1'+const getAPIBase = () => {+ const serverUrl = localStorage.getItem('server_url') || 'http://localhost:3000'+ return `${serverUrl}/api/v1`+}++const API_BASE = (import.meta.env.VITE_API_URL as string) || getAPIBase()const api: AxiosInstance = axios.create({baseURL: API_BASE,diff --git a/web/src/stores/server.ts b/web/src/stores/server.tsnew file mode 100644index 0000000..4f94a4b--- /dev/null+++ b/web/src/stores/server.ts@@ -0,0 +1,27 @@+import { create } from 'zustand'++interface ServerStore {+ serverUrl: string+ setServerUrl: (url: string) => void+ getServerUrl: () => string+}++const DEFAULT_SERVER = 'http://localhost:3000'++export const useServerStore = create<ServerStore>((set, get) => {+ const stored = localStorage.getItem('server_url') || DEFAULT_SERVER++ return {+ serverUrl: stored,++ setServerUrl: (url: string) => {+ const normalized = url.trim().replace(/\/$/, '')+ localStorage.setItem('server_url', normalized)+ set({ serverUrl: normalized })+ },++ getServerUrl: () => {+ return get().serverUrl+ },+ }+})