Who's Coming
`;
return;
}
el.innerHTML = gear.map((g, i) => `
${g.name}
${gearAdminMode ? `
` : ''}
${g.item}
${g.extra ? `
✓ Extra Available` : ''}
${g.note ? `
${g.note}
` : ''}
`).join('');
}
function openAddGearModal() {
document.getElementById('gear-name').value = '';
document.getElementById('gear-item').value = '';
document.getElementById('gear-extra').checked = false;
document.getElementById('gear-note').value = '';
document.getElementById('gear-modal').style.display = 'flex';
}
function closeGearModal() {
document.getElementById('gear-modal').style.display = 'none';
}
function submitGear() {
const name = document.getElementById('gear-name').value.trim();
const item = document.getElementById('gear-item').value.trim();
if (!name || !item) { showToast('Please enter your name and what you\'re bringing.'); return; }
const gear = loadGear();
gear.push({
name,
item,
extra: document.getElementById('gear-extra').checked,
note: document.getElementById('gear-note').value.trim()
});
saveGear(gear);
closeGearModal();
renderGearList();
showToast('Gear added to the list!');
}
function deleteGear(i) {
const gear = loadGear();
gear.splice(i, 1);
saveGear(gear);
renderGearList();
}
function openGearAdminModal() {
if (gearAdminMode) {
gearAdminMode = false;
document.getElementById('gear-lock-btn').textContent = '🔒 Admin';
renderGearList();
return;
}
document.getElementById('gear-pw-input').value = '';
document.getElementById('gear-pw-error').style.display = 'none';
document.getElementById('gear-pw-modal').style.display = 'flex';
setTimeout(() => document.getElementById('gear-pw-input').focus(), 100);
}
function closeGearAdminModal() {
document.getElementById('gear-pw-modal').style.display = 'none';
}
function checkGearPassword() {
if (document.getElementById('gear-pw-input').value === 'RiverFam25') {
closeGearAdminModal();
gearAdminMode = true;
document.getElementById('gear-lock-btn').textContent = '🔓 Admin';
renderGearList();
} else {
document.getElementById('gear-pw-error').style.display = 'block';
document.getElementById('gear-pw-input').value = '';
}
}
document.getElementById('gear-modal').addEventListener('click', function(e) { if (e.target === this) closeGearModal(); });
document.getElementById('gear-pw-modal').addEventListener('click', function(e) { if (e.target === this) closeGearAdminModal(); });
// ── Countdown Timer ───────────────────────────
let countdownInterval = null;
function getNextTrip() {
const now = new Date(); now.setHours(0,0,0,0);
const trips = DB.data.trips || [];
return trips
.filter(t => new Date(t.date + 'T12:00:00') >= now)
.sort((a, b) => new Date(a.date) - new Date(b.date))[0];
}
function initCountdown() {
const next = getNextTrip();
const wrap = document.getElementById('countdown-wrap');
if (!next) { wrap.style.display = 'none'; if (countdownInterval) clearInterval(countdownInterval); return; }
wrap.style.display = 'block';
document.getElementById('countdown-tripname').textContent = next.name || '';
const targetTime = next.time || '09:00';
const target = new Date(next.date + 'T' + targetTime + ':00');
function tick() {
const now = new Date();
let diff = target - now;
if (diff < 0) diff = 0;
const days = Math.floor(diff / 86400000);
const hours = Math.floor((diff % 86400000) / 3600000);
const mins = Math.floor((diff % 3600000) / 60000);
const secs = Math.floor((diff % 60000) / 1000);
document.getElementById('cd-days').textContent = days;
document.getElementById('cd-hours').textContent = hours;
document.getElementById('cd-mins').textContent = mins;
document.getElementById('cd-secs').textContent = secs;
document.getElementById('countdown-label').textContent = diff <= 0 ? "It's Today!" : 'Next Trip In';
}
tick();
if (countdownInterval) clearInterval(countdownInterval);
countdownInterval = setInterval(tick, 1000);
}
// ── River Conditions + Weather Forecast ───────
// USGS gauge: American River at Fair Oaks, CA (closest reliable gauge to Rancho Cordova/Sunrise launch)
const USGS_SITE = '11446500';
const RIVER_LAT = 38.5816;
const RIVER_LON = -121.2880;
const WEATHER_ICONS = {
0:'☀️',1:'🌤️',2:'⛅',3:'☁️',45:'🌫️',48:'🌫️',
51:'🌦️',53:'🌦️',55:'🌧️',61:'🌧️',63:'🌧️',65:'🌧️',
71:'🌨️',73:'🌨️',75:'❄️',80:'🌦️',81:'🌧️',82:'⛈️',
95:'⛈️',96:'⛈️',99:'⛈️'
};
async function renderRiverWeather() {
const row = document.getElementById('river-weather-row');
if (!row) { console.warn('river-weather-row element not found in DOM'); return; }
let next;
try { next = getNextTrip(); } catch(e) { console.error('getNextTrip failed:', e); next = null; }
row.innerHTML = `
🌊
River Conditions
Loading current flow...
⛅
Weather Forecast
${next ? 'Loading forecast...' : 'No trip scheduled yet.'}
`;
// River conditions (USGS) — always attempt regardless of trip/weather status
try {
const r = await fetch(`https://waterservices.usgs.gov/nwis/iv/?format=json&sites=${USGS_SITE}¶meterCd=00060,00010&siteStatus=all`);
const data = await r.json();
const series = data.value.timeSeries;
const flowSeries = series.find(s => s.variable.variableCode[0].value === '00060');
const tempSeries = series.find(s => s.variable.variableCode[0].value === '00010');
const flow = flowSeries ? Math.round(flowSeries.values[0].value[0].value) : null;
const tempC = tempSeries ? parseFloat(tempSeries.values[0].value[0].value) : null;
const tempF = tempC !== null ? Math.round(tempC * 9/5 + 32) : null;
let flowLevel = '';
let flowColor = 'var(--river)';
if (flow !== null) {
if (flow < 1500) { flowLevel = 'Low — mellow float'; flowColor = '#2d7a4f'; }
else if (flow < 3500) { flowLevel = 'Moderate — good conditions'; flowColor = '#0096c7'; }
else { flowLevel = 'High — use caution'; flowColor = '#c0392b'; }
}
const riverCardEl = document.getElementById('river-card');
if (riverCardEl) riverCardEl.innerHTML = `
🌊
River Conditions
${flow !== null ? flow.toLocaleString() : '—'}
CFS · American River at Fair Oaks
${flowLevel ? `
${flowLevel}
` : ''}
${tempF !== null ? `
💧 Water Temp: ${tempF}°F
` : ''}
Live from USGS gauge #${USGS_SITE}
`;
} catch(e) {
console.error('River conditions fetch failed:', e);
const riverCardEl = document.getElementById('river-card');
if (riverCardEl) riverCardEl.innerHTML = `
🌊
River Conditions
Couldn't load live data right now. Check USGS directly ↗
`;
}
// Weather forecast (Open-Meteo) — only if a trip date exists AND it's within the ~16-day forecast window
if (!next) return;
const weatherCardEl = document.getElementById('weather-card');
const tripDate = new Date(next.date + 'T00:00:00');
const today = new Date(); today.setHours(0,0,0,0);
const daysAway = Math.round((tripDate - today) / 86400000);
if (daysAway < 0 || daysAway > 15) {
if (weatherCardEl) weatherCardEl.innerHTML = `
⛅
Weather Forecast
Forecast opens up about 2 weeks before the trip. Check back closer to the date!
`;
return;
}
try {
const url = `https://api.open-meteo.com/v1/forecast?latitude=${RIVER_LAT}&longitude=${RIVER_LON}&daily=temperature_2m_max,temperature_2m_min,precipitation_probability_max,weathercode&temperature_unit=fahrenheit&timezone=America%2FLos_Angeles&start_date=${next.date}&end_date=${next.date}`;
const r = await fetch(url);
const data = await r.json();
if (!data.daily || !data.daily.time || !data.daily.time.length) {
if (weatherCardEl) weatherCardEl.innerHTML = `
⛅
Weather Forecast
Forecast opens up about 2 weeks before the trip. Check back closer to the date!
`;
return;
}
const hi = Math.round(data.daily.temperature_2m_max[0]);
const lo = Math.round(data.daily.temperature_2m_min[0]);
const rain = data.daily.precipitation_probability_max[0];
const code = data.daily.weathercode[0];
const icon = WEATHER_ICONS[code] || '🌤️';
if (weatherCardEl) weatherCardEl.innerHTML = `
${icon}
Weather Forecast
${hi}° / ${lo}°
High / Low · Trip Day
${rain > 20 ? `
☔ ${rain}% chance of rain
` : `
☀️ ${rain}% chance of rain
`}
Forecast updates daily
`;
} catch(e) {
document.getElementById('weather-card').innerHTML = `
⛅
Weather Forecast
Couldn't load forecast right now.
`;
}
}
// ── Boot: cache-first, then background refresh ──
(async () => {
const hasCached = DB.loadCache();
renderTripDetails();
renderRsvpList();
updateRsvpTripLabel();
renderDeals();
renderBringBoard();
renderGearList();
initCountdown();
renderRiverWeather();
const changed = await DB.fetchRemote();
if (changed || !hasCached) {
renderTripDetails();
renderRsvpList();
updateRsvpTripLabel();
renderDeals();
renderBringBoard();
renderGearList();
initCountdown();
renderRiverWeather();
}
})();