Water Tracker
WIDGET
maws7140

Water Tracker

Tap glasses to log water through the day. Saves per day, so it resets each morning.

What you need

  • The Datacore community plugin (Settings → Community plugins → Browse, search "Datacore").
  • The VaultHub widgets CSS snippet: download vaulthub-widgets.css, save it in your vault's .obsidian/snippets/ folder, then switch it on under Settings → Appearance → CSS snippets. One snippet styles every VaultHub widget.

Add it to a note

Paste the block below into any note. It renders in Live Preview and Reading view.

Change GOAL and GLASS_LITRES at the top to match your target. The count is stored in Obsidian's local storage under one key per day, so it survives reloads on the same device.

return function WaterTracker() {
    const GOAL = 8;
    const GLASS_LITRES = 0.25;

    const d = new Date();
    const key = `vaulthub-water-${d.getFullYear()}-${d.getMonth() + 1}-${d.getDate()}`;
    const [glasses, setGlasses] = dc.useState(() => Number(localStorage.getItem(key)) || 0);

    dc.useEffect(() => {
        localStorage.setItem(key, String(glasses));
    }, [key, glasses]);

    const toggle = (idx) => setGlasses(prev => (idx < prev ? idx : idx + 1));

    return (
        <div className="vh-widget vh-water">
            <div className="vh-water-title">HYDRATION TRACKER</div>
            <div className="vh-water-glasses">
                {Array.from({ length: GOAL }, (_, i) => (
                    <div
                        key={i}
                        className={`vh-glass ${i < glasses ? 'done' : ''}`}
                        onClick={() => toggle(i)}
                    />
                ))}
            </div>
            <div className="vh-water-count">
                {glasses} / {GOAL} GLASSES ({(glasses * GLASS_LITRES).toFixed(2)}L)
            </div>
        </div>
    );
}

Related

How to Install

  1. Install the Datacore community plugin
  2. Add the VaultHub widgets CSS snippet to .obsidian/snippets/ and enable it
  3. Copy the code block on this page into any note

Required Plugins

Datacore

Tags

vaulthubwaterhealthhabit