27 lines
21 KiB
JavaScript
27 lines
21 KiB
JavaScript
if('serviceWorker'in navigator)window.addEventListener('load',()=>navigator.serviceWorker.register('./service-worker.js').catch(()=>{}));
|
||
const messages = [
|
||
{id:1, initials:'AL', color:'#ead1c1', sender:'Amelia Laurent', email:'amelia@northstar.design', subject:'The new studio is ready ✨', snippet:'I finally get to show you what we’ve been working on. There’s light in every corner.', time:'9:41 AM', date:'Today, 9:41 AM', unread:true, star:true, tags:['Design','New'], body:["Hey Mira,","After months of sketches, coffee, and very optimistic tape measurements, the new Northstar studio is ready. We wanted it to feel like a place you could arrive at slowly — the kind of room where morning light does most of the decorating.","I’ve attached the first look at the space. Come by next week? I’d love to make you that cardamom coffee you keep asking about.","Warmly,"] , signature:'Amelia', attachment:'northstar-studio.jpg', size:'4.8 MB'},
|
||
{id:2, initials:'JK', color:'#d8e3d4', sender:'Jonah Kim', email:'jonah@fieldnotes.co', subject:'Re: Weekend in the mountains?', snippet:'The forecast looks perfect for Saturday. I found a cabin with a little wood stove...', time:'8:22 AM', date:'Today, 8:22 AM', unread:true, star:false, tags:['Personal'], body:["Morning!","The forecast looks perfect for Saturday. I found a cabin with a little wood stove and a trail that starts right behind it. Sending you the details now — it feels like exactly the kind of weekend we need.","Bring a book. I’ll bring the coffee and the slightly overambitious packing list.","See you soon,"] , signature:'Jonah'},
|
||
{id:3, initials:'SP', color:'#e8d9e9', sender:'Sofia Park', email:'sofia@smallhours.works', subject:'A little idea for the spring launch', snippet:'What if the whole thing felt like opening a window after a long winter?', time:'Yesterday', date:'Yesterday, 4:16 PM', unread:true, star:true, tags:['Design'], body:["Hi Mira,","What if the whole spring launch felt like opening a window after a long winter? I put a few thoughts into a tiny moodboard. Soft color, honest materials, lots of breathing room.","Would love your instinct on it. No rush — just thought I’d put it somewhere sunny for you to find.","Sofia"]},
|
||
{id:4, initials:'MR', color:'#d9e4e9', sender:'Mateo Rivera', email:'mateo@roam.travel', subject:'Your Lisbon itinerary is here', snippet:'Three quiet mornings, one very good bakery, and a tram ride that goes nowhere in particular.', time:'Yesterday', date:'Yesterday, 2:03 PM', unread:true, star:false, tags:['Travel'], body:["Your Lisbon itinerary is ready!","Three quiet mornings, one very good bakery, and a tram ride that goes nowhere in particular. I kept the afternoons open so you can wander. The bookshop and the tiny ceramics studio are both on the way from your hotel.","Everything is in the attached guide. Have the loveliest time — Lisbon is best when you let it surprise you.","Mateo"] , attachment:'lisbon-slow-guide.pdf', size:'2.1 MB'},
|
||
{id:5, initials:'ED', color:'#eee1c6', sender:'Eden Foster', email:'eden@paperandpine.com', subject:'Thank you for yesterday', snippet:'Still thinking about the conversation and the lemon cake. Both were exactly what I needed.', time:'Oct 2', date:'Oct 2, 2026', unread:false, star:false, tags:['Personal'], body:["Mira,","Still thinking about our conversation and the lemon cake. Both were exactly what I needed. Thank you for making an ordinary Thursday feel like a small holiday.","I hope your weekend is full of slow breakfasts and absolutely no urgent emails.","Eden"]},
|
||
{id:6, initials:'NB', color:'#d9d8ec', sender:'Noah Bennett', email:'noah@common-thread.org', subject:'Community garden — October notes', snippet:'The first seedlings are in, and our corner of the neighborhood is already greener.', time:'Oct 2', date:'Oct 2, 2026', unread:false, star:true, tags:['Personal'], body:["Hi everyone,","The first autumn seedlings are in and our corner of the neighborhood is already greener. Thank you to everyone who brought tools, snacks, and patient hands.","Next gathering is Sunday at ten. All levels of gardening optimism are welcome.","Noah"]},
|
||
{id:7, initials:'IR', color:'#ead6d4', sender:'Iris Rowe', email:'iris@littlefern.press', subject:'The book you left at my place', snippet:'I’ve tucked in a note at the page where I stopped. You’ll know why when you get there.', time:'Oct 1', date:'Oct 1, 2026', unread:false, star:false, tags:['Personal'], body:["Hey you,","I’ve tucked a note in at the page where I stopped. You’ll know why when you get there. No rush returning it — I think this one likes a slow reader.","I’ll be home Sunday if you want to pick it up and stay for tea.","Iris"]},
|
||
{id:8, initials:'AI', color:'#d6e3d9', sender:'Aster Intelligence', email:'updates@aster.ai', subject:'Your September reflections', snippet:'A small look back at what you made space for this month. Here’s to a softer October.', time:'Sep 30', date:'Sep 30, 2026', unread:false, star:false, tags:['Personal'], body:["September, in little moments","This month you spent more time outdoors, caught up with people you love, and made room for a new idea. That’s something worth keeping.","Here’s to a softer October — one with space for the things you haven’t thought of yet.","Aster"]}
|
||
];
|
||
const contacts=[['Amelia Laurent','amelia@northstar.design','Design partner','AL','#ead1c1'],['Jonah Kim','jonah@fieldnotes.co','Friend','JK','#d8e3d4'],['Sofia Park','sofia@smallhours.works','Creative director','SP','#e8d9e9'],['Mateo Rivera','mateo@roam.travel','Travel planner','MR','#d9e4e9'],['Eden Foster','eden@paperandpine.com','Friend','ED','#eee1c6'],['Noah Bennett','noah@common-thread.org','Garden club','NB','#d9d8ec'],['Iris Rowe','iris@littlefern.press','Friend','IR','#ead6d4']];
|
||
let activeMessage=1,activeFolder='Inbox',activeView='mail',query='',toastTimer,selectedIds=new Set();
|
||
const $=s=>document.querySelector(s), $$=s=>[...document.querySelectorAll(s)];
|
||
function esc(x){return String(x).replace(/[&<>"']/g,c=>({'&':'&','<':'<','>':'>','"':'"',"'":'''}[c]))}
|
||
function renderList(){let rows=messages.filter(m=>{if(activeFolder==='Starred'&&!m.star)return false;if(activeFolder==='Inbox'&&m.archived)return false;if(activeFolder==='Archive'&&!m.archived)return false;if(activeFolder==='Trash'&&!m.deleted)return false;if(activeFolder==='Sent')return false;if(activeFolder==='Drafts')return false;if(activeFolder==='Snoozed')return false;if(m.deleted&&activeFolder!=='Trash')return false;return !query||`${m.sender} ${m.email} ${m.subject} ${m.snippet}`.toLowerCase().includes(query.toLowerCase())});$('#message-list').innerHTML=rows.length?rows.map(m=>`<div class="message ${m.unread?'unread':''} ${m.id===activeMessage?'selected':''}" data-id="${m.id}"><input class="row-check" type="checkbox" aria-label="Select message" ${selectedIds.has(m.id)?'checked':''}><div class="contact-avatar" style="background:${m.color}">${m.initials}</div><div class="message-body"><div class="sender">${esc(m.sender)}</div><div class="subject">${esc(m.subject)}</div><div class="snippet">${esc(m.snippet)}</div></div><div class="message-meta"><span class="time">${esc(m.time)}</span><button class="star ${m.star?'on':''}" aria-label="${m.star?'Unstar':'Star'}">${m.star?'★':'☆'}</button></div></div>`).join(''):`<div class="reader-empty"><div><div class="empty-icon">⌕</div><h3>No messages here</h3><p>Try another folder or search.</p></div></div>`;$$('.message').forEach(row=>{row.addEventListener('click',e=>{if(e.target.closest('.row-check')){const id=+row.dataset.id;selectedIds.has(id)?selectedIds.delete(id):selectedIds.add(id);return}if(e.target.closest('.star')){const m=messages.find(x=>x.id===+row.dataset.id);m.star=!m.star;renderList();return}openMessage(+row.dataset.id)});});if(!rows.length)$('#reader-pane').innerHTML=''}
|
||
function openMessage(id){activeMessage=id;const m=messages.find(x=>x.id===id);if(!m)return;m.unread=false;renderList();$('#reader-pane').innerHTML=`<div class="reader-header"><div class="reader-topline"><div class="reader-tags">${m.tags.map((t,i)=>`<span class="tag ${i?'green':''}">${esc(t)}</span>`).join('')}</div><div class="reader-tools"><button class="icon-button" id="reader-archive" title="Archive">▱</button><button class="icon-button" id="reader-delete" title="Delete">⌫</button><button class="icon-button" title="More">···</button></div></div><h2 class="reader-subject">${esc(m.subject)}</h2><div class="sender-row"><div class="contact-avatar" style="background:${m.color}">${m.initials}</div><div class="sender-details"><strong>${esc(m.sender)}</strong><span>${esc(m.email)} · to me</span></div><span class="message-date">${esc(m.date)}</span><button class="icon-button" title="Star" id="reader-star">${m.star?'★':'☆'}</button></div></div><div class="reader-body">${m.body.map(p=>`<p>${esc(p)}</p>`).join('')}<p class="signoff">${esc(m.signature||m.sender)}</p>${m.attachment?`<div class="attachment"><div class="file-icon">${m.attachment.endsWith('.pdf')?'▤':'▧'}</div><div class="attachment-info"><strong>${esc(m.attachment)}</strong><small>${m.size} · Preview ready</small></div><button class="download" title="Download">↓</button></div>`:''}</div><div class="reply-bar"><button class="reply-button primary" id="reply">↶ Reply</button><button class="reply-button" id="forward">↗ Forward</button></div>`;$('#reader-archive').onclick=()=>{m.archived=true;toast('Moved to Archive');renderList();$('#reader-pane').innerHTML=emptyReader()};$('#reader-delete').onclick=()=>{m.deleted=true;toast('Moved to Trash');renderList();$('#reader-pane').innerHTML=emptyReader()};$('#reader-star').onclick=()=>{m.star=!m.star;renderList();openMessage(id)};$('#reply').onclick=()=>showCompose(m);$('#forward').onclick=()=>showCompose(m,true)}
|
||
function emptyReader(){return `<div class="reader-empty"><div><div class="empty-icon">✉</div><h3>Your inbox, at your pace</h3><p>Select a message to read it here.</p></div></div>`}
|
||
function toast(s){const el=$('#toast');el.textContent=s;el.classList.add('visible');clearTimeout(toastTimer);toastTimer=setTimeout(()=>el.classList.remove('visible'),2300)}
|
||
function showCompose(reply,forward=false){const root=$('#modal-root');root.innerHTML=`<div class="modal-overlay"><div class="compose-modal"><div class="modal-head"><span>${reply?(forward?'Forward message':'Reply to message'):'New message'}</span><button class="modal-close" aria-label="Close">×</button></div><div class="compose-fields"><label class="compose-line"><span>To</span><input id="compose-to" placeholder="name@example.com" value="${reply?esc(forward?'':reply.email):''}"></label><label class="compose-line"><span>Cc</span><input id="compose-cc" placeholder="Add Cc"></label><input id="compose-subject" class="compose-subject" placeholder="Subject" value="${reply?esc((forward?'Fwd: ':'Re: ')+reply.subject):''}"></div><textarea class="compose-body" id="compose-body" placeholder="Write something thoughtful…">${reply&&!forward?'\n\nOn '+reply.date+', '+reply.sender+' wrote:\n> '+reply.snippet:''}</textarea><div class="compose-footer"><button class="discard" id="discard">Discard</button><button class="send-button" id="send">Send ↗</button></div></div></div>`;const close=()=>root.innerHTML='';$('.modal-close').onclick=close;$('#discard').onclick=close;$('.modal-overlay').addEventListener('click',e=>{if(e.target.classList.contains('modal-overlay'))close()});$('#send').onclick=()=>{const to=$('#compose-to').value.trim();if(!to){$('#compose-to').focus();toast('Add a recipient to send your message');return}const subject=$('#compose-subject').value.trim()||'(no subject)';const body=$('#compose-body').value;messages.unshift({id:Date.now(),initials:'MS',color:'#dce9dd',sender:'Mira Sol',email:'mira@daybreak.studio',subject,snippet:body||'No message text',time:'Just now',date:'Today',unread:false,star:false,tags:['Sent'],body:body.split('\n').filter(Boolean)});close();toast('Message sent');renderList()};$('#compose-to').focus()}
|
||
function switchView(view){activeView=view;$$('.rail-button[data-view]').forEach(b=>b.classList.toggle('active',b.dataset.view===view));$('.mail-layout').classList.toggle('hidden',view!=='mail');$('#calendar-view').classList.toggle('hidden',view!=='calendar');$('#contacts-view').classList.toggle('hidden',view!=='contacts');$('#sidebar-title').textContent=view==='mail'?activeFolder:view==='calendar'?'Calendar':'Contacts';$('#crumb-parent').textContent=view==='mail'?'Mail':'Workspace';$('#crumb-current').textContent=view==='mail'?activeFolder:view==='calendar'?'Calendar':'Contacts';}
|
||
function renderCalendar(){const days=['Sun','Mon','Tue','Wed','Thu','Fri','Sat'];const start=new Date(2026,9,1);const offset=start.getDay();const events={4:[['10:00','Studio catch-up','green'],[14,'A little time outside','gold']],7:[['11:30','Design review','blue']],11:[['09:00','Coffee with Jonah','gold'],[15,'Focus time','green']],15:[['13:00','Spring launch','blue']],18:[['10:00','Community garden','green']],22:[['16:00','Lisbon planning','gold']],27:[['09:30','Studio catch-up','blue']]};let cells='';for(let i=0;i<35;i++){const n=i-offset+1,valid=n>0&&n<=31,items=events[n]||[];cells+=`<div class="cal-cell ${valid?'':'outside'} ${n===4?'today':''}" data-day="${valid?n:''}"><span class="cal-number">${valid?n:''}</span>${items.map(it=>`<div class="event-chip ${it[2]}" data-event="${esc(it[1])}">${esc(it[1])}</div>`).join('')}</div>`}$('#calendar-view').innerHTML=`<div class="page-heading"><div><p class="eyebrow">YOUR TIME, WITH ROOM TO BREATHE</p><h2>October 2026</h2><p class="page-subtitle">A month that still has room for surprises.</p></div><div class="cal-actions"><button class="outline-button" id="today-btn">Today</button><button class="outline-button" id="prev-month">‹</button><button class="outline-button" id="next-month">›</button><button class="compose-button" id="new-event">+ New event</button></div></div><div class="calendar-card"><div class="calendar-week">${days.map(d=>`<span>${d}</span>`).join('')}</div><div class="calendar-grid">${cells}</div></div><div class="upcoming"><h3>Coming up</h3><div class="upcoming-row"><span class="event-date">OCT<br><strong>07</strong></span><div><strong>Design review</strong><small>11:30 AM · with Sofia Park</small></div></div><div class="upcoming-row"><span class="event-date gold-date">OCT<br><strong>11</strong></span><div><strong>Coffee with Jonah</strong><small>9:00 AM · Little Fern Café</small></div></div></div>`;$('#new-event').onclick=()=>showEvent();$('#today-btn').onclick=()=>toast('You’re looking at this month');$('#prev-month').onclick=()=>toast('Previous month');$('#next-month').onclick=()=>toast('Next month');$$('.cal-cell').forEach(c=>c.onclick=e=>{if(e.target.closest('.event-chip'))toast(e.target.closest('.event-chip').dataset.event);else if(c.dataset.day)showEvent(c.dataset.day)})}
|
||
function showEvent(day){const root=$('#modal-root');root.innerHTML=`<div class="modal-overlay"><div class="compose-modal"><div class="modal-head"><span>Make a little room for it</span><button class="modal-close">×</button></div><div class="compose-fields"><label class="compose-line"><span>Event</span><input id="event-name" placeholder="Give it a name"></label><label class="compose-line"><span>Date</span><input id="event-date" type="date" value="2026-10-${String(day||4).padStart(2,'0')}"></label><label class="compose-line"><span>Time</span><input id="event-time" type="time" value="10:00"></label><label class="compose-line"><span>With</span><input id="event-people" placeholder="Add people"></label><label class="compose-line"><span>Place</span><input id="event-place" placeholder="Add a place"></label></div><div class="compose-footer"><button class="discard modal-close">Cancel</button><button class="send-button" id="save-event">Save event</button></div></div></div>`;$$('.modal-close').forEach(b=>b.onclick=()=>root.innerHTML='');$('#save-event').onclick=()=>{const name=$('#event-name').value.trim();if(!name){$('#event-name').focus();toast('Give your event a name');return}root.innerHTML='';toast('Event added to your calendar') }}
|
||
function renderContacts(){const cards=contacts.map(c=>`<article class="contact-card"><div class="contact-avatar" style="background:${c[4]}">${c[3]}</div><div><strong>${esc(c[0])}</strong><span>${esc(c[1])}</span><small>${esc(c[2])}</small></div><button class="icon-button contact-more" aria-label="Contact options">···</button><button class="contact-email" data-email="${esc(c[1])}" aria-label="Email ${esc(c[0])}">↗</button></article>`).join('');$('#contacts-view').innerHTML=`<div class="page-heading"><div><p class="eyebrow">THE PEOPLE WHO MAKE LIFE FULLER</p><h2>Your people</h2><p class="page-subtitle">${contacts.length} familiar faces, all in one place.</p></div><button class="compose-button" id="add-contact">+ Add contact</button></div><div class="contact-search"><span>⌕</span><input id="contact-search" placeholder="Find someone by name or email"></div><div class="contacts-grid">${cards}</div>`;$('#add-contact').onclick=()=>showContact();$('#contact-search').oninput=e=>{$$('.contact-card').forEach(c=>c.classList.toggle('hidden',!c.innerText.toLowerCase().includes(e.target.value.toLowerCase())))};$$('.contact-email').forEach(b=>b.onclick=()=>showCompose({email:b.dataset.email,subject:'',date:''}))}
|
||
function showContact(){const root=$('#modal-root');root.innerHTML=`<div class="modal-overlay"><div class="compose-modal"><div class="modal-head"><span>Add someone to your circle</span><button class="modal-close">×</button></div><div class="compose-fields"><label class="compose-line"><span>Name</span><input id="contact-name" placeholder="Their name"></label><label class="compose-line"><span>Email</span><input id="contact-email" type="email" placeholder="name@example.com"></label><label class="compose-line"><span>Note</span><input id="contact-note" placeholder="How you know them"></label></div><div class="compose-footer"><button class="discard modal-close">Cancel</button><button class="send-button" id="save-contact">Save contact</button></div></div></div>`;$$('.modal-close').forEach(b=>b.onclick=()=>root.innerHTML='');$('#save-contact').onclick=()=>{const name=$('#contact-name').value.trim(),email=$('#contact-email').value.trim();if(!name||!email){toast('Add a name and email');return}const initials=name.split(' ').map(x=>x[0]).join('').slice(0,2).toUpperCase();contacts.push([name,email,$('#contact-note').value||'Contact',initials,'#e7dfce']);root.innerHTML='';renderContacts();toast('Contact saved')}}
|
||
$$('.folder').forEach(b=>b.onclick=()=>{activeFolder=b.dataset.folder;$$('.folder').forEach(x=>x.classList.toggle('active',x===b));$('#sidebar-title').textContent=activeFolder;$('#crumb-current').textContent=activeFolder;renderList()});$$('.rail-button[data-view]').forEach(b=>b.onclick=()=>{switchView(b.dataset.view);if(b.dataset.view==='calendar')renderCalendar();if(b.dataset.view==='contacts')renderContacts()});$('#theme-toggle').onclick=()=>{document.body.classList.toggle('wasteland');const isWaste=document.body.classList.contains('wasteland');$('#theme-toggle span').textContent=isWaste?'☾':'☼';$('#theme-toggle').title=isWaste?'Switch to Eternity Daylight':'Switch to Wasteland';localStorage.setItem('daybreak-theme',isWaste?'wasteland':'daylight');toast(isWaste?'Wasteland theme':'Eternity Daylight theme')};if(localStorage.getItem('daybreak-theme')==='wasteland'){document.body.classList.add('wasteland');$('#theme-toggle span').textContent='☾'}$('#search').oninput=e=>{query=e.target.value;renderList()};$('#search').addEventListener('keydown',e=>{if(e.key==='Escape'){e.target.value='';query='';renderList()}});$('#compose').onclick=()=>showCompose();$('#refresh').onclick=()=>{toast('You’re all up to date');renderList()};$('#select-all').onclick=()=>{const visible=messages.filter(m=>!m.archived&&!m.deleted);const all=visible.every(m=>selectedIds.has(m.id));visible.forEach(m=>all?selectedIds.delete(m.id):selectedIds.add(m.id));renderList()};$('#archive-selected').onclick=()=>{messages.filter(m=>selectedIds.has(m.id)).forEach(m=>m.archived=true);selectedIds.clear();renderList();toast('Selected messages archived')};$('#delete-selected').onclick=()=>{messages.filter(m=>selectedIds.has(m.id)).forEach(m=>m.deleted=true);selectedIds.clear();renderList();toast('Selected messages moved to Trash')};$('#sidebar-menu').onclick=()=>toast('More mailbox options');$$('.settings-button,.help-button,.tiny-plus,.text-button').forEach(b=>b.onclick=()=>toast('You’re all caught up'));document.addEventListener('keydown',e=>{if((e.metaKey||e.ctrlKey)&&e.key.toLowerCase()==='k'){e.preventDefault();$('#search').focus()}if(e.key==='Escape')$('#modal-root').innerHTML=''});$('#today-label').textContent=new Intl.DateTimeFormat('en-US',{weekday:'long',month:'long',day:'numeric'}).format(new Date()).toUpperCase();$('#reader-pane').innerHTML=emptyReader();renderList();openMessage(activeMessage);
|