Redesign UI as light-themed week-grid calendar matching Skylight-style device
- Replace scrolling event list + photo background with a Sun–Sat week grid plus a "Next Week" preview column; Prev/Next navigation and per-member filter - Add [Name] event title prefix convention for color-coded family member cards (Ludwig/Dad=blue, Michelle/Mom=pink, Jason=green, Daniel=yellow) - /api/calendar now accepts ?start=YYYY-MM-DD, returns bucketed week payload with member/color metadata; fetches 14 days to populate Next Week column - Drop rotating background photo and dad joke from the display (endpoints kept) - Update README with new UI overview, prefix convention, and API docs Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -1,441 +1,326 @@
|
||||
/* Reset and base styles */
|
||||
* {
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
box-sizing: border-box;
|
||||
}
|
||||
|
||||
body {
|
||||
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
|
||||
html, body {
|
||||
height: 100%;
|
||||
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
|
||||
background: #F4F5F7;
|
||||
color: #2B2B33;
|
||||
overflow: hidden;
|
||||
width: 100vw;
|
||||
height: 100vh;
|
||||
color: #ffffff;
|
||||
transition: color 0.5s ease-in-out;
|
||||
}
|
||||
|
||||
/* Dark text for bright backgrounds */
|
||||
body.light-bg {
|
||||
color: #1a1a1a;
|
||||
}
|
||||
|
||||
body.light-bg .time,
|
||||
body.light-bg .date,
|
||||
body.light-bg .current-temp,
|
||||
body.light-bg .weather-label,
|
||||
body.light-bg .weather-icon,
|
||||
body.light-bg .forecast-icon,
|
||||
body.light-bg section h2,
|
||||
body.light-bg .day-name,
|
||||
body.light-bg .day-date,
|
||||
body.light-bg .event-title,
|
||||
body.light-bg .event-location,
|
||||
body.light-bg .joke {
|
||||
text-shadow: 1px 1px 3px rgba(255, 255, 255, 0.8);
|
||||
}
|
||||
|
||||
body.light-bg .event-time {
|
||||
color: #0066cc;
|
||||
}
|
||||
|
||||
body.light-bg .event {
|
||||
border-left-color: #0066cc;
|
||||
}
|
||||
|
||||
/* White text for dark backgrounds (default) */
|
||||
body.dark-bg {
|
||||
color: #ffffff;
|
||||
}
|
||||
|
||||
body.dark-bg .event-time {
|
||||
color: #4a9eff;
|
||||
}
|
||||
|
||||
body.dark-bg .event {
|
||||
border-left-color: #4a9eff;
|
||||
}
|
||||
|
||||
/* Background */
|
||||
#background {
|
||||
position: fixed;
|
||||
top: 0;
|
||||
left: 0;
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
background-size: cover;
|
||||
background-position: center;
|
||||
background-repeat: no-repeat;
|
||||
z-index: 0;
|
||||
transition: background-image 1s ease-in-out;
|
||||
}
|
||||
|
||||
#background::before {
|
||||
content: '';
|
||||
position: absolute;
|
||||
top: 0;
|
||||
left: 0;
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
background: rgba(0, 0, 0, 0.1);
|
||||
z-index: 1;
|
||||
}
|
||||
|
||||
/* Main container */
|
||||
.container {
|
||||
position: relative;
|
||||
z-index: 2;
|
||||
width: 100%;
|
||||
.app {
|
||||
height: 100vh;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
padding: 1rem;
|
||||
padding: 18px 24px 24px;
|
||||
}
|
||||
|
||||
/* Header – maximally transparent; text readable via text-shadow */
|
||||
.header {
|
||||
/* ---------- Top bar ---------- */
|
||||
|
||||
.topbar {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: flex-start;
|
||||
margin-bottom: 1rem;
|
||||
background: rgba(0, 0, 0, 0.03);
|
||||
padding: 1rem 1.5rem;
|
||||
border-radius: 10px;
|
||||
justify-content: space-between;
|
||||
margin-bottom: 18px;
|
||||
flex-wrap: wrap;
|
||||
gap: 12px;
|
||||
}
|
||||
|
||||
.time-display {
|
||||
.date-time {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: baseline;
|
||||
gap: 10px;
|
||||
}
|
||||
|
||||
.time {
|
||||
font-size: 4.5rem;
|
||||
font-weight: 600;
|
||||
line-height: 1;
|
||||
text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.5);
|
||||
.icon-badge {
|
||||
font-size: 22px;
|
||||
margin-right: 2px;
|
||||
}
|
||||
|
||||
.date {
|
||||
font-size: 1.6rem;
|
||||
.header-date {
|
||||
font-size: 28px;
|
||||
font-weight: 700;
|
||||
color: #1F2430;
|
||||
}
|
||||
|
||||
.header-time {
|
||||
font-size: 18px;
|
||||
font-weight: 500;
|
||||
margin-top: 0.3rem;
|
||||
opacity: 0.9;
|
||||
text-shadow: 1px 1px 2px rgba(0, 0, 0, 0.5);
|
||||
color: #8A8F9C;
|
||||
}
|
||||
|
||||
.weather-summary {
|
||||
.nav-row {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 1.5rem;
|
||||
gap: 10px;
|
||||
margin-top: 10px;
|
||||
}
|
||||
|
||||
.current-weather-item {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
.pill {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
gap: 0.2rem;
|
||||
background: #FFFFFF;
|
||||
border: 1px solid #E3E5EA;
|
||||
border-radius: 18px;
|
||||
padding: 6px 14px;
|
||||
font-size: 13px;
|
||||
font-weight: 600;
|
||||
color: #4A4E5A;
|
||||
}
|
||||
|
||||
.weather-label {
|
||||
font-size: 1.2rem;
|
||||
font-weight: 600;
|
||||
opacity: 0.8;
|
||||
text-transform: uppercase;
|
||||
letter-spacing: 0.05em;
|
||||
.filter-select {
|
||||
appearance: none;
|
||||
-webkit-appearance: none;
|
||||
cursor: pointer;
|
||||
padding-right: 28px;
|
||||
background-image: linear-gradient(45deg, transparent 50%, #8A8F9C 50%), linear-gradient(135deg, #8A8F9C 50%, transparent 50%);
|
||||
background-position: calc(100% - 14px) center, calc(100% - 9px) center;
|
||||
background-size: 5px 5px, 5px 5px;
|
||||
background-repeat: no-repeat;
|
||||
}
|
||||
|
||||
.current-temp {
|
||||
font-size: 3rem;
|
||||
.week-nav {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 6px;
|
||||
background: #FFFFFF;
|
||||
border: 1px solid #E3E5EA;
|
||||
border-radius: 18px;
|
||||
padding: 4px 8px;
|
||||
}
|
||||
|
||||
.nav-arrow {
|
||||
border: none;
|
||||
background: transparent;
|
||||
font-size: 18px;
|
||||
line-height: 1;
|
||||
color: #4A4E5A;
|
||||
cursor: pointer;
|
||||
padding: 4px 8px;
|
||||
border-radius: 50%;
|
||||
}
|
||||
|
||||
.nav-arrow:hover {
|
||||
background: #F0F1F4;
|
||||
}
|
||||
|
||||
.week-range {
|
||||
font-size: 13px;
|
||||
font-weight: 600;
|
||||
text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.5);
|
||||
color: #4A4E5A;
|
||||
min-width: 80px;
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
.topbar-right {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 14px;
|
||||
}
|
||||
|
||||
.weather-chip {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 6px;
|
||||
background: #FFFFFF;
|
||||
border: 1px solid #E3E5EA;
|
||||
border-radius: 18px;
|
||||
padding: 6px 14px;
|
||||
}
|
||||
|
||||
.weather-icon {
|
||||
font-size: 2.5rem;
|
||||
width: 22px;
|
||||
height: 22px;
|
||||
background-size: contain;
|
||||
background-repeat: no-repeat;
|
||||
}
|
||||
|
||||
.header-forecast {
|
||||
display: flex;
|
||||
gap: 1rem;
|
||||
}
|
||||
|
||||
.forecast-item {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
gap: 0.2rem;
|
||||
}
|
||||
|
||||
.forecast-icon {
|
||||
font-size: 2.2rem;
|
||||
}
|
||||
|
||||
.forecast-temps {
|
||||
display: flex;
|
||||
gap: 0.3rem;
|
||||
font-size: 1.3rem;
|
||||
}
|
||||
|
||||
.forecast-temps .high {
|
||||
.current-temp {
|
||||
font-size: 14px;
|
||||
font-weight: 700;
|
||||
color: #4A4E5A;
|
||||
}
|
||||
|
||||
.forecast-temps .low {
|
||||
opacity: 0.6;
|
||||
.wifi-icon {
|
||||
font-size: 18px;
|
||||
color: #8A8F9C;
|
||||
}
|
||||
|
||||
/* Main content */
|
||||
.main-content {
|
||||
/* ---------- Week grid ---------- */
|
||||
|
||||
.week-grid {
|
||||
flex: 1;
|
||||
display: flex;
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
/* Sections */
|
||||
section {
|
||||
background: rgba(0, 0, 0, 0.03);
|
||||
padding: 1rem 1.5rem;
|
||||
border-radius: 10px;
|
||||
overflow-y: auto;
|
||||
flex: 1;
|
||||
}
|
||||
|
||||
section h2 {
|
||||
font-size: 2rem;
|
||||
font-weight: 700;
|
||||
margin-bottom: 0.8rem;
|
||||
text-shadow: 1px 1px 2px rgba(0, 0, 0, 0.5);
|
||||
}
|
||||
|
||||
section h3 {
|
||||
font-size: 1.1rem;
|
||||
font-weight: 400;
|
||||
margin: 1rem 0 0.5rem;
|
||||
text-shadow: 1px 1px 2px rgba(0, 0, 0, 0.5);
|
||||
}
|
||||
|
||||
/* Weather Section */
|
||||
.weather-description {
|
||||
font-size: 1.1rem;
|
||||
margin-bottom: 0.6rem;
|
||||
text-transform: capitalize;
|
||||
}
|
||||
|
||||
.weather-details {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 0.4rem;
|
||||
margin: 0.8rem 0;
|
||||
}
|
||||
|
||||
.weather-detail {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
font-size: 0.95rem;
|
||||
padding: 0.3rem 0;
|
||||
border-bottom: 1px solid rgba(255, 255, 255, 0.1);
|
||||
}
|
||||
|
||||
.weather-detail .label {
|
||||
opacity: 0.8;
|
||||
}
|
||||
|
||||
/* Forecast */
|
||||
.forecast-days {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 0.5rem;
|
||||
}
|
||||
|
||||
.forecast-day {
|
||||
display: grid;
|
||||
grid-template-columns: 60px 1fr 100px;
|
||||
align-items: center;
|
||||
padding: 0.6rem;
|
||||
background: rgba(255, 255, 255, 0.04);
|
||||
border-radius: 8px;
|
||||
gap: 0.8rem;
|
||||
}
|
||||
|
||||
.forecast-day-name {
|
||||
font-size: 1rem;
|
||||
font-weight: 500;
|
||||
}
|
||||
|
||||
.forecast-description {
|
||||
font-size: 0.9rem;
|
||||
opacity: 0.8;
|
||||
text-transform: capitalize;
|
||||
}
|
||||
|
||||
.forecast-temp {
|
||||
font-size: 1rem;
|
||||
text-align: right;
|
||||
}
|
||||
|
||||
.forecast-temp .high {
|
||||
font-weight: 500;
|
||||
}
|
||||
|
||||
.forecast-temp .low {
|
||||
opacity: 0.6;
|
||||
margin-left: 0.5rem;
|
||||
}
|
||||
|
||||
/* Calendar Section */
|
||||
.events-list {
|
||||
display: grid;
|
||||
grid-template-columns: repeat(5, 1fr);
|
||||
gap: 0.8rem;
|
||||
height: 100%;
|
||||
}
|
||||
|
||||
.day-group {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
grid-template-columns: repeat(7, 1fr) 1.1fr;
|
||||
gap: 12px;
|
||||
min-height: 0;
|
||||
}
|
||||
|
||||
.day-header {
|
||||
.day-column {
|
||||
background: #FFFFFF;
|
||||
border-radius: 14px;
|
||||
padding: 12px 10px;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
padding: 0.6rem;
|
||||
background: rgba(255, 255, 255, 0.06);
|
||||
border-radius: 8px 8px 0 0;
|
||||
margin-bottom: 0.5rem;
|
||||
text-align: center;
|
||||
min-height: 0;
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
.day-column.is-today {
|
||||
box-shadow: 0 0 0 2px #4A90D9 inset;
|
||||
}
|
||||
|
||||
.day-header {
|
||||
margin-bottom: 8px;
|
||||
}
|
||||
|
||||
.day-name {
|
||||
font-size: 1.5rem;
|
||||
font-size: 11px;
|
||||
font-weight: 700;
|
||||
text-shadow: 1px 1px 2px rgba(0, 0, 0, 0.5);
|
||||
text-transform: uppercase;
|
||||
color: #A6AAB4;
|
||||
letter-spacing: 0.04em;
|
||||
}
|
||||
|
||||
.day-date {
|
||||
font-size: 1.2rem;
|
||||
font-weight: 600;
|
||||
opacity: 0.8;
|
||||
margin-top: 0.2rem;
|
||||
.day-number {
|
||||
font-size: 20px;
|
||||
font-weight: 700;
|
||||
color: #1F2430;
|
||||
}
|
||||
|
||||
.day-count {
|
||||
font-size: 11px;
|
||||
color: #A6AAB4;
|
||||
margin-top: 2px;
|
||||
}
|
||||
|
||||
.day-events {
|
||||
flex: 1;
|
||||
overflow-y: auto;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 0.5rem;
|
||||
overflow-y: auto;
|
||||
flex: 1;
|
||||
gap: 6px;
|
||||
}
|
||||
|
||||
.no-events {
|
||||
font-size: 1.2rem;
|
||||
font-weight: 500;
|
||||
opacity: 0.5;
|
||||
font-style: italic;
|
||||
padding: 0.5rem;
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
.event {
|
||||
background: rgba(255, 255, 255, 0.04);
|
||||
padding: 0.5rem 0.6rem;
|
||||
border-radius: 6px;
|
||||
border-left: 3px solid #4a9eff;
|
||||
.event-card {
|
||||
border-radius: 8px;
|
||||
padding: 6px 8px;
|
||||
border-left: 4px solid transparent;
|
||||
font-size: 11.5px;
|
||||
line-height: 1.35;
|
||||
}
|
||||
|
||||
.event-time {
|
||||
font-size: 1.1rem;
|
||||
font-weight: 700;
|
||||
margin-bottom: 0.2rem;
|
||||
color: #4a9eff;
|
||||
color: rgba(0, 0, 0, 0.55);
|
||||
font-size: 10.5px;
|
||||
}
|
||||
|
||||
.event-title {
|
||||
font-size: 1.3rem;
|
||||
font-weight: 600;
|
||||
margin-bottom: 0.2rem;
|
||||
line-height: 1.2;
|
||||
color: #2B2B33;
|
||||
overflow-wrap: anywhere;
|
||||
}
|
||||
|
||||
.event-location {
|
||||
font-size: 1.1rem;
|
||||
font-weight: 500;
|
||||
opacity: 0.7;
|
||||
font-style: italic;
|
||||
.event-member {
|
||||
font-size: 10px;
|
||||
color: rgba(0, 0, 0, 0.5);
|
||||
margin-top: 1px;
|
||||
}
|
||||
|
||||
.next-week-column {
|
||||
background: #FFFFFF;
|
||||
border-radius: 14px;
|
||||
padding: 14px 12px;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
.next-week-column:hover {
|
||||
background: #F7F8FA;
|
||||
}
|
||||
|
||||
.next-week-title {
|
||||
font-size: 14px;
|
||||
font-weight: 700;
|
||||
color: #1F2430;
|
||||
}
|
||||
|
||||
.next-week-range {
|
||||
font-size: 11px;
|
||||
color: #A6AAB4;
|
||||
margin-bottom: 10px;
|
||||
}
|
||||
|
||||
.next-week-count {
|
||||
font-size: 13px;
|
||||
color: #4A4E5A;
|
||||
font-weight: 600;
|
||||
}
|
||||
|
||||
.event-placeholder {
|
||||
font-size: 1rem;
|
||||
opacity: 0.6;
|
||||
grid-column: 1 / -1;
|
||||
text-align: center;
|
||||
padding: 2rem;
|
||||
color: #A6AAB4;
|
||||
padding-top: 60px;
|
||||
font-size: 14px;
|
||||
}
|
||||
|
||||
/* Footer */
|
||||
.footer {
|
||||
margin-top: 1rem;
|
||||
background: rgba(0, 0, 0, 0.03);
|
||||
padding: 0.8rem 1.5rem;
|
||||
/* ---------- Add button ---------- */
|
||||
|
||||
.add-fab {
|
||||
position: fixed;
|
||||
bottom: 26px;
|
||||
right: 26px;
|
||||
width: 52px;
|
||||
height: 52px;
|
||||
border-radius: 50%;
|
||||
border: none;
|
||||
background: #4A90D9;
|
||||
color: #FFFFFF;
|
||||
font-size: 26px;
|
||||
font-weight: 400;
|
||||
line-height: 1;
|
||||
cursor: pointer;
|
||||
box-shadow: 0 6px 16px rgba(74, 144, 217, 0.4);
|
||||
}
|
||||
|
||||
.add-fab:hover {
|
||||
background: #3A7BC0;
|
||||
}
|
||||
|
||||
.add-toast {
|
||||
position: fixed;
|
||||
bottom: 90px;
|
||||
right: 26px;
|
||||
background: #1F2430;
|
||||
color: #FFFFFF;
|
||||
padding: 10px 16px;
|
||||
border-radius: 10px;
|
||||
font-size: 12.5px;
|
||||
max-width: 240px;
|
||||
opacity: 0;
|
||||
transform: translateY(6px);
|
||||
transition: opacity 0.2s ease, transform 0.2s ease;
|
||||
pointer-events: none;
|
||||
}
|
||||
|
||||
.joke {
|
||||
font-size: 1.3rem;
|
||||
font-weight: 500;
|
||||
font-style: italic;
|
||||
text-align: center;
|
||||
opacity: 0.9;
|
||||
text-shadow: 1px 1px 2px rgba(0, 0, 0, 0.5);
|
||||
.add-toast.visible {
|
||||
opacity: 1;
|
||||
transform: translateY(0);
|
||||
}
|
||||
|
||||
/* Scrollbar styling */
|
||||
::-webkit-scrollbar {
|
||||
width: 8px;
|
||||
/* Scrollbar styling for day columns */
|
||||
.day-events::-webkit-scrollbar {
|
||||
width: 4px;
|
||||
}
|
||||
|
||||
::-webkit-scrollbar-track {
|
||||
background: rgba(255, 255, 255, 0.05);
|
||||
border-radius: 10px;
|
||||
}
|
||||
|
||||
::-webkit-scrollbar-thumb {
|
||||
background: rgba(255, 255, 255, 0.2);
|
||||
border-radius: 10px;
|
||||
}
|
||||
|
||||
::-webkit-scrollbar-thumb:hover {
|
||||
background: rgba(255, 255, 255, 0.3);
|
||||
}
|
||||
|
||||
/* Responsive adjustments for smaller screens */
|
||||
@media (max-width: 1200px) {
|
||||
.time {
|
||||
font-size: 5rem;
|
||||
}
|
||||
|
||||
.date {
|
||||
font-size: 2rem;
|
||||
}
|
||||
|
||||
.current-temp {
|
||||
font-size: 4rem;
|
||||
}
|
||||
|
||||
section h2 {
|
||||
font-size: 2.5rem;
|
||||
}
|
||||
}
|
||||
|
||||
@media (max-width: 768px) {
|
||||
.main-content {
|
||||
grid-template-columns: 1fr;
|
||||
}
|
||||
|
||||
.time {
|
||||
font-size: 4rem;
|
||||
}
|
||||
|
||||
.current-temp {
|
||||
font-size: 3.5rem;
|
||||
}
|
||||
.day-events::-webkit-scrollbar-thumb {
|
||||
background: #E3E5EA;
|
||||
border-radius: 4px;
|
||||
}
|
||||
|
||||
426
static/js/app.js
426
static/js/app.js
@@ -2,315 +2,195 @@
|
||||
const INTERVALS = {
|
||||
TIME: 1000, // 1 second
|
||||
WEATHER: 900000, // 15 minutes
|
||||
CALENDAR: 300000, // 5 minutes
|
||||
BACKGROUND: 3600000, // 60 minutes
|
||||
JOKE: 3600000 // 1 hour
|
||||
CALENDAR: 300000 // 5 minutes
|
||||
};
|
||||
|
||||
const DAY_LABELS = ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday'];
|
||||
const MONTH_LABELS = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'];
|
||||
|
||||
let currentWeekStart = startOfWeek(new Date());
|
||||
let activeFilter = 'all';
|
||||
let filterOptionsBuilt = false;
|
||||
let lastWeekData = null;
|
||||
|
||||
// Return an OWM icon image tag for a given icon code
|
||||
function weatherIcon(code) {
|
||||
const src = `https://openweathermap.org/img/wn/${code}@2x.png`;
|
||||
return `<img src="${src}" alt="${code}" class="owm-icon">`;
|
||||
}
|
||||
|
||||
// Initialize the application
|
||||
document.addEventListener('DOMContentLoaded', () => {
|
||||
// Start all update functions
|
||||
updateTime();
|
||||
updateWeather();
|
||||
updateCalendar();
|
||||
updateBackground();
|
||||
updateJoke();
|
||||
|
||||
// Set up intervals
|
||||
setInterval(updateTime, INTERVALS.TIME);
|
||||
setInterval(updateWeather, INTERVALS.WEATHER);
|
||||
setInterval(updateCalendar, INTERVALS.CALENDAR);
|
||||
setInterval(updateBackground, INTERVALS.BACKGROUND);
|
||||
setInterval(updateJoke, INTERVALS.JOKE);
|
||||
});
|
||||
|
||||
// Update time and date
|
||||
function updateTime() {
|
||||
const now = new Date();
|
||||
|
||||
// Format time (HH:MM)
|
||||
const hours = String(now.getHours()).padStart(2, '0');
|
||||
const minutes = String(now.getMinutes()).padStart(2, '0');
|
||||
document.getElementById('time').textContent = `${hours}:${minutes}`;
|
||||
|
||||
// Format date (Day, Month Date)
|
||||
const options = { weekday: 'long', month: 'long', day: 'numeric' };
|
||||
const dateString = now.toLocaleDateString('en-NZ', options);
|
||||
document.getElementById('date').textContent = dateString;
|
||||
// Sunday-starting week for a given date
|
||||
function startOfWeek(date) {
|
||||
const d = new Date(date);
|
||||
d.setHours(0, 0, 0, 0);
|
||||
d.setDate(d.getDate() - d.getDay());
|
||||
return d;
|
||||
}
|
||||
|
||||
// Fetch and update weather
|
||||
function toISODate(date) {
|
||||
const y = date.getFullYear();
|
||||
const m = String(date.getMonth() + 1).padStart(2, '0');
|
||||
const d = String(date.getDate()).padStart(2, '0');
|
||||
return `${y}-${m}-${d}`;
|
||||
}
|
||||
|
||||
function formatRangeLabel(startISO, endISO) {
|
||||
const start = new Date(startISO + 'T00:00:00');
|
||||
const end = new Date(endISO + 'T00:00:00');
|
||||
const startLabel = `${MONTH_LABELS[start.getMonth()]} ${start.getDate()}`;
|
||||
const endLabel = end.getMonth() === start.getMonth() ? `${end.getDate()}` : `${MONTH_LABELS[end.getMonth()]} ${end.getDate()}`;
|
||||
return `${startLabel}-${endLabel}`;
|
||||
}
|
||||
|
||||
// Initialize the application
|
||||
document.addEventListener('DOMContentLoaded', () => {
|
||||
updateTime();
|
||||
updateWeather();
|
||||
fetchCalendar();
|
||||
|
||||
document.getElementById('prev-week').addEventListener('click', () => shiftWeek(-7));
|
||||
document.getElementById('next-week').addEventListener('click', () => shiftWeek(7));
|
||||
document.getElementById('member-filter').addEventListener('change', (e) => {
|
||||
activeFilter = e.target.value;
|
||||
if (lastWeekData) renderWeek(lastWeekData);
|
||||
});
|
||||
document.getElementById('add-btn').addEventListener('click', showAddToast);
|
||||
|
||||
setInterval(updateTime, INTERVALS.TIME);
|
||||
setInterval(updateWeather, INTERVALS.WEATHER);
|
||||
setInterval(fetchCalendar, INTERVALS.CALENDAR);
|
||||
});
|
||||
|
||||
function shiftWeek(days) {
|
||||
currentWeekStart = new Date(currentWeekStart);
|
||||
currentWeekStart.setDate(currentWeekStart.getDate() + days);
|
||||
fetchCalendar();
|
||||
}
|
||||
|
||||
// Update time and date in the header
|
||||
function updateTime() {
|
||||
const now = new Date();
|
||||
const hours = String(now.getHours()).padStart(2, '0');
|
||||
const minutes = String(now.getMinutes()).padStart(2, '0');
|
||||
document.getElementById('header-time').textContent = `${hours}:${minutes}`;
|
||||
document.getElementById('header-date').textContent = `${MONTH_LABELS[now.getMonth()]} ${String(now.getDate()).padStart(2, '0')}`;
|
||||
}
|
||||
|
||||
// Fetch and update weather chip
|
||||
async function updateWeather() {
|
||||
try {
|
||||
const response = await fetch('/api/weather');
|
||||
if (!response.ok) throw new Error('Weather fetch failed');
|
||||
|
||||
const data = await response.json();
|
||||
if (data.error || !data.current) return;
|
||||
|
||||
if (data.error) {
|
||||
console.error('Weather error:', data.error);
|
||||
return;
|
||||
}
|
||||
|
||||
// Update current weather in header
|
||||
const { current, forecast } = data;
|
||||
|
||||
document.getElementById('current-temp').textContent = `${current.temp}°`;
|
||||
document.getElementById('weather-icon').innerHTML = weatherIcon(current.icon);
|
||||
|
||||
// Update 3-day forecast in header
|
||||
const headerForecast = document.getElementById('header-forecast');
|
||||
headerForecast.innerHTML = '';
|
||||
|
||||
forecast.forEach(day => {
|
||||
const dayElement = document.createElement('div');
|
||||
dayElement.className = 'forecast-item';
|
||||
dayElement.innerHTML = `
|
||||
<div class="weather-label">${day.date}</div>
|
||||
<div class="forecast-icon">${weatherIcon(day.icon)}</div>
|
||||
<div class="forecast-temps">
|
||||
<span class="high">${day.temp_max}°</span>
|
||||
<span class="low">${day.temp_min}°</span>
|
||||
</div>
|
||||
`;
|
||||
headerForecast.appendChild(dayElement);
|
||||
});
|
||||
|
||||
document.getElementById('current-temp').textContent = `${data.current.temp}°`;
|
||||
document.getElementById('weather-icon').innerHTML = weatherIcon(data.current.icon);
|
||||
} catch (error) {
|
||||
console.error('Error updating weather:', error);
|
||||
}
|
||||
}
|
||||
|
||||
// Fetch and update calendar events
|
||||
async function updateCalendar() {
|
||||
// Fetch the current week's calendar data and render it
|
||||
async function fetchCalendar() {
|
||||
try {
|
||||
const response = await fetch('/api/calendar');
|
||||
const response = await fetch(`/api/calendar?start=${toISODate(currentWeekStart)}`);
|
||||
if (!response.ok) throw new Error('Calendar fetch failed');
|
||||
|
||||
const events = await response.json();
|
||||
|
||||
if (events.error) {
|
||||
console.error('Calendar error:', events.error);
|
||||
return;
|
||||
}
|
||||
|
||||
const eventsContainer = document.getElementById('calendar-events');
|
||||
|
||||
if (!events || events.length === 0) {
|
||||
eventsContainer.innerHTML = '<div class="event-placeholder">No upcoming events</div>';
|
||||
return;
|
||||
}
|
||||
|
||||
// Group events by day
|
||||
const eventsByDay = {};
|
||||
const today = new Date();
|
||||
today.setHours(0, 0, 0, 0);
|
||||
|
||||
// Create 5 days (today + 4 more)
|
||||
for (let i = 0; i < 5; i++) {
|
||||
const date = new Date(today);
|
||||
date.setDate(today.getDate() + i);
|
||||
const dateKey = date.toISOString().split('T')[0];
|
||||
eventsByDay[dateKey] = {
|
||||
date: date,
|
||||
events: []
|
||||
};
|
||||
}
|
||||
|
||||
// Group events by their date (including multi-day events)
|
||||
events.forEach(event => {
|
||||
const eventStart = new Date(event.start);
|
||||
const eventEnd = new Date(event.end);
|
||||
eventStart.setHours(0, 0, 0, 0);
|
||||
eventEnd.setHours(0, 0, 0, 0);
|
||||
|
||||
// Check each day in our 5-day view
|
||||
Object.keys(eventsByDay).forEach(dateKey => {
|
||||
const dayDate = new Date(eventsByDay[dateKey].date);
|
||||
dayDate.setHours(0, 0, 0, 0);
|
||||
|
||||
// Include event if this day falls within the event's duration
|
||||
if (dayDate >= eventStart && dayDate <= eventEnd) {
|
||||
eventsByDay[dateKey].events.push(event);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
// Render events grouped by day
|
||||
eventsContainer.innerHTML = '';
|
||||
|
||||
Object.keys(eventsByDay).sort().forEach(dateKey => {
|
||||
const dayData = eventsByDay[dateKey];
|
||||
const dayElement = document.createElement('div');
|
||||
dayElement.className = 'day-group';
|
||||
|
||||
// Format day header
|
||||
const dayDate = dayData.date;
|
||||
const isToday = dayDate.toDateString() === new Date().toDateString();
|
||||
const dayName = isToday ? 'Today' : dayDate.toLocaleDateString('en-NZ', { weekday: 'long' });
|
||||
const dateStr = dayDate.toLocaleDateString('en-NZ', { day: 'numeric', month: 'short' });
|
||||
|
||||
dayElement.innerHTML = `
|
||||
<div class="day-header">
|
||||
<span class="day-name">${dayName}</span>
|
||||
<span class="day-date">${dateStr}</span>
|
||||
</div>
|
||||
<div class="day-events"></div>
|
||||
`;
|
||||
|
||||
const dayEventsContainer = dayElement.querySelector('.day-events');
|
||||
|
||||
if (dayData.events.length === 0) {
|
||||
dayEventsContainer.innerHTML = '<div class="no-events">No events</div>';
|
||||
} else {
|
||||
dayData.events.forEach(event => {
|
||||
const eventElement = document.createElement('div');
|
||||
eventElement.className = 'event';
|
||||
|
||||
const startTime = new Date(event.start);
|
||||
const endTime = new Date(event.end);
|
||||
|
||||
// Check if it's an all-day event (time is 00:00)
|
||||
const isAllDay = startTime.getHours() === 0 && startTime.getMinutes() === 0
|
||||
&& endTime.getHours() === 0 && endTime.getMinutes() === 0;
|
||||
|
||||
let timeString;
|
||||
if (isAllDay) {
|
||||
timeString = 'All day';
|
||||
} else {
|
||||
timeString = startTime.toLocaleTimeString('en-NZ', { hour: '2-digit', minute: '2-digit' });
|
||||
}
|
||||
|
||||
eventElement.innerHTML = `
|
||||
<div class="event-time">${timeString}</div>
|
||||
<div class="event-title">${event.title}</div>
|
||||
${event.location ? `<div class="event-location">📍 ${event.location}</div>` : ''}
|
||||
`;
|
||||
|
||||
dayEventsContainer.appendChild(eventElement);
|
||||
});
|
||||
}
|
||||
|
||||
eventsContainer.appendChild(dayElement);
|
||||
});
|
||||
const data = await response.json();
|
||||
lastWeekData = data;
|
||||
|
||||
document.getElementById('week-range').textContent = formatRangeLabel(data.week_start, data.week_end);
|
||||
buildFilterOptions(data.members);
|
||||
renderWeek(data);
|
||||
} catch (error) {
|
||||
console.error('Error updating calendar:', error);
|
||||
document.getElementById('week-grid').innerHTML = '<div class="event-placeholder">Unable to load calendar</div>';
|
||||
}
|
||||
}
|
||||
|
||||
// Calculate brightness of an image
|
||||
function calculateImageBrightness(imageSrc, callback) {
|
||||
const img = new Image();
|
||||
img.crossOrigin = 'Anonymous';
|
||||
|
||||
img.onload = () => {
|
||||
// Create a canvas to analyze the image
|
||||
const canvas = document.createElement('canvas');
|
||||
const ctx = canvas.getContext('2d');
|
||||
|
||||
// Use a smaller size for faster processing
|
||||
canvas.width = 100;
|
||||
canvas.height = 100;
|
||||
|
||||
// Draw the image scaled down
|
||||
ctx.drawImage(img, 0, 0, 100, 100);
|
||||
|
||||
// Get image data
|
||||
const imageData = ctx.getImageData(0, 0, 100, 100);
|
||||
const data = imageData.data;
|
||||
|
||||
// Calculate average brightness
|
||||
let totalBrightness = 0;
|
||||
const pixelCount = data.length / 4;
|
||||
|
||||
for (let i = 0; i < data.length; i += 4) {
|
||||
const r = data[i];
|
||||
const g = data[i + 1];
|
||||
const b = data[i + 2];
|
||||
|
||||
// Calculate perceived brightness (using luminance formula)
|
||||
const brightness = (0.299 * r + 0.587 * g + 0.114 * b);
|
||||
totalBrightness += brightness;
|
||||
}
|
||||
|
||||
const avgBrightness = totalBrightness / pixelCount;
|
||||
|
||||
// Return brightness value (0-255)
|
||||
callback(avgBrightness);
|
||||
};
|
||||
|
||||
img.onerror = () => {
|
||||
console.error('Error loading image for brightness analysis');
|
||||
// Default to dark background if error
|
||||
callback(100);
|
||||
};
|
||||
|
||||
img.src = imageSrc;
|
||||
function buildFilterOptions(members) {
|
||||
if (filterOptionsBuilt || !members) return;
|
||||
const select = document.getElementById('member-filter');
|
||||
members.forEach(member => {
|
||||
const option = document.createElement('option');
|
||||
option.value = member.key;
|
||||
option.textContent = member.name;
|
||||
select.appendChild(option);
|
||||
});
|
||||
filterOptionsBuilt = true;
|
||||
}
|
||||
|
||||
// Update background image
|
||||
async function updateBackground() {
|
||||
try {
|
||||
const response = await fetch('/api/background');
|
||||
if (!response.ok) throw new Error('Background fetch failed');
|
||||
function filterEvents(events) {
|
||||
if (activeFilter === 'all') return events;
|
||||
return events.filter(e => e.member === activeFilter);
|
||||
}
|
||||
|
||||
const data = await response.json();
|
||||
const backgroundElement = document.getElementById('background');
|
||||
function formatEventTime(event) {
|
||||
const start = new Date(event.start);
|
||||
const end = new Date(event.end);
|
||||
const isAllDay = start.getHours() === 0 && start.getMinutes() === 0 && end.getHours() === 0 && end.getMinutes() === 0;
|
||||
if (isAllDay) return 'All day';
|
||||
return start.toLocaleTimeString('en-NZ', { hour: '2-digit', minute: '2-digit' });
|
||||
}
|
||||
|
||||
if (data.image) {
|
||||
// Preload image to avoid flicker
|
||||
const img = new Image();
|
||||
img.onload = () => {
|
||||
backgroundElement.style.backgroundImage = `url('${data.image}')`;
|
||||
function eventCardHTML(event) {
|
||||
return `
|
||||
<div class="event-card" style="background:${event.bg}; border-left-color:${event.color};">
|
||||
<div class="event-time">${formatEventTime(event)}</div>
|
||||
<div class="event-title">${event.title}</div>
|
||||
<div class="event-member">${event.member_name}</div>
|
||||
</div>
|
||||
`;
|
||||
}
|
||||
|
||||
// Analyze brightness and adjust text color
|
||||
calculateImageBrightness(data.image, (brightness) => {
|
||||
// Threshold: 128 is middle brightness
|
||||
// If brightness > 140, use dark text (light background)
|
||||
// If brightness <= 140, use white text (dark background)
|
||||
if (brightness > 140) {
|
||||
document.body.classList.remove('dark-bg');
|
||||
document.body.classList.add('light-bg');
|
||||
} else {
|
||||
document.body.classList.remove('light-bg');
|
||||
document.body.classList.add('dark-bg');
|
||||
}
|
||||
});
|
||||
};
|
||||
img.src = data.image;
|
||||
} else if (data.color) {
|
||||
backgroundElement.style.backgroundColor = data.color;
|
||||
backgroundElement.style.backgroundImage = 'none';
|
||||
// Assume solid colors are dark
|
||||
document.body.classList.remove('light-bg');
|
||||
document.body.classList.add('dark-bg');
|
||||
}
|
||||
function renderWeek(data) {
|
||||
const grid = document.getElementById('week-grid');
|
||||
grid.innerHTML = '';
|
||||
|
||||
} catch (error) {
|
||||
console.error('Error updating background:', error);
|
||||
}
|
||||
}
|
||||
|
||||
// Fetch and update dad joke
|
||||
async function updateJoke() {
|
||||
try {
|
||||
const response = await fetch('/api/joke');
|
||||
if (!response.ok) throw new Error('Joke fetch failed');
|
||||
|
||||
const data = await response.json();
|
||||
|
||||
if (data.joke) {
|
||||
document.getElementById('joke').textContent = data.joke;
|
||||
}
|
||||
|
||||
} catch (error) {
|
||||
console.error('Error updating joke:', error);
|
||||
const todayISO = toISODate(new Date());
|
||||
|
||||
data.days.forEach(day => {
|
||||
const dayDate = new Date(day.date + 'T00:00:00');
|
||||
const events = filterEvents(day.events);
|
||||
|
||||
const column = document.createElement('div');
|
||||
column.className = 'day-column' + (day.date === todayISO ? ' is-today' : '');
|
||||
column.innerHTML = `
|
||||
<div class="day-header">
|
||||
<div class="day-name">${DAY_LABELS[dayDate.getDay()]}</div>
|
||||
<div class="day-number">${dayDate.getDate()}</div>
|
||||
<div class="day-count">${events.length} event${events.length === 1 ? '' : 's'}</div>
|
||||
</div>
|
||||
<div class="day-events">
|
||||
${events.map(eventCardHTML).join('') || ''}
|
||||
</div>
|
||||
`;
|
||||
grid.appendChild(column);
|
||||
});
|
||||
|
||||
const nextWeekEvents = filterEvents(data.next_week.events);
|
||||
const nextColumn = document.createElement('div');
|
||||
nextColumn.className = 'next-week-column';
|
||||
nextColumn.innerHTML = `
|
||||
<div class="next-week-title">Next Week</div>
|
||||
<div class="next-week-range">${formatRangeLabel(data.next_week.start, data.next_week.end)}</div>
|
||||
<div class="next-week-count">${data.next_week.count} event${data.next_week.count === 1 ? '' : 's'}</div>
|
||||
`;
|
||||
nextColumn.addEventListener('click', () => shiftWeek(7));
|
||||
grid.appendChild(nextColumn);
|
||||
}
|
||||
|
||||
function showAddToast() {
|
||||
let toast = document.querySelector('.add-toast');
|
||||
if (!toast) {
|
||||
toast = document.createElement('div');
|
||||
toast.className = 'add-toast';
|
||||
toast.textContent = 'This display is read-only — add events directly in Google Calendar.';
|
||||
document.body.appendChild(toast);
|
||||
}
|
||||
toast.classList.add('visible');
|
||||
clearTimeout(showAddToast._timer);
|
||||
showAddToast._timer = setTimeout(() => toast.classList.remove('visible'), 3000);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user