diff --git a/src/App.jsx b/src/App.jsx
index 28a162e..d48c629 100644
--- a/src/App.jsx
+++ b/src/App.jsx
@@ -1,7 +1,22 @@
import { useState, useEffect, useCallback, useContext, useRef } from "react";
import { AuthContext } from "./AuthContext";
-import Login from "./Login";
-import Register from "./Register";
+
+// Import pages/views
+import Login from "./pages/Login";
+import Register from "./pages/Register";
+import ProfilePage from "./pages/ProfilePage";
+
+// Import refactored components
+import CreateModal from "./components/CreateModal";
+import BeanForm from "./components/BeanForm";
+import BrewForm from "./components/BrewForm";
+import BeanDetail from "./components/BeanDetail";
+import BrewCard from "./components/BrewCard";
+import BottomNav from "./components/BottomNav";
+
+
+// Import constants
+import { METHODS, METHOD_LABELS, METHOD_ICONS, METHOD_COLORS } from "./constants";
// ─── Storage helpers ───
const STORAGE_KEY = "coffee-logbook-data";
@@ -37,375 +52,6 @@ async function saveData(data) {
const uid = () => Date.now().toString(36) + Math.random().toString(36).slice(2, 7);
-const ROAST_TYPES = ["Light", "Light-Medium", "Medium", "Medium-Dark", "Dark"];
-const METHODS = ["pourover", "espresso", "coldbrew"];
-const METHOD_LABELS = { pourover: "Pour Over", espresso: "Espresso", coldbrew: "Cold Brew" };
-const METHOD_ICONS = { pourover: "☕", espresso: "⚡", coldbrew: "❄️" };
-const METHOD_COLORS = { pourover: "#8B6914", espresso: "#5C3317", coldbrew: "#2F4F6F" };
-
-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";
-
-// ─── Create Modal ───
-function CreateModal({ onClose, onAddBean, onAddBrew }) {
- return (
-
-
e.stopPropagation()}>
-
-
What would you like to add?
-
-
-
-
-
-
- );
-}
-
-// ─── 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 }));
- const canSave = form.name.trim().length > 0;
-
- const handleImage = (e) => {
- const file = e.target.files?.[0];
- if (!file) return;
- if (file.size > 2 * 1024 * 1024) { alert("Image must be under 2 MB"); return; }
- const reader = new FileReader();
- reader.onload = () => set("image", reader.result);
- reader.readAsDataURL(file);
- };
-
- return (
-
-
e.stopPropagation()}>
-
-
{initial ? "Edit Bean" : "Add Bean"}
-
- set("name", e.target.value)} />
-
- set("roastery", e.target.value)} />
-
-
- set("roastDate", e.target.value)} />
-
-
-
-
-
-
- {form.image ? (
- <>

-
>
- ) : (<>
📷
Tap to upload a photo
>)}
-
-
-
Max 2 MB · JPG, PNG, or WebP
-
-
-
-
-
- );
-}
-
-// ─── Brew Form ───
-function BrewForm({ beans, onSave, onClose }) {
- const [method, setMethod] = useState("pourover");
- const [form, setForm] = useState({ beanId: beans[0]?.id || "" });
- const set = (k, v) => setForm(p => ({ ...p, [k]: v }));
-
- if (beans.length === 0) {
- return (
-
-
e.stopPropagation()}>
-
-
Log a Brew
-
-
🫘
-
No beans yet
-
Add a bean to your library first.
-
-
-
-
- );
- }
-
- const fields = {
- pourover: [
- { key: "grindSize", label: "Grind Size", placeholder: "e.g. 18 clicks", hint: "Relative to your grinder" },
- { key: "waterTemp", label: "Water Temp", placeholder: "e.g. 93°C" },
- { key: "beanWeight", label: "Bean Weight", placeholder: "e.g. 15g" },
- { key: "brewRatio", label: "Brew Ratio", placeholder: "e.g. 1:16" },
- { key: "brewTime", label: "Brew Time", placeholder: "e.g. 3:30" },
- { key: "numPours", label: "# of Pours", placeholder: "e.g. 4", type: "number" },
- ],
- espresso: [
- { key: "grindSize", label: "Grind Size", placeholder: "e.g. 8" },
- { key: "dose", label: "Dose", placeholder: "e.g. 18g" },
- { key: "yield", label: "Yield", placeholder: "e.g. 36g" },
- { key: "brewTime", label: "Brew Time", placeholder: "e.g. 28s" },
- ],
- coldbrew: [
- { key: "grindSize", label: "Grind Size", placeholder: "e.g. coarse" },
- { key: "beanWeight", label: "Bean Weight", placeholder: "e.g. 100g" },
- { key: "waterVolume", label: "Water Volume", placeholder: "e.g. 700ml" },
- { key: "steepTime", label: "Steep Time", placeholder: "e.g. 18 hours" },
- ],
- };
-
- return (
-
-
e.stopPropagation()}>
-
-
Log a Brew
-
- {METHODS.map(m => (
-
- ))}
-
-
-
-
- {fields[method].map(f => (
-
-
-
set(f.key, e.target.value)} />
- {f.hint &&
{f.hint}
}
-
- ))}
-
-
-
-
- set("tasteNotes", e.target.value)} />
-
-
-
- );
-}
-
-// ─── 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]"
- : "bg-[#FFF3D6] text-[#8B6914]";
- return (
-
-
- {bean.image &&

}
-
{bean.name}
- {bean.roastery &&
{bean.roastery}
}
- {bean.tastingNotes &&
👅 {bean.tastingNotes}
}
-
- {bean.roastType && {bean.roastType}}
- {bean.roastDate && Roasted {bean.roastDate}}
- {beanLogs.length} brew{beanLogs.length !== 1 ? "s" : ""}
-
-
-
-
-
-
-
Brew History
- {beanLogs.length === 0 ? (
-
No brews logged with this bean yet.
- ) : beanLogs.map(log =>
)}
-
-
- );
-}
-
-// ─── 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" };
- return (
-
-
-
-
-
-
{new Date(log.createdAt).toLocaleDateString("en-IN", { day: "numeric", month: "short", year: "numeric" })}
- {beanName &&
{beanName}
}
-
-
{METHOD_ICONS[log.method]} {METHOD_LABELS[log.method]}
-
- {allFields.length > 0 && (
-
- {allFields.map(([k, v]) => (
-
-
{fieldLabels[k] || k}
-
{v}
-
- ))}
-
- )}
- {log.recipeDetails &&
📝 {log.recipeDetails}
}
- {log.tasteNotes &&
👅 {log.tasteNotes}
}
-
-
- );
-}
-
-// ─── Profile Page ───
-function ProfilePage({ user, isOnline, syncing, showSyncedStatus }) {
- const { logout } = useContext(AuthContext);
- return (
-
- {/* Avatar & Name */}
-
-
- {user?.username?.[0]?.toUpperCase() || "☕"}
-
-
{user?.username}
-
{user?.email}
- {showSyncedStatus && (
-
- ●
- {isOnline ? (syncing ? "Syncing…" : "All data synced") : "Offline — saved locally"}
-
- )}
-
-
- {/* Account section */}
-
-
Account
-
-
-
👤
-
-
Username
-
{user?.username}
-
-
-
-
✉️
-
-
Email
-
{user?.email}
-
-
-
-
-
- {/* App info */}
-
-
App
-
-
-
-
🗄️
-
-
Storage
-
Local + PostgreSQL
-
-
-
-
-
- {/* Sign out */}
-
-
- );
-}
-
-// ─── 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 (
-
-
- {items.map(item => {
- const isActive = view === item.id;
- if (item.isAction) {
- return (
-
- );
- }
- return (
-
- );
- })}
-
-
- );
-}
-
// ─── Main App ───
export default function CoffeeLogbook() {
const { token, user, loading, logout } = useContext(AuthContext);
diff --git a/src/components/BeanDetail.jsx b/src/components/BeanDetail.jsx
new file mode 100644
index 0000000..9a7134b
--- /dev/null
+++ b/src/components/BeanDetail.jsx
@@ -0,0 +1,33 @@
+import React from "react";
+import BrewCard from "./BrewCard";
+
+export default 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]"
+ : "bg-[#FFF3D6] text-[#8B6914]";
+ return (
+
+
+ {bean.image &&

}
+
{bean.name}
+ {bean.roastery &&
{bean.roastery}
}
+ {bean.tastingNotes &&
👅 {bean.tastingNotes}
}
+
+ {bean.roastType && {bean.roastType}}
+ {bean.roastDate && Roasted {bean.roastDate}}
+ {beanLogs.length} brew{beanLogs.length !== 1 ? "s" : ""}
+
+
+
+
+
+
+
Brew History
+ {beanLogs.length === 0 ? (
+
No brews logged with this bean yet.
+ ) : beanLogs.map(log =>
)}
+
+
+ );
+}
diff --git a/src/components/BeanForm.jsx b/src/components/BeanForm.jsx
new file mode 100644
index 0000000..220f07d
--- /dev/null
+++ b/src/components/BeanForm.jsx
@@ -0,0 +1,59 @@
+import React, { useState } from "react";
+import { ROAST_TYPES, inputCls, labelCls } from "../constants";
+
+export default 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 }));
+ const canSave = form.name.trim().length > 0;
+
+ const handleImage = (e) => {
+ const file = e.target.files?.[0];
+ if (!file) return;
+ if (file.size > 2 * 1024 * 1024) { alert("Image must be under 2 MB"); return; }
+ const reader = new FileReader();
+ reader.onload = () => set("image", reader.result);
+ reader.readAsDataURL(file);
+ };
+
+ return (
+
+
e.stopPropagation()}>
+
+
{initial ? "Edit Bean" : "Add Bean"}
+
+ set("name", e.target.value)} />
+
+ set("roastery", e.target.value)} />
+
+
+ set("roastDate", e.target.value)} />
+
+
+
+
+
+
+ {form.image ? (
+ <>

+
>
+ ) : (<>
📷
Tap to upload a photo
>)}
+
+
+
Max 2 MB · JPG, PNG, or WebP
+
+
+
+
+
+ );
+}
diff --git a/src/components/BottomNav.jsx b/src/components/BottomNav.jsx
new file mode 100644
index 0000000..2d0f273
--- /dev/null
+++ b/src/components/BottomNav.jsx
@@ -0,0 +1,42 @@
+import React from "react";
+
+export default 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 (
+
+
+ {items.map(item => {
+ const isActive = view === item.id;
+ if (item.isAction) {
+ return (
+
+ );
+ }
+ return (
+
+ );
+ })}
+
+
+ );
+}
diff --git a/src/components/BrewCard.jsx b/src/components/BrewCard.jsx
new file mode 100644
index 0000000..2869ad2
--- /dev/null
+++ b/src/components/BrewCard.jsx
@@ -0,0 +1,36 @@
+import React from "react";
+import { METHOD_COLORS, METHOD_ICONS, METHOD_LABELS } from "../constants";
+
+export default 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" };
+ return (
+
+
+
+
+
+
{new Date(log.createdAt).toLocaleDateString("en-IN", { day: "numeric", month: "short", year: "numeric" })}
+ {beanName &&
{beanName}
}
+
+
{METHOD_ICONS[log.method]} {METHOD_LABELS[log.method]}
+
+ {allFields.length > 0 && (
+
+ {allFields.map(([k, v]) => (
+
+
{fieldLabels[k] || k}
+
{v}
+
+ ))}
+
+ )}
+ {log.recipeDetails &&
📝 {log.recipeDetails}
}
+ {log.tasteNotes &&
👅 {log.tasteNotes}
}
+
+
+ );
+}
diff --git a/src/components/BrewForm.jsx b/src/components/BrewForm.jsx
new file mode 100644
index 0000000..3606879
--- /dev/null
+++ b/src/components/BrewForm.jsx
@@ -0,0 +1,90 @@
+import React, { useState } from "react";
+import { METHODS, METHOD_LABELS, METHOD_ICONS, METHOD_COLORS, inputCls, labelCls } from "../constants";
+
+export default function BrewForm({ beans, onSave, onClose }) {
+ const [method, setMethod] = useState("pourover");
+ const [form, setForm] = useState({ beanId: beans[0]?.id || "" });
+ const set = (k, v) => setForm(p => ({ ...p, [k]: v }));
+
+ if (beans.length === 0) {
+ return (
+
+
e.stopPropagation()}>
+
+
Log a Brew
+
+
🫘
+
No beans yet
+
Add a bean to your library first.
+
+
+
+
+ );
+ }
+
+ const fields = {
+ pourover: [
+ { key: "grindSize", label: "Grind Size", placeholder: "e.g. 18 clicks", hint: "Relative to your grinder" },
+ { key: "waterTemp", label: "Water Temp", placeholder: "e.g. 93°C" },
+ { key: "beanWeight", label: "Bean Weight", placeholder: "e.g. 15g" },
+ { key: "brewRatio", label: "Brew Ratio", placeholder: "e.g. 1:16" },
+ { key: "brewTime", label: "Brew Time", placeholder: "e.g. 3:30" },
+ { key: "numPours", label: "# of Pours", placeholder: "e.g. 4", type: "number" },
+ ],
+ espresso: [
+ { key: "grindSize", label: "Grind Size", placeholder: "e.g. 8" },
+ { key: "dose", label: "Dose", placeholder: "e.g. 18g" },
+ { key: "yield", label: "Yield", placeholder: "e.g. 36g" },
+ { key: "brewTime", label: "Brew Time", placeholder: "e.g. 28s" },
+ ],
+ coldbrew: [
+ { key: "grindSize", label: "Grind Size", placeholder: "e.g. coarse" },
+ { key: "beanWeight", label: "Bean Weight", placeholder: "e.g. 100g" },
+ { key: "waterVolume", label: "Water Volume", placeholder: "e.g. 700ml" },
+ { key: "steepTime", label: "Steep Time", placeholder: "e.g. 18 hours" },
+ ],
+ };
+
+ return (
+
+
e.stopPropagation()}>
+
+
Log a Brew
+
+ {METHODS.map(m => (
+
+ ))}
+
+
+
+
+ {fields[method].map(f => (
+
+
+
set(f.key, e.target.value)} />
+ {f.hint &&
{f.hint}
}
+
+ ))}
+
+
+
+
+ set("tasteNotes", e.target.value)} />
+
+
+
+ );
+}
diff --git a/src/components/CreateModal.jsx b/src/components/CreateModal.jsx
new file mode 100644
index 0000000..337b610
--- /dev/null
+++ b/src/components/CreateModal.jsx
@@ -0,0 +1,32 @@
+import React from "react";
+
+export default function CreateModal({ onClose, onAddBean, onAddBrew }) {
+ return (
+
+
e.stopPropagation()}>
+
+
What would you like to add?
+
+
+
+
+
+
+ );
+}
diff --git a/src/constants.js b/src/constants.js
new file mode 100644
index 0000000..2af906c
--- /dev/null
+++ b/src/constants.js
@@ -0,0 +1,8 @@
+export const ROAST_TYPES = ["Light", "Light-Medium", "Medium", "Medium-Dark", "Dark"];
+export const METHODS = ["pourover", "espresso", "coldbrew"];
+export const METHOD_LABELS = { pourover: "Pour Over", espresso: "Espresso", coldbrew: "Cold Brew" };
+export const METHOD_ICONS = { pourover: "☕", espresso: "⚡", coldbrew: "❄️" };
+export const METHOD_COLORS = { pourover: "#8B6914", espresso: "#5C3317", coldbrew: "#2F4F6F" };
+
+export 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]";
+export const labelCls = "block text-[10px] font-semibold uppercase tracking-wider text-[#6B5744] mb-1.5";
diff --git a/src/Login.jsx b/src/pages/Login.jsx
similarity index 88%
rename from src/Login.jsx
rename to src/pages/Login.jsx
index d718a03..fed1e2c 100644
--- a/src/Login.jsx
+++ b/src/pages/Login.jsx
@@ -1,8 +1,6 @@
import { useState, useContext } from 'react';
-import { AuthContext } from './AuthContext';
-
-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 labelCls = "block text-[10px] font-semibold uppercase tracking-wider text-[#6B5744] mb-1.5";
+import { AuthContext } from '../AuthContext';
+import { inputCls, labelCls } from '../constants';
export default function Login({ onLoginSuccess }) {
const [formData, setFormData] = useState({ email: '', password: '' });
diff --git a/src/pages/ProfilePage.jsx b/src/pages/ProfilePage.jsx
new file mode 100644
index 0000000..b10f983
--- /dev/null
+++ b/src/pages/ProfilePage.jsx
@@ -0,0 +1,73 @@
+import React, { useContext } from "react";
+import { AuthContext } from "../AuthContext";
+
+export default function ProfilePage({ user, isOnline, syncing, showSyncedStatus }) {
+ const { logout } = useContext(AuthContext);
+ return (
+
+ {/* Avatar & Name */}
+
+
+ {user?.username?.[0]?.toUpperCase() || "☕"}
+
+
{user?.username}
+
{user?.email}
+ {showSyncedStatus && (
+
+ ●
+ {isOnline ? (syncing ? "Syncing…" : "All data synced") : "Offline — saved locally"}
+
+ )}
+
+
+ {/* Account section */}
+
+
Account
+
+
+
👤
+
+
Username
+
{user?.username}
+
+
+
+
✉️
+
+
Email
+
{user?.email}
+
+
+
+
+
+ {/* App info */}
+
+
App
+
+
+
+
🗄️
+
+
Storage
+
Local + PostgreSQL
+
+
+
+
+
+ {/* Sign out */}
+
+
+ );
+}
diff --git a/src/Register.jsx b/src/pages/Register.jsx
similarity index 92%
rename from src/Register.jsx
rename to src/pages/Register.jsx
index f8a6cf1..5ffda2a 100644
--- a/src/Register.jsx
+++ b/src/pages/Register.jsx
@@ -1,8 +1,6 @@
import { useState, useContext } from 'react';
-import { AuthContext } from './AuthContext';
-
-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 labelCls = "block text-[10px] font-semibold uppercase tracking-wider text-[#6B5744] mb-1.5";
+import { AuthContext } from '../AuthContext';
+import { inputCls, labelCls } from '../constants';
export default function Register({ onRegisterSuccess }) {
const [formData, setFormData] = useState({ username: '', email: '', password: '', confirmPassword: '' });