feat(ui): add ambient body doubling pill and focus room feed

This commit is contained in:
djg 2026-09-23 05:40:22 +00:00
parent 2077e9b1d7
commit b39f7fdb81
3 changed files with 379 additions and 22 deletions

View file

@ -28,6 +28,17 @@
<a href="#now" data-tab="now" class="tab" role="tab" id="tab-now" aria-selected="false" aria-controls="now">One thing</a>
<a href="#inbox" data-tab="inbox" class="tab" role="tab" id="tab-inbox" aria-selected="false" aria-controls="inbox">Brain dump</a>
</nav>
<div id="ambient-pill" class="ambient-pill" role="button" aria-expanded="false" tabindex="0">
<span class="pill-dot">🟢</span>
<span id="pill-count">..</span> with you
</div>
<div id="ambient-panel" class="ambient-panel" hidden>
<p class="ambient-panel-head">You are not alone. Across the world, people with ADHD are taking on tasks just like you.</p>
<ul id="ambient-feed" class="ambient-feed">
<!-- feed items added via JS -->
</ul>
<div id="ambient-cheer-btn" class="ambient-cheer" role="button" tabindex="0">Send a quiet cheer 🎉</div>
</div>
</header>
<main>
@ -101,7 +112,7 @@
<button class="chip preset break" data-min="5" aria-label="5 minute break">5 min break</button>
<button class="chip preset break" data-min="15" aria-label="15 minute break">15 min break</button>
</div>
<div class="row center gap" style="margin-bottom: 12px; margin-top: -8px;">
<button class="btn ghost toggle-visual" id="timer-mode-toggle" aria-label="Toggle Pie Clock Mode">
<svg width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" style="margin-right:8px; vertical-align:text-bottom;">
@ -133,12 +144,12 @@
</div>
<p class="tiny" id="timer-note">Tip: 25 minutes is a suggestion, not a law. The best length is the one you'll actually start.</p>
</div>
<div class="card center" style="margin-top: 16px;">
<h3>Interval Grounding</h3>
<p class="tiny" style="margin-bottom: 12px; margin-top: 4px;">Time blindness? A soft chime will ground you every few minutes to pull you out of rabbit holes.</p>
<div class="presets" style="margin-bottom: 8px;">
<button class="chip preset grounding-chime" data-interval="5" aria-label="Every 5 minutes">5 min pings</button>
<button class="chip preset grounding-chime" data-interval="10" aria-label="Every 10 minutes">10 min pings</button>

View file

@ -752,35 +752,35 @@
inboxItems.forEach(function (item, i) {
var li = document.createElement('li');
li.className = 'step';
var textDiv = document.createElement('div');
textDiv.className = 'step-text';
textDiv.textContent = item;
var editInput = document.createElement('input');
editInput.type = 'text';
editInput.className = 'step-edit-input sr-only';
editInput.value = item;
textDiv.addEventListener('click', function () {
textDiv.classList.add('sr-only');
editInput.classList.remove('sr-only');
editInput.focus();
});
function commitEdit() {
var v = editInput.value.trim();
if (!v) { inboxItems.splice(i, 1); }
else { inboxItems[i] = v; }
saveInbox();
}
editInput.addEventListener('blur', commitEdit);
editInput.addEventListener('keydown', function(e) { if (e.key === 'Enter') commitEdit(); });
var actionsDiv = document.createElement('div');
actionsDiv.className = 'row gap';
var breakBtn = document.createElement('button');
breakBtn.className = 'btn ghost small';
breakBtn.textContent = 'break this down';
@ -791,7 +791,7 @@
showTab('breaker');
$('#breaker-form').dispatchEvent(new Event('submit'));
});
var delBtn = document.createElement('button');
delBtn.className = 'btn ghost small';
delBtn.textContent = '×';
@ -855,6 +855,117 @@
}
});
// ==========================================
// AMBIENT BODY DOUBLING (Feature C)
// ==========================================
var pill = $('#ambient-pill');
var panel = $('#ambient-panel');
var countEl = $('#pill-count');
var feedEl = $('#ambient-feed');
var cheerBtn = $('#ambient-cheer-btn');
var fakeBaseCount = 1400; // baseline
var feedEvents = [
"Someone just finished a 15m focus round",
"Someone broke down an intimidating task",
"Someone took a mindful breath",
"Someone swept their inbox clean",
"Someone just started a timer",
"Someone released a stale task to the universe",
"Someone decided to focus on just One Thing"
];
function getCircadianOffset() {
// Generate a smooth hour-based wave offset so the fake count feels organic
var hour = new Date().getHours();
var minute = new Date().getMinutes();
var time = hour + (minute/60);
// peak at noon and 8pm roughly
return Math.floor((Math.sin(time * 0.5) * 300) + (Math.cos(time * 0.8) * 150));
}
function updateCount() {
if (!countEl) return;
var base = fakeBaseCount + getCircadianOffset();
// small jitter
var jitter = Math.floor(Math.random() * 15) - 7;
var finalCount = base + jitter;
if (finalCount < 200) finalCount = 200; // min floor
countEl.textContent = finalCount.toLocaleString();
}
function addFeedItem(text) {
if (!feedEl) return;
var li = document.createElement('li');
li.className = 'feed-item';
li.textContent = text;
feedEl.prepend(li);
// keep only top 4
if (feedEl.children.length > 4) {
feedEl.removeChild(feedEl.lastChild);
}
}
function feedLoop() {
// random feed inject every 8-25 seconds
var delay = 8000 + Math.random() * 17000;
setTimeout(function() {
var evt = feedEvents[Math.floor(Math.random() * feedEvents.length)];
addFeedItem(evt);
updateCount();
feedLoop();
}, delay);
}
if (pill) {
updateCount();
addFeedItem("You joined the focus room");
feedLoop();
// click to toggle panel
pill.addEventListener('click', function(e) {
e.stopPropagation();
var expanded = pill.getAttribute('aria-expanded') === 'true';
pill.setAttribute('aria-expanded', !expanded);
panel.hidden = expanded;
});
// click outside to close
document.addEventListener('click', function(e) {
if (!panel.hidden && !panel.contains(e.target) && !pill.contains(e.target)) {
panel.hidden = true;
pill.setAttribute('aria-expanded', 'false');
}
});
pill.addEventListener('keydown', function(e) {
if (e.key === 'Enter' || e.key === ' ') {
e.preventDefault();
pill.click();
}
});
}
if (cheerBtn) {
cheerBtn.addEventListener('click', function() {
addFeedItem("You sent a quiet cheer 🎉");
cheerBtn.textContent = "Sent!";
cheerBtn.style.pointerEvents = "none";
setTimeout(function() {
cheerBtn.textContent = "Send a quiet cheer 🎉";
cheerBtn.style.pointerEvents = "auto";
}, 3000);
party.confetti(cheerBtn, { count: 15, spread: 30 });
});
cheerBtn.addEventListener('keydown', function(e) {
if (e.key === 'Enter' || e.key === ' ') {
e.preventDefault();
cheerBtn.click();
}
});
}
})();
@ -894,13 +1005,13 @@
if(!text) return;
clearInterval(breathInterval);
let cycle = 0;
// Physiological Sigh timing matcher (approximate for the 8s CSS animation)
// 0-2s: Inhale
// 2-3.5s: 2nd Inhale
// 3.5-4s: Hold
// 4-8s: Long slow exhale
const updateText = () => {
cycle = (cycle + 1) % 8;
if (cycle < 2) text.textContent = "Inhale...";
@ -908,12 +1019,12 @@
else if (cycle < 4) text.textContent = "Hold...";
else text.textContent = "Slooow Exhale...";
};
updateText(); // immediate run
breathInterval = setInterval(() => {
if (modal.hidden || p1.hidden) {
clearInterval(breathInterval);
return;
if (modal.hidden || p1.hidden) {
clearInterval(breathInterval);
return;
}
updateText();
}, 1000);
@ -933,13 +1044,13 @@
// Proceed from phase 1 to 2
$('#unstuck-next-1').addEventListener('click', () => {
p1.hidden = true;
p1.hidden = true;
p2.hidden = false;
});
// Proceed from phase 2 to 3
$('#unstuck-next-2').addEventListener('click', () => {
p2.hidden = true;
p2.hidden = true;
p3.hidden = false;
});
@ -947,18 +1058,18 @@
startTimerBtn.addEventListener('click', () => {
startTimerBtn.hidden = true;
let timeLeft = 180; // 3 minutes
unstuckInterval = setInterval(() => {
timeLeft--;
const m = Math.floor(timeLeft / 60).toString().padStart(2, '0');
const s = (timeLeft % 60).toString().padStart(2, '0');
timerDisplay.textContent = `${m}:${s}`;
if (timeLeft <= 0) {
clearInterval(unstuckInterval);
timerDisplay.textContent = "Done!";
finishBtn.hidden = false;
// Play success tone if soundscapes/audio is available globally
try {
if (window.AudioContext && !window.audioCtx) {
@ -989,4 +1100,115 @@
if(timerTabBtn) timerTabBtn.click();
});
// ==========================================
// AMBIENT BODY DOUBLING (Feature C)
// ==========================================
var pill = $('#ambient-pill');
var panel = $('#ambient-panel');
var countEl = $('#pill-count');
var feedEl = $('#ambient-feed');
var cheerBtn = $('#ambient-cheer-btn');
var fakeBaseCount = 1400; // baseline
var feedEvents = [
"Someone just finished a 15m focus round",
"Someone broke down an intimidating task",
"Someone took a mindful breath",
"Someone swept their inbox clean",
"Someone just started a timer",
"Someone released a stale task to the universe",
"Someone decided to focus on just One Thing"
];
function getCircadianOffset() {
// Generate a smooth hour-based wave offset so the fake count feels organic
var hour = new Date().getHours();
var minute = new Date().getMinutes();
var time = hour + (minute/60);
// peak at noon and 8pm roughly
return Math.floor((Math.sin(time * 0.5) * 300) + (Math.cos(time * 0.8) * 150));
}
function updateCount() {
if (!countEl) return;
var base = fakeBaseCount + getCircadianOffset();
// small jitter
var jitter = Math.floor(Math.random() * 15) - 7;
var finalCount = base + jitter;
if (finalCount < 200) finalCount = 200; // min floor
countEl.textContent = finalCount.toLocaleString();
}
function addFeedItem(text) {
if (!feedEl) return;
var li = document.createElement('li');
li.className = 'feed-item';
li.textContent = text;
feedEl.prepend(li);
// keep only top 4
if (feedEl.children.length > 4) {
feedEl.removeChild(feedEl.lastChild);
}
}
function feedLoop() {
// random feed inject every 8-25 seconds
var delay = 8000 + Math.random() * 17000;
setTimeout(function() {
var evt = feedEvents[Math.floor(Math.random() * feedEvents.length)];
addFeedItem(evt);
updateCount();
feedLoop();
}, delay);
}
if (pill) {
updateCount();
addFeedItem("You joined the focus room");
feedLoop();
// click to toggle panel
pill.addEventListener('click', function(e) {
e.stopPropagation();
var expanded = pill.getAttribute('aria-expanded') === 'true';
pill.setAttribute('aria-expanded', !expanded);
panel.hidden = expanded;
});
// click outside to close
document.addEventListener('click', function(e) {
if (!panel.hidden && !panel.contains(e.target) && !pill.contains(e.target)) {
panel.hidden = true;
pill.setAttribute('aria-expanded', 'false');
}
});
pill.addEventListener('keydown', function(e) {
if (e.key === 'Enter' || e.key === ' ') {
e.preventDefault();
pill.click();
}
});
}
if (cheerBtn) {
cheerBtn.addEventListener('click', function() {
addFeedItem("You sent a quiet cheer 🎉");
cheerBtn.textContent = "Sent!";
cheerBtn.style.pointerEvents = "none";
setTimeout(function() {
cheerBtn.textContent = "Send a quiet cheer 🎉";
cheerBtn.style.pointerEvents = "auto";
}, 3000);
party.confetti(cheerBtn, { count: 15, spread: 30 });
});
cheerBtn.addEventListener('keydown', function(e) {
if (e.key === 'Enter' || e.key === ' ') {
e.preventDefault();
cheerBtn.click();
}
});
}
})();

View file

@ -381,3 +381,127 @@ input[type="text"]:focus-visible { outline: 2px solid var(--accent); outline-off
0% { fill: #d97706; }
100% { fill: #f59e0b; }
}
/* Ambient Doubling */
.ambient-pill {
position: absolute;
right: var(--spacing);
top: 50%;
transform: translateY(-50%);
background: var(--surface0);
border: 1px solid var(--surface1);
padding: 4px 12px;
border-radius: 20px;
font-size: 0.85rem;
font-weight: 500;
color: var(--text-muted);
cursor: pointer;
display: flex;
align-items: center;
gap: 6px;
box-shadow: 0 2px 4px rgba(0,0,0,0.2);
transition: all 0.2s;
user-select: none;
}
.ambient-pill:hover, .ambient-pill:focus-visible {
background: var(--surface1);
color: var(--text-main);
}
.pill-dot {
font-size: 0.6rem;
animation: slow-pulse 4s ease-in-out infinite alternate;
}
@keyframes slow-pulse {
0% { opacity: 0.4; }
100% { opacity: 1; }
}
.ambient-panel {
position: absolute;
right: var(--spacing);
top: calc(100% + 4px);
width: 320px;
background: var(--surface0);
border: 1px solid var(--surface1);
border-radius: 12px;
padding: 16px;
box-shadow: 0 8px 24px rgba(0,0,0,0.4);
z-index: 100;
display: flex;
flex-direction: column;
gap: 12px;
}
.ambient-panel[hidden] {
display: none !important;
}
.ambient-panel-head {
font-size: 0.9rem;
color: var(--text-muted);
line-height: 1.4;
margin: 0;
padding-bottom: 8px;
border-bottom: 1px solid var(--surface1);
}
.ambient-feed {
list-style: none;
padding: 0;
margin: 0;
display: flex;
flex-direction: column;
gap: 8px;
max-height: 150px;
overflow: hidden;
position: relative;
}
.ambient-feed::after {
content: "";
position: absolute;
bottom: 0; left: 0; right: 0;
height: 40px;
background: linear-gradient(transparent, var(--surface0));
pointer-events: none;
}
.feed-item {
font-size: 0.85rem;
color: var(--text-main);
animation: slide-down 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275) forwards;
opacity: 0;
transform: translateY(-10px);
}
@keyframes slide-down {
to { transform: translateY(0); opacity: 1; }
}
.ambient-cheer {
margin-top: 4px;
background: var(--surface1);
border: 1px solid var(--surface2);
border-radius: 8px;
padding: 10px;
text-align: center;
font-size: 0.9rem;
font-weight: 500;
cursor: pointer;
transition: all 0.2s;
user-select: none;
}
.ambient-cheer:hover, .ambient-cheer:focus-visible {
background: var(--accent);
color: var(--bg);
border-color: var(--accent);
}
.ambient-cheer:active {
transform: scale(0.97);
}
@media (max-width: 900px) {
.ambient-pill {
position: static;
transform: none;
margin-left: auto;
}
.top {
flex-wrap: wrap;
gap: 12px;
}
}