update navbar, fix versioning
This commit is contained in:
576
src/App.jsx
576
src/App.jsx
@@ -12,16 +12,10 @@ const storage = {
|
||||
try {
|
||||
const val = localStorage.getItem(key);
|
||||
return val ? { value: val } : null;
|
||||
} catch {
|
||||
return null;
|
||||
}
|
||||
} catch { return null; }
|
||||
},
|
||||
set: async (key, val) => {
|
||||
try {
|
||||
localStorage.setItem(key, val);
|
||||
} catch (e) {
|
||||
console.error("Storage set failed:", e);
|
||||
}
|
||||
try { localStorage.setItem(key, val); } catch (e) { console.error("Storage set failed:", e); }
|
||||
}
|
||||
};
|
||||
|
||||
@@ -30,24 +24,15 @@ async function loadData() {
|
||||
const result = await storage.get(STORAGE_KEY);
|
||||
if (result) {
|
||||
const parsed = JSON.parse(result.value);
|
||||
return {
|
||||
beans: parsed.beans || [],
|
||||
brewLogs: parsed.brewLogs || [],
|
||||
lastSyncedAt: parsed.lastSyncedAt || null
|
||||
};
|
||||
return { beans: parsed.beans || [], brewLogs: parsed.brewLogs || [], lastSyncedAt: parsed.lastSyncedAt || null };
|
||||
}
|
||||
return defaultData;
|
||||
} catch {
|
||||
return defaultData;
|
||||
}
|
||||
} catch { return defaultData; }
|
||||
}
|
||||
|
||||
async function saveData(data) {
|
||||
try {
|
||||
await storage.set(STORAGE_KEY, JSON.stringify(data));
|
||||
} catch (e) {
|
||||
console.error("Save failed:", e);
|
||||
}
|
||||
try { await storage.set(STORAGE_KEY, JSON.stringify(data)); }
|
||||
catch (e) { console.error("Save failed:", e); }
|
||||
}
|
||||
|
||||
const uid = () => Date.now().toString(36) + Math.random().toString(36).slice(2, 7);
|
||||
@@ -58,12 +43,42 @@ const METHOD_LABELS = { pourover: "Pour Over", espresso: "Espresso", coldbrew: "
|
||||
const METHOD_ICONS = { pourover: "☕", espresso: "⚡", coldbrew: "❄️" };
|
||||
const METHOD_COLORS = { pourover: "#8B6914", espresso: "#5C3317", coldbrew: "#2F4F6F" };
|
||||
|
||||
// ─── Shared input/label styles ───
|
||||
const inputCls = "w-full px-3.5 py-3 border border-[#E8DFD3] rounded-lg bg-white font-sans text-sm text-[#2C1810] transition-colors outline-none focus:border-[#8B6914]";
|
||||
const inputCls = "w-full px-3.5 py-3 border border-[#E8DFD3] rounded-lg bg-white text-sm text-[#2C1810] transition-colors outline-none focus:border-[#8B6914]";
|
||||
const labelCls = "block text-[10px] font-semibold uppercase tracking-wider text-[#6B5744] mb-1.5";
|
||||
|
||||
// ─── Components ───
|
||||
// ─── Create Modal ───
|
||||
function CreateModal({ onClose, onAddBean, onAddBrew }) {
|
||||
return (
|
||||
<div className="fixed inset-0 bg-[rgba(44,24,16,0.5)] z-[100] flex items-end justify-center animate-fade-in" onClick={onClose}>
|
||||
<div className="bg-[#FAF6F1] rounded-t-[28px] w-full max-w-[480px] px-5 pb-10 animate-slide-up" onClick={e => e.stopPropagation()}>
|
||||
<div className="w-9 h-1 bg-[#E8DFD3] rounded mx-auto mt-3 mb-6" />
|
||||
<div className="font-serif text-xl font-semibold text-[#2C1810] mb-6">What would you like to add?</div>
|
||||
<div className="flex flex-col gap-3">
|
||||
<button
|
||||
className="flex items-center gap-4 px-5 py-4 bg-white border border-[#E8DFD3] rounded-2xl text-left cursor-pointer hover:shadow-[0_4px_16px_rgba(44,24,16,0.08)] transition-all active:scale-[0.98]"
|
||||
onClick={() => { onClose(); onAddBrew(); }}>
|
||||
<div className="w-12 h-12 rounded-xl bg-[#FAF6F1] flex items-center justify-center text-2xl flex-shrink-0">☕</div>
|
||||
<div>
|
||||
<div className="font-semibold text-[#2C1810] text-sm">Log a Brew</div>
|
||||
<div className="text-xs text-[#9C8B7A] mt-0.5">Record a brewing session with recipe details</div>
|
||||
</div>
|
||||
</button>
|
||||
<button
|
||||
className="flex items-center gap-4 px-5 py-4 bg-white border border-[#E8DFD3] rounded-2xl text-left cursor-pointer hover:shadow-[0_4px_16px_rgba(44,24,16,0.08)] transition-all active:scale-[0.98]"
|
||||
onClick={() => { onClose(); onAddBean(); }}>
|
||||
<div className="w-12 h-12 rounded-xl bg-[#FAF6F1] flex items-center justify-center text-2xl flex-shrink-0">🫘</div>
|
||||
<div>
|
||||
<div className="font-semibold text-[#2C1810] text-sm">Add Bean</div>
|
||||
<div className="text-xs text-[#9C8B7A] mt-0.5">Add a new coffee bean to your library</div>
|
||||
</div>
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
// ─── Bean Form ───
|
||||
function BeanForm({ onSave, onClose, initial }) {
|
||||
const [form, setForm] = useState(initial || { name: "", roastery: "", roastDate: "", roastType: "", image: "", tastingNotes: "" });
|
||||
const set = (k, v) => setForm(p => ({ ...p, [k]: v }));
|
||||
@@ -80,62 +95,39 @@ function BeanForm({ onSave, onClose, initial }) {
|
||||
|
||||
return (
|
||||
<div className="fixed inset-0 bg-[rgba(44,24,16,0.4)] z-[100] flex items-end justify-center animate-fade-in" onClick={onClose}>
|
||||
<div className="bg-[#FAF6F1] rounded-t-[20px] w-full max-w-[480px] max-h-[88vh] overflow-y-auto animate-slide-up px-5 pb-8" onClick={e => e.stopPropagation()}>
|
||||
<div className="bg-[#FAF6F1] rounded-t-[24px] w-full max-w-[480px] max-h-[88vh] overflow-y-auto animate-slide-up px-5 pb-8" onClick={e => e.stopPropagation()}>
|
||||
<div className="w-9 h-1 bg-[#E8DFD3] rounded mx-auto my-3" />
|
||||
<div className="font-serif text-xl font-semibold text-[#2C1810] mb-5">{initial ? "Edit Bean" : "Add Bean"}</div>
|
||||
|
||||
<div className="mb-4">
|
||||
<label className={labelCls}>Bean Name *</label>
|
||||
<input className={inputCls} placeholder="e.g. Ethiopia Yirgacheffe" value={form.name} onChange={e => set("name", e.target.value)} />
|
||||
</div>
|
||||
<div className="mb-4">
|
||||
<label className={labelCls}>Roastery</label>
|
||||
<input className={inputCls} placeholder="e.g. Blue Tokai" value={form.roastery} onChange={e => set("roastery", e.target.value)} />
|
||||
</div>
|
||||
<div className="mb-4"><label className={labelCls}>Bean Name *</label>
|
||||
<input className={inputCls} placeholder="e.g. Ethiopia Yirgacheffe" value={form.name} onChange={e => set("name", e.target.value)} /></div>
|
||||
<div className="mb-4"><label className={labelCls}>Roastery</label>
|
||||
<input className={inputCls} placeholder="e.g. Blue Tokai" value={form.roastery} onChange={e => set("roastery", e.target.value)} /></div>
|
||||
<div className="flex gap-2.5 mb-4">
|
||||
<div className="flex-1">
|
||||
<label className={labelCls}>Roast Date</label>
|
||||
<input className={inputCls} type="date" value={form.roastDate} onChange={e => set("roastDate", e.target.value)} />
|
||||
</div>
|
||||
<div className="flex-1">
|
||||
<label className={labelCls}>Roast Type</label>
|
||||
<div className="flex-1"><label className={labelCls}>Roast Date</label>
|
||||
<input className={inputCls} type="date" value={form.roastDate} onChange={e => set("roastDate", e.target.value)} /></div>
|
||||
<div className="flex-1"><label className={labelCls}>Roast Type</label>
|
||||
<select className={inputCls} value={form.roastType} onChange={e => set("roastType", e.target.value)}>
|
||||
<option value="">Select…</option>
|
||||
{ROAST_TYPES.map(r => <option key={r} value={r}>{r}</option>)}
|
||||
</select>
|
||||
</div>
|
||||
</select></div>
|
||||
</div>
|
||||
|
||||
<div className="mb-4">
|
||||
<label className={labelCls}>Bean Photo</label>
|
||||
<div className={`relative border-2 rounded-lg text-center cursor-pointer transition-all overflow-hidden ${form.image ? "border-[#E8DFD3] p-0" : "border-dashed border-[#E8DFD3] p-5 hover:border-[#8B6914] hover:bg-[rgba(139,105,20,0.03)]"}`}>
|
||||
<div className={`relative border-2 rounded-lg text-center cursor-pointer transition-all overflow-hidden ${form.image ? "border-[#E8DFD3] p-0" : "border-dashed border-[#E8DFD3] p-5 hover:border-[#8B6914]"}`}>
|
||||
{form.image ? (
|
||||
<>
|
||||
<img src={form.image} alt="Bean" className="w-full h-40 object-cover rounded-lg block" />
|
||||
<><img src={form.image} alt="Bean" className="w-full h-40 object-cover rounded-lg block" />
|
||||
<button className="absolute top-2 right-2 w-7 h-7 rounded-full bg-[rgba(44,24,16,0.7)] text-white border-none text-sm cursor-pointer flex items-center justify-center"
|
||||
onClick={(e) => { e.stopPropagation(); set("image", ""); }} type="button">×</button>
|
||||
</>
|
||||
) : (
|
||||
<>
|
||||
<div className="text-3xl mb-1.5 opacity-40">📷</div>
|
||||
<div className="text-xs text-[#9C8B7A]">Tap to upload a photo</div>
|
||||
</>
|
||||
)}
|
||||
onClick={(e) => { e.stopPropagation(); set("image", ""); }} type="button">×</button></>
|
||||
) : (<><div className="text-3xl mb-1.5 opacity-40">📷</div><div className="text-xs text-[#9C8B7A]">Tap to upload a photo</div></>)}
|
||||
<input type="file" accept="image/*" onChange={handleImage} className="absolute inset-0 opacity-0 cursor-pointer" />
|
||||
</div>
|
||||
<div className="text-[11px] text-[#9C8B7A] mt-1">Max 2 MB · JPG, PNG, or WebP</div>
|
||||
</div>
|
||||
|
||||
<div className="mb-4">
|
||||
<label className={labelCls}>Tasting Notes</label>
|
||||
<textarea className={`${inputCls} resize-y min-h-[80px]`} placeholder="e.g. Citrus, dark chocolate, floral with a honey finish…" value={form.tastingNotes || ""} onChange={e => set("tastingNotes", e.target.value)} />
|
||||
<div className="text-[11px] text-[#9C8B7A] mt-1">Flavour profile from the bag or your own impressions</div>
|
||||
</div>
|
||||
|
||||
<button
|
||||
className="w-full py-3.5 border-none rounded-lg text-sm font-semibold tracking-wide transition-opacity mt-2 cursor-pointer bg-[#2C1810] text-[#FAF6F1]"
|
||||
style={{ opacity: canSave ? 1 : 0.4, cursor: canSave ? "pointer" : "not-allowed" }}
|
||||
disabled={!canSave}
|
||||
<div className="mb-4"><label className={labelCls}>Tasting Notes</label>
|
||||
<textarea className={`${inputCls} resize-y min-h-[80px]`} placeholder="e.g. Citrus, dark chocolate, floral…" value={form.tastingNotes || ""} onChange={e => set("tastingNotes", e.target.value)} />
|
||||
<div className="text-[11px] text-[#9C8B7A] mt-1">Flavour profile from the bag or your own impressions</div></div>
|
||||
<button className="w-full py-3.5 border-none rounded-xl bg-[#2C1810] text-[#FAF6F1] text-sm font-semibold cursor-pointer mt-2"
|
||||
style={{ opacity: canSave ? 1 : 0.4, cursor: canSave ? "pointer" : "not-allowed" }} disabled={!canSave}
|
||||
onClick={() => { if (canSave) onSave(form); }}>
|
||||
{initial ? "Save Changes" : "Add to Library"}
|
||||
</button>
|
||||
@@ -144,6 +136,7 @@ function BeanForm({ onSave, onClose, initial }) {
|
||||
);
|
||||
}
|
||||
|
||||
// ─── Brew Form ───
|
||||
function BrewForm({ beans, onSave, onClose }) {
|
||||
const [method, setMethod] = useState("pourover");
|
||||
const [form, setForm] = useState({ beanId: beans[0]?.id || "" });
|
||||
@@ -152,15 +145,15 @@ function BrewForm({ beans, onSave, onClose }) {
|
||||
if (beans.length === 0) {
|
||||
return (
|
||||
<div className="fixed inset-0 bg-[rgba(44,24,16,0.4)] z-[100] flex items-end justify-center animate-fade-in" onClick={onClose}>
|
||||
<div className="bg-[#FAF6F1] rounded-t-[20px] w-full max-w-[480px] max-h-[88vh] overflow-y-auto animate-slide-up px-5 pb-8" onClick={e => e.stopPropagation()}>
|
||||
<div className="bg-[#FAF6F1] rounded-t-[24px] w-full max-w-[480px] max-h-[88vh] overflow-y-auto animate-slide-up px-5 pb-8" onClick={e => e.stopPropagation()}>
|
||||
<div className="w-9 h-1 bg-[#E8DFD3] rounded mx-auto my-3" />
|
||||
<div className="font-serif text-xl font-semibold text-[#2C1810] mb-5">Log a Brew</div>
|
||||
<div className="text-center py-12 text-[#9C8B7A]">
|
||||
<div className="text-4xl mb-3 opacity-50">🫘</div>
|
||||
<h3 className="text-base mb-1.5 text-[#6B5744]">No beans yet</h3>
|
||||
<p className="text-[13px] leading-relaxed">Add a bean to your library first, then come back to log a brew.</p>
|
||||
<p className="text-[13px] leading-relaxed">Add a bean to your library first.</p>
|
||||
</div>
|
||||
<button className="w-full py-3.5 border border-[#E8DFD3] rounded-lg text-sm font-semibold text-[#6B5744] bg-transparent cursor-pointer mt-2" onClick={onClose}>Close</button>
|
||||
<button className="w-full py-3.5 border border-[#E8DFD3] rounded-xl text-sm font-semibold text-[#6B5744] bg-transparent cursor-pointer" onClick={onClose}>Close</button>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
@@ -191,29 +184,23 @@ function BrewForm({ beans, onSave, onClose }) {
|
||||
|
||||
return (
|
||||
<div className="fixed inset-0 bg-[rgba(44,24,16,0.4)] z-[100] flex items-end justify-center animate-fade-in" onClick={onClose}>
|
||||
<div className="bg-[#FAF6F1] rounded-t-[20px] w-full max-w-[480px] max-h-[88vh] overflow-y-auto animate-slide-up px-5 pb-8" onClick={e => e.stopPropagation()}>
|
||||
<div className="bg-[#FAF6F1] rounded-t-[24px] w-full max-w-[480px] max-h-[88vh] overflow-y-auto animate-slide-up px-5 pb-8" onClick={e => e.stopPropagation()}>
|
||||
<div className="w-9 h-1 bg-[#E8DFD3] rounded mx-auto my-3" />
|
||||
<div className="font-serif text-xl font-semibold text-[#2C1810] mb-5">Log a Brew</div>
|
||||
|
||||
<div className="flex gap-1.5 mb-5">
|
||||
{METHODS.map(m => (
|
||||
<button key={m}
|
||||
className={`flex-1 py-3 px-2 border-2 bg-white rounded-lg cursor-pointer text-center text-xs font-semibold transition-all tracking-wide ${method === m ? "border-current" : "border-[#E8DFD3] text-[#9C8B7A]"}`}
|
||||
className={`flex-1 py-3 px-2 border-2 bg-white rounded-xl cursor-pointer text-center text-xs font-semibold transition-all ${method === m ? "border-current" : "border-[#E8DFD3] text-[#9C8B7A]"}`}
|
||||
style={{ color: method === m ? METHOD_COLORS[m] : undefined }}
|
||||
onClick={() => setMethod(m)}>
|
||||
<div className="text-xl mb-1">{METHOD_ICONS[m]}</div>
|
||||
{METHOD_LABELS[m]}
|
||||
<div className="text-xl mb-1">{METHOD_ICONS[m]}</div>{METHOD_LABELS[m]}
|
||||
</button>
|
||||
))}
|
||||
</div>
|
||||
|
||||
<div className="mb-4">
|
||||
<label className={labelCls}>Bean *</label>
|
||||
<div className="mb-4"><label className={labelCls}>Bean *</label>
|
||||
<select className={inputCls} value={form.beanId} onChange={e => set("beanId", e.target.value)}>
|
||||
{beans.map(b => <option key={b.id} value={b.id}>{b.name}{b.roastery ? ` — ${b.roastery}` : ""}</option>)}
|
||||
</select>
|
||||
</div>
|
||||
|
||||
</select></div>
|
||||
<div className="flex flex-wrap gap-2.5 mb-4">
|
||||
{fields[method].map(f => (
|
||||
<div key={f.key} className="flex-1 min-w-[45%]">
|
||||
@@ -224,79 +211,59 @@ function BrewForm({ beans, onSave, onClose }) {
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
|
||||
<div className="mb-4">
|
||||
<label className={labelCls}>{method === "pourover" ? "Recipe Details" : "Notes"}</label>
|
||||
<div className="mb-4"><label className={labelCls}>{method === "pourover" ? "Recipe Details" : "Notes"}</label>
|
||||
<textarea className={`${inputCls} resize-y min-h-[80px]`}
|
||||
placeholder="Describe your recipe, technique, or anything notable…"
|
||||
value={form.recipeDetails || ""} onChange={e => set("recipeDetails", e.target.value)} />
|
||||
</div>
|
||||
<div className="mb-4">
|
||||
<label className={labelCls}>Taste Notes</label>
|
||||
value={form.recipeDetails || ""} onChange={e => set("recipeDetails", e.target.value)} /></div>
|
||||
<div className="mb-4"><label className={labelCls}>Taste Notes</label>
|
||||
<input className={inputCls} placeholder="e.g. citrus, chocolate, floral"
|
||||
value={form.tasteNotes || ""} onChange={e => set("tasteNotes", e.target.value)} />
|
||||
</div>
|
||||
|
||||
<button className="w-full py-3.5 border-none rounded-lg bg-[#2C1810] text-[#FAF6F1] text-sm font-semibold tracking-wide transition-opacity hover:opacity-90 mt-2 cursor-pointer"
|
||||
onClick={() => onSave({ ...form, method })}>
|
||||
Save Brew Log
|
||||
</button>
|
||||
value={form.tasteNotes || ""} onChange={e => set("tasteNotes", e.target.value)} /></div>
|
||||
<button className="w-full py-3.5 border-none rounded-xl bg-[#2C1810] text-[#FAF6F1] text-sm font-semibold cursor-pointer hover:opacity-90 mt-2"
|
||||
onClick={() => onSave({ ...form, method })}>Save Brew Log</button>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
// ─── Bean Detail ───
|
||||
function BeanDetail({ bean, logs, onBack, onEdit, onDelete }) {
|
||||
const beanLogs = logs.filter(l => l.beanId === bean.id).sort((a, b) => b.createdAt - a.createdAt);
|
||||
const roastTagCls = bean.roastType?.toLowerCase().includes("dark")
|
||||
? "bg-[#E0D0BD] text-[#4A3520]"
|
||||
: bean.roastType?.toLowerCase().includes("medium")
|
||||
? "bg-[#F0E0C8] text-[#6B4E2A]"
|
||||
const roastTagCls = bean.roastType?.toLowerCase().includes("dark") ? "bg-[#E0D0BD] text-[#4A3520]"
|
||||
: bean.roastType?.toLowerCase().includes("medium") ? "bg-[#F0E0C8] text-[#6B4E2A]"
|
||||
: "bg-[#FFF3D6] text-[#8B6914]";
|
||||
|
||||
return (
|
||||
<div>
|
||||
<button className="flex items-center gap-1.5 bg-none border-none font-sans text-[13px] text-[#6B5744] cursor-pointer p-0 mb-4" onClick={onBack}>
|
||||
← Back
|
||||
</button>
|
||||
{bean.image && <img src={bean.image} alt={bean.name} className="w-full h-44 object-cover rounded-xl mb-4" />}
|
||||
<button className="flex items-center gap-1.5 border-none bg-transparent text-[13px] text-[#6B5744] cursor-pointer p-0 mb-4" onClick={onBack}>← Back</button>
|
||||
{bean.image && <img src={bean.image} alt={bean.name} className="w-full h-44 object-cover rounded-2xl mb-4" />}
|
||||
<h2 className="font-serif text-[22px] font-semibold text-[#2C1810] mb-1">{bean.name}</h2>
|
||||
{bean.roastery && <div className="text-[#6B5744] text-sm mb-2">{bean.roastery}</div>}
|
||||
{bean.tastingNotes && <div className="text-[13px] text-[#6B5744] italic mt-1.5 leading-snug mb-2.5">👅 {bean.tastingNotes}</div>}
|
||||
<div className="flex gap-2 mt-2.5 flex-wrap">
|
||||
{bean.roastType && <span className={`text-[11px] px-2.5 py-1 rounded-full font-medium tracking-wide ${roastTagCls}`}>{bean.roastType}</span>}
|
||||
{bean.roastType && <span className={`text-[11px] px-2.5 py-1 rounded-full font-medium ${roastTagCls}`}>{bean.roastType}</span>}
|
||||
{bean.roastDate && <span className="text-[11px] px-2.5 py-1 rounded-full bg-[#F3EDE4] text-[#6B5744] font-medium">Roasted {bean.roastDate}</span>}
|
||||
<span className="text-[11px] px-2.5 py-1 rounded-full bg-[#F3EDE4] text-[#6B5744] font-medium">{beanLogs.length} brew{beanLogs.length !== 1 ? "s" : ""}</span>
|
||||
</div>
|
||||
|
||||
<div className="flex gap-2 mt-4">
|
||||
<button className="flex-1 py-2.5 border border-[#E8DFD3] rounded-lg text-sm font-semibold text-[#6B5744] bg-transparent cursor-pointer hover:bg-[#F3EDE4] transition-colors" onClick={onEdit}>Edit</button>
|
||||
<button className="flex-1 py-2.5 border border-[#B44040] rounded-lg text-xs font-semibold text-[#B44040] bg-transparent cursor-pointer hover:bg-[rgba(180,64,64,0.05)] transition-colors" onClick={onDelete}>Delete</button>
|
||||
<button className="flex-1 py-2.5 border border-[#E8DFD3] rounded-xl text-sm font-semibold text-[#6B5744] bg-transparent cursor-pointer hover:bg-[#F3EDE4] transition-colors" onClick={onEdit}>Edit</button>
|
||||
<button className="flex-1 py-2.5 border border-[#B44040] rounded-xl text-xs font-semibold text-[#B44040] bg-transparent cursor-pointer" onClick={onDelete}>Delete</button>
|
||||
</div>
|
||||
|
||||
<div className="mt-5">
|
||||
<div className="text-[13px] font-semibold text-[#6B5744] uppercase tracking-widest mb-3">Brew History</div>
|
||||
{beanLogs.length === 0 ? (
|
||||
<div className="text-center py-6 text-[#9C8B7A]">
|
||||
<p className="text-[13px]">No brews logged with this bean yet.</p>
|
||||
</div>
|
||||
<div className="text-center py-6 text-[#9C8B7A]"><p className="text-[13px]">No brews logged with this bean yet.</p></div>
|
||||
) : beanLogs.map(log => <BrewCard key={log.id} log={log} beanName={bean.name} />)}
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
// ─── Brew Card ───
|
||||
function BrewCard({ log, beanName }) {
|
||||
const color = METHOD_COLORS[log.method];
|
||||
const allFields = Object.entries(log)
|
||||
.filter(([k]) => !["id", "beanId", "method", "createdAt", "recipeDetails", "tasteNotes", "updatedAt", "isDeleted"].includes(k))
|
||||
.filter(([, v]) => v !== "" && v != null);
|
||||
const fieldLabels = {
|
||||
grindSize: "Grind", waterTemp: "Temp", beanWeight: "Weight", brewRatio: "Ratio",
|
||||
brewTime: "Time", numPours: "Pours", dose: "Dose", yield: "Yield",
|
||||
waterVolume: "Water", steepTime: "Steep",
|
||||
};
|
||||
|
||||
const fieldLabels = { grindSize: "Grind", waterTemp: "Temp", beanWeight: "Weight", brewRatio: "Ratio", brewTime: "Time", numPours: "Pours", dose: "Dose", yield: "Yield", waterVolume: "Water", steepTime: "Steep" };
|
||||
return (
|
||||
<div className="relative mb-3">
|
||||
<div className="brew-method-bar" style={{ background: color }} />
|
||||
@@ -325,6 +292,120 @@ function BrewCard({ log, beanName }) {
|
||||
);
|
||||
}
|
||||
|
||||
// ─── Profile Page ───
|
||||
function ProfilePage({ user, isOnline, syncing, showSyncedStatus }) {
|
||||
const { logout } = useContext(AuthContext);
|
||||
return (
|
||||
<div>
|
||||
{/* Avatar & Name */}
|
||||
<div className="flex flex-col items-center pt-6 pb-8">
|
||||
<div className="w-20 h-20 rounded-full bg-[#2C1810] flex items-center justify-center text-3xl text-[#FAF6F1] font-serif font-bold mb-3">
|
||||
{user?.username?.[0]?.toUpperCase() || "☕"}
|
||||
</div>
|
||||
<div className="font-serif text-xl font-semibold text-[#2C1810]">{user?.username}</div>
|
||||
<div className="text-sm text-[#9C8B7A] mt-0.5">{user?.email}</div>
|
||||
{showSyncedStatus && (
|
||||
<div className={`flex items-center gap-1.5 text-[11px] font-medium px-3 py-1.5 rounded-full mt-3 transition-all ${isOnline ? "text-[#4A7C59] bg-[rgba(74,124,89,0.1)]" : "text-[#B44040] bg-[rgba(180,64,64,0.1)]"}`}>
|
||||
<span className={`text-[10px] ${syncing ? "animate-sync-pulse" : ""}`}>●</span>
|
||||
<span>{isOnline ? (syncing ? "Syncing…" : "All data synced") : "Offline — saved locally"}</span>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
|
||||
{/* Account section */}
|
||||
<div className="mb-6">
|
||||
<div className="text-[11px] font-semibold uppercase tracking-widest text-[#9C8B7A] mb-2 px-1">Account</div>
|
||||
<div className="bg-white rounded-2xl border border-[#E8DFD3] overflow-hidden">
|
||||
<div className="flex items-center gap-3 px-4 py-3.5 border-b border-[#F3EDE4]">
|
||||
<span className="text-lg">👤</span>
|
||||
<div>
|
||||
<div className="text-xs text-[#9C8B7A]">Username</div>
|
||||
<div className="text-sm font-medium text-[#2C1810]">{user?.username}</div>
|
||||
</div>
|
||||
</div>
|
||||
<div className="flex items-center gap-3 px-4 py-3.5">
|
||||
<span className="text-lg">✉️</span>
|
||||
<div>
|
||||
<div className="text-xs text-[#9C8B7A]">Email</div>
|
||||
<div className="text-sm font-medium text-[#2C1810]">{user?.email}</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* App info */}
|
||||
<div className="mb-6">
|
||||
<div className="text-[11px] font-semibold uppercase tracking-widest text-[#9C8B7A] mb-2 px-1">App</div>
|
||||
<div className="bg-white rounded-2xl border border-[#E8DFD3] overflow-hidden">
|
||||
<div className="flex items-center justify-between px-4 py-3.5 border-b border-[#F3EDE4]">
|
||||
<div className="flex items-center gap-3">
|
||||
<span className="text-lg">☕</span>
|
||||
<div className="text-sm font-medium text-[#2C1810]">Brew Journal</div>
|
||||
</div>
|
||||
<div className="text-xs text-[#9C8B7A] font-mono">{__APP_VERSION__}</div>
|
||||
</div>
|
||||
<div className="flex items-center gap-3 px-4 py-3.5">
|
||||
<span className="text-lg">🗄️</span>
|
||||
<div>
|
||||
<div className="text-xs text-[#9C8B7A]">Storage</div>
|
||||
<div className="text-sm font-medium text-[#2C1810]">Local + PostgreSQL</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* Sign out */}
|
||||
<button
|
||||
onClick={() => logout()}
|
||||
className="w-full py-3.5 border border-[#B44040] rounded-2xl text-sm font-semibold text-[#B44040] bg-transparent cursor-pointer hover:bg-[rgba(180,64,64,0.05)] transition-colors">
|
||||
Sign Out
|
||||
</button>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
// ─── Bottom Nav ───
|
||||
function BottomNav({ view, setView, setSelectedBean, onCreatePress }) {
|
||||
const items = [
|
||||
{ id: "dashboard", label: "Home", icon: "🏠" },
|
||||
{ id: "beans", label: "Recipes", icon: "🫘" },
|
||||
{ id: "create", label: "Create", icon: "+", isAction: true },
|
||||
{ id: "brews", label: "Logs", icon: "📋" },
|
||||
{ id: "profile", label: "Profile", icon: "👤" },
|
||||
];
|
||||
|
||||
return (
|
||||
<div className="fixed bottom-4 left-1/2 -translate-x-1/2 w-[calc(100%-32px)] max-w-[448px] z-[60]">
|
||||
<div className="bg-white/90 backdrop-blur-md border border-[#E8DFD3] rounded-[28px] shadow-[0_8px_32px_rgba(44,24,16,0.12),0_2px_8px_rgba(44,24,16,0.08)] flex items-center px-2 py-2">
|
||||
{items.map(item => {
|
||||
const isActive = view === item.id;
|
||||
if (item.isAction) {
|
||||
return (
|
||||
<button
|
||||
key={item.id}
|
||||
onClick={onCreatePress}
|
||||
className="flex-1 flex flex-col items-center justify-center mx-1">
|
||||
<div className="w-12 h-12 rounded-full bg-[#2C1810] flex items-center justify-center text-[#FAF6F1] text-2xl font-light shadow-[0_4px_12px_rgba(44,24,16,0.25)] transition-transform active:scale-90 hover:scale-105">
|
||||
+
|
||||
</div>
|
||||
</button>
|
||||
);
|
||||
}
|
||||
return (
|
||||
<button
|
||||
key={item.id}
|
||||
onClick={() => { setView(item.id); setSelectedBean(null); }}
|
||||
className={`flex-1 flex flex-col items-center gap-0.5 py-1.5 rounded-[20px] cursor-pointer border-none transition-all ${isActive ? "bg-[#FAF6F1]" : "bg-transparent"}`}>
|
||||
<span className={`text-xl transition-transform ${isActive ? "scale-110" : "scale-100 opacity-50"}`}>{item.icon}</span>
|
||||
<span className={`text-[10px] font-semibold tracking-wide transition-colors ${isActive ? "text-[#2C1810]" : "text-[#9C8B7A]"}`}>{item.label}</span>
|
||||
</button>
|
||||
);
|
||||
})}
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
// ─── Main App ───
|
||||
export default function CoffeeLogbook() {
|
||||
const { token, user, loading, logout } = useContext(AuthContext);
|
||||
@@ -332,7 +413,7 @@ export default function CoffeeLogbook() {
|
||||
const [data, setData] = useState(null);
|
||||
const [view, setView] = useState("dashboard");
|
||||
const [modal, setModal] = useState(null);
|
||||
const [fabOpen, setFabOpen] = useState(false);
|
||||
const [createOpen, setCreateOpen] = useState(false);
|
||||
const [selectedBean, setSelectedBean] = useState(null);
|
||||
const [brewFilter, setBrewFilter] = useState("all");
|
||||
const [editingBean, setEditingBean] = useState(null);
|
||||
@@ -341,114 +422,59 @@ export default function CoffeeLogbook() {
|
||||
const [syncing, setSyncing] = useState(false);
|
||||
const [showSyncedStatus, setShowSyncedStatus] = useState(false);
|
||||
|
||||
// Load local data on mount
|
||||
useEffect(() => {
|
||||
loadData().then(setData);
|
||||
}, []);
|
||||
useEffect(() => { loadData().then(setData); }, []);
|
||||
|
||||
const dataRef = useRef(data);
|
||||
dataRef.current = data;
|
||||
|
||||
// Sync logic
|
||||
const syncData = useCallback(async (currentData = dataRef.current) => {
|
||||
if (!token || !currentData) return;
|
||||
if (!navigator.onLine) {
|
||||
setIsOnline(false);
|
||||
setShowSyncedStatus(true);
|
||||
return;
|
||||
}
|
||||
setIsOnline(true);
|
||||
setSyncing(true);
|
||||
setShowSyncedStatus(true);
|
||||
|
||||
if (!navigator.onLine) { setIsOnline(false); setShowSyncedStatus(true); return; }
|
||||
setIsOnline(true); setSyncing(true); setShowSyncedStatus(true);
|
||||
try {
|
||||
const { beans = [], brewLogs = [], lastSyncedAt = null } = currentData;
|
||||
|
||||
const res = await fetch('/api/sync', {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
'Authorization': `Bearer ${token}`
|
||||
},
|
||||
headers: { 'Content-Type': 'application/json', 'Authorization': `Bearer ${token}` },
|
||||
body: JSON.stringify({ lastSyncedAt, beans, brewLogs })
|
||||
});
|
||||
|
||||
if (!res.ok) throw new Error('Sync failed');
|
||||
|
||||
const responseData = await res.json();
|
||||
const { serverTime, beans: serverBeans, brewLogs: serverLogs } = responseData;
|
||||
|
||||
// Merge server beans
|
||||
const { serverTime, beans: serverBeans, brewLogs: serverLogs } = await res.json();
|
||||
const mergedBeans = [...beans];
|
||||
serverBeans.forEach(sb => {
|
||||
const idx = mergedBeans.findIndex(b => b.id === sb.id);
|
||||
if (idx >= 0) {
|
||||
if (new Date(sb.updatedAt) > new Date(mergedBeans[idx].updatedAt || 0)) mergedBeans[idx] = sb;
|
||||
} else {
|
||||
mergedBeans.push(sb);
|
||||
}
|
||||
});
|
||||
|
||||
// Merge server logs
|
||||
serverBeans.forEach(sb => { const i = mergedBeans.findIndex(b => b.id === sb.id); i >= 0 ? (new Date(sb.updatedAt) > new Date(mergedBeans[i].updatedAt || 0) && (mergedBeans[i] = sb)) : mergedBeans.push(sb); });
|
||||
const mergedLogs = [...brewLogs];
|
||||
serverLogs.forEach(sl => {
|
||||
const idx = mergedLogs.findIndex(l => l.id === sl.id);
|
||||
if (idx >= 0) {
|
||||
if (new Date(sl.updatedAt) > new Date(mergedLogs[idx].updatedAt || 0)) mergedLogs[idx] = sl;
|
||||
} else {
|
||||
mergedLogs.push(sl);
|
||||
}
|
||||
});
|
||||
|
||||
const finalBeans = mergedBeans.filter(b => !(b.isDeleted && new Date(b.updatedAt) <= new Date(serverTime)));
|
||||
const finalLogs = mergedLogs.filter(l => !(l.isDeleted && new Date(l.updatedAt) <= new Date(serverTime)));
|
||||
|
||||
const nextData = { beans: finalBeans, brewLogs: finalLogs, lastSyncedAt: serverTime };
|
||||
setData(nextData);
|
||||
await saveData(nextData);
|
||||
} catch (err) {
|
||||
console.error('Failed to sync data:', err);
|
||||
} finally {
|
||||
serverLogs.forEach(sl => { const i = mergedLogs.findIndex(l => l.id === sl.id); i >= 0 ? (new Date(sl.updatedAt) > new Date(mergedLogs[i].updatedAt || 0) && (mergedLogs[i] = sl)) : mergedLogs.push(sl); });
|
||||
const nextData = {
|
||||
beans: mergedBeans.filter(b => !(b.isDeleted && new Date(b.updatedAt) <= new Date(serverTime))),
|
||||
brewLogs: mergedLogs.filter(l => !(l.isDeleted && new Date(l.updatedAt) <= new Date(serverTime))),
|
||||
lastSyncedAt: serverTime
|
||||
};
|
||||
setData(nextData); await saveData(nextData);
|
||||
} catch (err) { console.error('Failed to sync data:', err); }
|
||||
finally {
|
||||
setSyncing(false);
|
||||
if (navigator.onLine) {
|
||||
setTimeout(() => setShowSyncedStatus(false), 2500);
|
||||
} else {
|
||||
setShowSyncedStatus(true);
|
||||
}
|
||||
if (navigator.onLine) setTimeout(() => setShowSyncedStatus(false), 2500);
|
||||
else setShowSyncedStatus(true);
|
||||
}
|
||||
}, [token]);
|
||||
|
||||
// Periodic and event-driven sync triggers
|
||||
useEffect(() => {
|
||||
const handleOnline = () => { setIsOnline(true); syncData(); };
|
||||
const handleOffline = () => { setIsOnline(false); setShowSyncedStatus(true); };
|
||||
|
||||
window.addEventListener('online', handleOnline);
|
||||
window.addEventListener('offline', handleOffline);
|
||||
|
||||
if (token && data) syncData();
|
||||
|
||||
const interval = setInterval(() => { if (token && data) syncData(); }, 30000);
|
||||
|
||||
return () => {
|
||||
window.removeEventListener('online', handleOnline);
|
||||
window.removeEventListener('offline', handleOffline);
|
||||
clearInterval(interval);
|
||||
};
|
||||
return () => { window.removeEventListener('online', handleOnline); window.removeEventListener('offline', handleOffline); clearInterval(interval); };
|
||||
}, [token, data === null, syncData]);
|
||||
|
||||
const persist = useCallback(async (newData) => {
|
||||
setData(newData);
|
||||
await saveData(newData);
|
||||
syncData(newData);
|
||||
setData(newData); await saveData(newData); syncData(newData);
|
||||
}, [syncData]);
|
||||
|
||||
const LoadingScreen = () => (
|
||||
<div className="w-full max-w-[480px] mx-auto min-h-screen border-x border-[#E8DFD3] bg-[#FAF6F1] flex items-center justify-center">
|
||||
<div className="text-center text-[#9C8B7A]">
|
||||
<div className="text-4xl">☕</div>
|
||||
<div className="mt-2 text-sm">Loading…</div>
|
||||
</div>
|
||||
<div className="w-full max-w-[480px] mx-auto min-h-screen border-x border-[#E8DFD3] bg-[#FAF6F1] max-sm:border-x-0 flex items-center justify-center">
|
||||
<div className="text-center text-[#9C8B7A]"><div className="text-4xl">☕</div><div className="mt-2 text-sm">Loading…</div></div>
|
||||
</div>
|
||||
);
|
||||
|
||||
@@ -456,15 +482,13 @@ export default function CoffeeLogbook() {
|
||||
|
||||
if (!token || !user) {
|
||||
return (
|
||||
<div className="w-full max-w-[480px] mx-auto min-h-screen border-x border-[#E8DFD3] bg-[#FAF6F1]">
|
||||
<div className="w-full max-w-[480px] mx-auto min-h-screen border-x border-[#E8DFD3] bg-[#FAF6F1] max-sm:border-x-0">
|
||||
{authView === "login" ? (
|
||||
<>
|
||||
<Login onLoginSuccess={() => {}} />
|
||||
<div className="text-center mt-5 px-5">
|
||||
<p className="text-[#9C8B7A] text-sm">Don't have an account?{' '}
|
||||
<button onClick={() => setAuthView("register")} className="bg-none border-none text-[#8B6914] cursor-pointer underline text-sm">
|
||||
Register
|
||||
</button>
|
||||
<button onClick={() => setAuthView("register")} className="border-none bg-transparent text-[#8B6914] cursor-pointer underline text-sm">Register</button>
|
||||
</p>
|
||||
</div>
|
||||
</>
|
||||
@@ -473,9 +497,7 @@ export default function CoffeeLogbook() {
|
||||
<Register onRegisterSuccess={() => setAuthView("login")} />
|
||||
<div className="text-center mt-5 px-5">
|
||||
<p className="text-[#9C8B7A] text-sm">Already have an account?{' '}
|
||||
<button onClick={() => setAuthView("login")} className="bg-none border-none text-[#8B6914] cursor-pointer underline text-sm">
|
||||
Login
|
||||
</button>
|
||||
<button onClick={() => setAuthView("login")} className="border-none bg-transparent text-[#8B6914] cursor-pointer underline text-sm">Login</button>
|
||||
</p>
|
||||
</div>
|
||||
</>
|
||||
@@ -491,124 +513,79 @@ export default function CoffeeLogbook() {
|
||||
const beans = allBeans.filter(b => !b.isDeleted);
|
||||
const brewLogs = allLogs.filter(l => !l.isDeleted);
|
||||
|
||||
const addBean = (form) => {
|
||||
const now = new Date().toISOString();
|
||||
const bean = { id: uid(), ...form, updatedAt: now, isDeleted: false };
|
||||
persist({ ...data, beans: [...allBeans, bean] });
|
||||
setModal(null);
|
||||
};
|
||||
|
||||
const addBean = (form) => { persist({ ...data, beans: [...allBeans, { id: uid(), ...form, updatedAt: new Date().toISOString(), isDeleted: false }] }); setModal(null); };
|
||||
const updateBean = (form) => {
|
||||
const now = new Date().toISOString();
|
||||
const nextBeans = allBeans.map(b => b.id === editingBean.id ? { ...b, ...form, updatedAt: now } : b);
|
||||
persist({ ...data, beans: nextBeans });
|
||||
setModal(null);
|
||||
setEditingBean(null);
|
||||
persist({ ...data, beans: allBeans.map(b => b.id === editingBean.id ? { ...b, ...form, updatedAt: now } : b) });
|
||||
setModal(null); setEditingBean(null);
|
||||
if (selectedBean?.id === editingBean.id) setSelectedBean({ ...selectedBean, ...form, updatedAt: now });
|
||||
};
|
||||
|
||||
const deleteBean = (id) => {
|
||||
const now = new Date().toISOString();
|
||||
const nextBeans = allBeans.map(b => b.id === id ? { ...b, isDeleted: true, updatedAt: now } : b);
|
||||
const nextLogs = allLogs.map(l => l.beanId === id ? { ...l, isDeleted: true, updatedAt: now } : l);
|
||||
persist({ ...data, beans: nextBeans, brewLogs: nextLogs });
|
||||
persist({ ...data, beans: allBeans.map(b => b.id === id ? { ...b, isDeleted: true, updatedAt: now } : b), brewLogs: allLogs.map(l => l.beanId === id ? { ...l, isDeleted: true, updatedAt: now } : l) });
|
||||
setSelectedBean(null);
|
||||
};
|
||||
|
||||
const addBrew = (form) => {
|
||||
const now = new Date().toISOString();
|
||||
const log = { id: uid(), createdAt: Date.now(), ...form, updatedAt: now, isDeleted: false };
|
||||
persist({ ...data, brewLogs: [...allLogs, log] });
|
||||
setModal(null);
|
||||
};
|
||||
const addBrew = (form) => { persist({ ...data, brewLogs: [...allLogs, { id: uid(), createdAt: Date.now(), ...form, updatedAt: new Date().toISOString(), isDeleted: false }] }); setModal(null); };
|
||||
|
||||
const getBeanName = (id) => allBeans.find(b => b.id === id)?.name || "Unknown Bean";
|
||||
const filteredLogs = (brewFilter === "all" ? brewLogs : brewLogs.filter(l => l.method === brewFilter)).sort((a, b) => b.createdAt - a.createdAt);
|
||||
const methodCounts = { pourover: 0, espresso: 0, coldbrew: 0 };
|
||||
brewLogs.forEach(l => { if (methodCounts[l.method] !== undefined) methodCounts[l.method]++; });
|
||||
|
||||
const navBtnCls = (active) => `flex-1 py-2.5 px-2 border-none text-[13px] font-medium cursor-pointer rounded-lg transition-all tracking-wide ${
|
||||
active ? "bg-[#2C1810] text-[#FAF6F1] font-semibold" : "bg-transparent text-[#9C8B7A] hover:bg-[#F3EDE4] hover:text-[#2C1810]"
|
||||
}`;
|
||||
const filterPillCls = (active) => `px-3.5 py-1.5 rounded-full border text-xs font-medium whitespace-nowrap cursor-pointer transition-all ${active ? "bg-[#2C1810] text-[#FAF6F1] border-[#2C1810]" : "bg-white border-[#E8DFD3] text-[#6B5744]"}`;
|
||||
|
||||
const filterPillCls = (active) => `px-3.5 py-1.5 rounded-full border text-xs font-medium whitespace-nowrap cursor-pointer transition-all ${
|
||||
active ? "bg-[#2C1810] text-[#FAF6F1] border-[#2C1810]" : "bg-white border-[#E8DFD3] text-[#6B5744] hover:bg-[#F3EDE4]"
|
||||
}`;
|
||||
// Page title per view
|
||||
const pageTitles = { dashboard: "Brew Journal", beans: "Bean Recipes", brews: "Brew Logs", profile: "Profile" };
|
||||
const pageSubtitles = { dashboard: "Coffee Logbook", beans: "Your Collection", brews: "All Sessions", profile: "Account" };
|
||||
|
||||
return (
|
||||
<div className="w-full max-w-[480px] mx-auto min-h-screen bg-[#FAF6F1] border-x border-[#E8DFD3] shadow-[0_0_30px_rgba(44,24,16,0.05)] relative max-sm:border-x-0 max-sm:shadow-none font-sans">
|
||||
<div className="w-full max-w-[480px] mx-auto min-h-screen bg-[#FAF6F1] border-x border-[#E8DFD3] shadow-[0_0_30px_rgba(44,24,16,0.05)] max-sm:border-x-0 max-sm:shadow-none font-sans relative">
|
||||
|
||||
{/* Header */}
|
||||
<div className="px-5 pt-6 pb-4 flex items-center justify-between sticky top-0 bg-[#FAF6F1] z-50 border-b border-[#E8DFD3]">
|
||||
<div className="px-5 pt-6 pb-4 flex items-center justify-between sticky top-0 bg-[#FAF6F1]/95 backdrop-blur-sm z-50 border-b border-[#E8DFD3]">
|
||||
<div>
|
||||
<div className="text-[11px] text-[#9C8B7A] font-normal tracking-[1.5px] uppercase">Coffee Logbook</div>
|
||||
<h1 className="font-serif text-[22px] font-semibold tracking-[-0.3px] text-[#2C1810] mt-0.5">Brew Journal</h1>
|
||||
<div className="text-[10px] text-[#9C8B7A] font-semibold tracking-[1.5px] uppercase">{pageSubtitles[view] || "Coffee Logbook"}</div>
|
||||
<h1 className="font-serif text-[21px] font-semibold tracking-tight text-[#2C1810] mt-0.5">{pageTitles[view] || "Brew Journal"}</h1>
|
||||
</div>
|
||||
<div className="flex items-center gap-3">
|
||||
{showSyncedStatus && (
|
||||
<div
|
||||
className={`flex items-center gap-1 text-[11px] font-medium px-2 py-1 rounded-xl transition-all ${isOnline ? "text-[#4A7C59] bg-[rgba(74,124,89,0.08)]" : "text-[#B44040] bg-[rgba(180,64,64,0.08)]"}`}
|
||||
title={isOnline ? "Synchronized with database" : "Offline — saved locally"}
|
||||
>
|
||||
<span className={`text-[10px] ${syncing ? "animate-sync-pulse" : ""}`}>●</span>
|
||||
<span>{isOnline ? (syncing ? "Syncing..." : "Synced") : "Offline"}</span>
|
||||
</div>
|
||||
)}
|
||||
<span className="text-xs text-[#6B5744]">{user?.username}</span>
|
||||
<button onClick={() => logout()} className="text-3xl bg-none border-none cursor-pointer p-1" title="Logout">🚪</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* Nav */}
|
||||
<div className="flex gap-1 px-5 py-2 bg-[#FAF6F1] sticky top-[73px] z-[49]">
|
||||
<button className={navBtnCls(view === "dashboard")} onClick={() => { setView("dashboard"); setSelectedBean(null); }}>Dashboard</button>
|
||||
<button className={navBtnCls(view === "beans")} onClick={() => { setView("beans"); setSelectedBean(null); }}>Bean Library</button>
|
||||
<button className={navBtnCls(view === "brews")} onClick={() => { setView("brews"); setSelectedBean(null); }}>Brew Logs</button>
|
||||
{showSyncedStatus && (
|
||||
<div className={`flex items-center gap-1 text-[11px] font-medium px-2.5 py-1 rounded-full transition-all ${isOnline ? "text-[#4A7C59] bg-[rgba(74,124,89,0.1)]" : "text-[#B44040] bg-[rgba(180,64,64,0.1)]"}`}
|
||||
title={isOnline ? "Synchronized" : "Offline"}>
|
||||
<span className={`text-[10px] ${syncing ? "animate-sync-pulse" : ""}`}>●</span>
|
||||
<span>{isOnline ? (syncing ? "Syncing..." : "Synced") : "Offline"}</span>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
|
||||
{/* Content */}
|
||||
<div className="px-5 pt-4 pb-28">
|
||||
<div className="px-5 pt-4 pb-36">
|
||||
|
||||
{/* ── Dashboard ── */}
|
||||
{view === "dashboard" && (
|
||||
<>
|
||||
{/* Stats row */}
|
||||
<div className="flex gap-2 mb-5">
|
||||
{[
|
||||
{ num: beans.length, label: "Beans" },
|
||||
{ num: brewLogs.length, label: "Brews" },
|
||||
{ num: new Set(brewLogs.map(l => l.beanId)).size, label: "Tried" },
|
||||
].map(s => (
|
||||
<div key={s.label} className="flex-1 bg-white border border-[#E8DFD3] rounded-xl p-3.5 text-center">
|
||||
{[{ num: beans.length, label: "Beans" }, { num: brewLogs.length, label: "Brews" }, { num: new Set(brewLogs.map(l => l.beanId)).size, label: "Tried" }].map(s => (
|
||||
<div key={s.label} className="flex-1 bg-white border border-[#E8DFD3] rounded-2xl p-3.5 text-center">
|
||||
<div className="font-serif text-2xl font-bold text-[#2C1810]">{s.num}</div>
|
||||
<div className="text-[10px] text-[#9C8B7A] uppercase tracking-widest mt-0.5">{s.label}</div>
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
|
||||
{/* By Method */}
|
||||
<div className="flex justify-between items-center mb-3">
|
||||
<div className="text-[13px] font-semibold text-[#6B5744] uppercase tracking-widest">By Method</div>
|
||||
</div>
|
||||
<div className="text-[13px] font-semibold text-[#6B5744] uppercase tracking-widest mb-3">By Method</div>
|
||||
<div className="flex gap-2 mb-6">
|
||||
{METHODS.map(m => (
|
||||
<div key={m} className="flex-1 bg-white border border-[#E8DFD3] rounded-xl p-3 text-center" style={{ borderTop: `3px solid ${METHOD_COLORS[m]}` }}>
|
||||
<div key={m} className="flex-1 bg-white border border-[#E8DFD3] rounded-2xl p-3 text-center" style={{ borderTop: `3px solid ${METHOD_COLORS[m]}` }}>
|
||||
<div className="text-xl mb-1">{METHOD_ICONS[m]}</div>
|
||||
<div className="font-serif text-xl font-bold text-[#2C1810]">{methodCounts[m]}</div>
|
||||
<div className="text-[10px] text-[#9C8B7A] uppercase tracking-widest mt-0.5">{METHOD_LABELS[m]}</div>
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
|
||||
{/* Recent Brews */}
|
||||
<div className="flex justify-between items-center mb-3">
|
||||
<div className="text-[13px] font-semibold text-[#6B5744] uppercase tracking-widest">Recent Brews</div>
|
||||
</div>
|
||||
<div className="text-[13px] font-semibold text-[#6B5744] uppercase tracking-widest mb-3">Recent Brews</div>
|
||||
{brewLogs.length === 0 ? (
|
||||
<div className="text-center py-12 text-[#9C8B7A]">
|
||||
<div className="text-4xl mb-3 opacity-50">📝</div>
|
||||
<h3 className="text-base mb-1.5 font-serif text-[#6B5744]">No brews yet</h3>
|
||||
<p className="text-[13px] leading-relaxed">Tap + to add a bean and start logging your brews.</p>
|
||||
<p className="text-[13px] leading-relaxed">Tap the + button to log your first brew.</p>
|
||||
</div>
|
||||
) : brewLogs.sort((a, b) => b.createdAt - a.createdAt).slice(0, 5).map(log => (
|
||||
<BrewCard key={log.id} log={log} beanName={getBeanName(log.beanId)} />
|
||||
@@ -619,28 +596,22 @@ export default function CoffeeLogbook() {
|
||||
{/* ── Bean Library ── */}
|
||||
{view === "beans" && !selectedBean && (
|
||||
<>
|
||||
<div className="flex justify-between items-center mb-3">
|
||||
<div className="text-[13px] font-semibold text-[#6B5744] uppercase tracking-widest">Your Beans ({beans.length})</div>
|
||||
</div>
|
||||
<div className="text-[13px] font-semibold text-[#6B5744] uppercase tracking-widest mb-3">Your Beans ({beans.length})</div>
|
||||
{beans.length === 0 ? (
|
||||
<div className="text-center py-12 text-[#9C8B7A]">
|
||||
<div className="text-4xl mb-3 opacity-50">🫘</div>
|
||||
<h3 className="text-base mb-1.5 font-serif text-[#6B5744]">Library is empty</h3>
|
||||
<p className="text-[13px] leading-relaxed">Add your first bean to start tracking your coffee journey.</p>
|
||||
<p className="text-[13px] leading-relaxed">Tap + to add your first coffee bean.</p>
|
||||
</div>
|
||||
) : beans.map(bean => {
|
||||
const count = brewLogs.filter(l => l.beanId === bean.id).length;
|
||||
const roastTagCls = bean.roastType?.toLowerCase().includes("dark")
|
||||
? "bg-[#E0D0BD] text-[#4A3520]"
|
||||
: bean.roastType?.toLowerCase().includes("medium")
|
||||
? "bg-[#F0E0C8] text-[#6B4E2A]"
|
||||
: "bg-[#FFF3D6] text-[#8B6914]";
|
||||
const roastTagCls = bean.roastType?.toLowerCase().includes("dark") ? "bg-[#E0D0BD] text-[#4A3520]" : bean.roastType?.toLowerCase().includes("medium") ? "bg-[#F0E0C8] text-[#6B4E2A]" : "bg-[#FFF3D6] text-[#8B6914]";
|
||||
return (
|
||||
<div key={bean.id}
|
||||
className="bg-white rounded-xl shadow-[0_1px_3px_rgba(44,24,16,0.06),0_4px_12px_rgba(44,24,16,0.04)] p-[18px] mb-3 border border-[#E8DFD3] cursor-pointer transition-shadow hover:shadow-[0_4px_16px_rgba(44,24,16,0.08),0_12px_32px_rgba(44,24,16,0.06)] active:scale-[0.99]"
|
||||
className="bg-white rounded-2xl shadow-[0_1px_3px_rgba(44,24,16,0.06),0_4px_12px_rgba(44,24,16,0.04)] p-[18px] mb-3 border border-[#E8DFD3] cursor-pointer transition-all hover:shadow-[0_4px_16px_rgba(44,24,16,0.08)] active:scale-[0.99]"
|
||||
onClick={() => setSelectedBean(bean)}>
|
||||
<div className="flex justify-between items-start gap-3 mb-2">
|
||||
{bean.image && <img src={bean.image} alt="" className="w-14 h-14 rounded-lg object-cover flex-shrink-0" />}
|
||||
{bean.image && <img src={bean.image} alt="" className="w-14 h-14 rounded-xl object-cover flex-shrink-0" />}
|
||||
<div className="flex-1 min-w-0">
|
||||
<div className="font-serif text-[17px] font-semibold text-[#2C1810]">{bean.name}</div>
|
||||
{bean.roastery && <div className="text-[13px] text-[#6B5744] mt-0.5">{bean.roastery}</div>}
|
||||
@@ -649,7 +620,7 @@ export default function CoffeeLogbook() {
|
||||
</div>
|
||||
{bean.tastingNotes && <div className="text-[13px] text-[#6B5744] italic mt-1.5 leading-snug">👅 {bean.tastingNotes}</div>}
|
||||
<div className="flex gap-2 mt-2.5 flex-wrap">
|
||||
{bean.roastType && <span className={`text-[11px] px-2.5 py-1 rounded-full font-medium tracking-wide ${roastTagCls}`}>{bean.roastType}</span>}
|
||||
{bean.roastType && <span className={`text-[11px] px-2.5 py-1 rounded-full font-medium ${roastTagCls}`}>{bean.roastType}</span>}
|
||||
{bean.roastDate && <span className="text-[11px] px-2.5 py-1 rounded-full bg-[#F3EDE4] text-[#6B5744] font-medium">Roasted {bean.roastDate}</span>}
|
||||
</div>
|
||||
</div>
|
||||
@@ -660,9 +631,7 @@ export default function CoffeeLogbook() {
|
||||
|
||||
{/* ── Bean Detail ── */}
|
||||
{view === "beans" && selectedBean && (
|
||||
<BeanDetail
|
||||
bean={selectedBean}
|
||||
logs={brewLogs}
|
||||
<BeanDetail bean={selectedBean} logs={brewLogs}
|
||||
onBack={() => setSelectedBean(null)}
|
||||
onEdit={() => { setEditingBean(selectedBean); setModal("editBean"); }}
|
||||
onDelete={() => { if (confirm("Delete this bean and all its brew logs?")) deleteBean(selectedBean.id); }}
|
||||
@@ -691,21 +660,28 @@ export default function CoffeeLogbook() {
|
||||
))}
|
||||
</>
|
||||
)}
|
||||
|
||||
{/* ── Profile ── */}
|
||||
{view === "profile" && (
|
||||
<ProfilePage user={user} isOnline={isOnline} syncing={syncing} showSyncedStatus={showSyncedStatus} />
|
||||
)}
|
||||
</div>
|
||||
|
||||
{/* FAB */}
|
||||
<button
|
||||
className="fixed bottom-6 right-4 sm:right-[calc(50%-220px)] w-14 h-14 rounded-full bg-[#2C1810] text-[#FAF6F1] border-none text-3xl cursor-pointer shadow-[0_4px_16px_rgba(44,24,16,0.08),0_12px_32px_rgba(44,24,16,0.06)] z-[60] flex items-center justify-center transition-transform hover:scale-105 active:scale-95"
|
||||
onClick={() => setFabOpen(!fabOpen)}>
|
||||
{fabOpen ? "×" : "+"}
|
||||
</button>
|
||||
{fabOpen && (
|
||||
<div className="fixed bottom-24 right-4 sm:right-[calc(50%-220px)] flex flex-col gap-2 z-[61] animate-fade-in">
|
||||
<button className="flex items-center gap-2.5 px-4 py-2.5 bg-white border border-[#E8DFD3] rounded-full font-sans text-[13px] font-semibold cursor-pointer shadow-[0_1px_3px_rgba(44,24,16,0.06)] hover:shadow-[0_4px_16px_rgba(44,24,16,0.08)] whitespace-nowrap transition-all"
|
||||
onClick={() => { setFabOpen(false); setModal("addBrew"); }}>☕ Log a Brew</button>
|
||||
<button className="flex items-center gap-2.5 px-4 py-2.5 bg-white border border-[#E8DFD3] rounded-full font-sans text-[13px] font-semibold cursor-pointer shadow-[0_1px_3px_rgba(44,24,16,0.06)] hover:shadow-[0_4px_16px_rgba(44,24,16,0.08)] whitespace-nowrap transition-all"
|
||||
onClick={() => { setFabOpen(false); setModal("addBean"); }}>🫘 Add Bean</button>
|
||||
</div>
|
||||
{/* Floating Bottom Navigation */}
|
||||
<BottomNav
|
||||
view={view}
|
||||
setView={setView}
|
||||
setSelectedBean={setSelectedBean}
|
||||
onCreatePress={() => setCreateOpen(true)}
|
||||
/>
|
||||
|
||||
{/* Create Modal */}
|
||||
{createOpen && (
|
||||
<CreateModal
|
||||
onClose={() => setCreateOpen(false)}
|
||||
onAddBean={() => setModal("addBean")}
|
||||
onAddBrew={() => setModal("addBrew")}
|
||||
/>
|
||||
)}
|
||||
|
||||
{/* Modals */}
|
||||
|
||||
@@ -1,10 +1,33 @@
|
||||
import { defineConfig } from 'vite'
|
||||
import react from '@vitejs/plugin-react'
|
||||
import tailwindcss from '@tailwindcss/vite'
|
||||
import { execSync } from 'child_process'
|
||||
|
||||
// Derive version from git tags; fall back to commit hash
|
||||
function getGitVersion() {
|
||||
try {
|
||||
// If there's a tag pointing at HEAD, use it exactly (e.g. "v1.2.0")
|
||||
// Otherwise use "v0.0.0-<hash>[-dirty]"
|
||||
const raw = execSync('git describe --tags --always --dirty', { stdio: ['pipe', 'pipe', 'ignore'] })
|
||||
.toString()
|
||||
.trim();
|
||||
// If it looks like a pure tag (no dashes after the tag part) return as-is
|
||||
return raw;
|
||||
} catch {
|
||||
return 'dev';
|
||||
}
|
||||
}
|
||||
|
||||
const APP_VERSION = getGitVersion();
|
||||
console.log(`[vite] App version: ${APP_VERSION}`);
|
||||
|
||||
// https://vite.dev/config/
|
||||
export default defineConfig({
|
||||
plugins: [react(), tailwindcss()],
|
||||
define: {
|
||||
// Injected at build time — available as __APP_VERSION__ in source
|
||||
__APP_VERSION__: JSON.stringify(APP_VERSION),
|
||||
},
|
||||
server: {
|
||||
proxy: {
|
||||
'/api': {
|
||||
|
||||
Reference in New Issue
Block a user