'use strict'; /* global $, S, store, plan, planTab, savePlan, loadPlan, renderPlan, planSlot, applyBrand, cleanErr, newPersona, cal, camp, results, CONTENT_TYPES, ymd, resetPlanLoaded, online, brandBasicsReady, aiOn, makePortraits, askCloudflare, DEMO_VERSION, demoPlan, marketFacts, offlineMarket, applyMarketDraft, view, showView, renderPlanChip */ // The plan's seven steps (the sidebar), a short guide per step (what, why, example, what to do, key words; folded by // default), checks that mark a step done, ✨ Draft with AI (Cloudflare, 70B), the coach (Check my work), and the demo. const words = t => String(t || '').trim().split(/\s+/).filter(Boolean).length; const STEPS = [ { id: 'brand', day: 1, title: 'Brand identity', tab: 'Brand', lesson: { what: 'Your brand is how people recognise you and how they feel about you: what you offer, why you exist, how you sound and how you look.', why: 'A clear brand makes every post feel like it comes from the same place, so people remember you.', example: 'Bean & Bloom · “Your daily cup of calm.” A warm corner where neighbours meet over great coffee and cakes baked every morning.', exercise: 'Fill in your brand and save your Brand Identity Summary.', terms: [['Mission', 'One sentence: who you serve, what you do and why.'], ['Tone of voice', 'How your brand sounds in writing, e.g. warm and chatty, or calm and expert.'], ['Tagline', 'A short line people remember: seven words or fewer.']] }, checks: () => { const b = plan.brand || {}; return [ ['Brand name and what you offer', !!(b.name && b.offer)], ['Mission of 10 to 45 words: who you help and what you do', words(b.mission) >= 10 && words(b.mission) <= 45], ['At least 3 values', String(b.values || '').split(',').filter(x => x.trim()).length >= 3], ['Personality: 1 to 3 picked', (b.personality || []).length >= 1], ['Tone of voice described', words(b.tone) >= 2], ['Tagline of 7 words or fewer', words(b.tagline) >= 2 && words(b.tagline) <= 8], ['Two or more brand colours', (b.colors || []).length >= 2], ]; } }, { id: 'personas', day: 1, title: 'Customer personas', tab: 'Personas', lesson: { what: 'A persona is a short, realistic picture of one typical customer: who they are, what they need, what annoys them and where they spend time online.', why: 'Writing for one real-feeling person makes posts more personal, and shows you which channels to use.', example: 'Sofia, 34, remote designer · needs a calm place to work for a few hours · dislikes noisy chains · finds places on Instagram and Google.', exercise: 'Create two personas and mark the main one. Give each a picture.', terms: [['Persona', 'A made-up but realistic customer that stands for a group of real ones.'], ['Pain point', 'A problem or frustration your customer has that you can solve.']] }, checks: () => { const ps = (plan.personas || []).filter(p => p.name); return [ ['Two personas', ps.length >= 2], ['Each has an age and a job or situation', ps.length >= 2 && ps.every(p => p.age && p.job)], ['Each has needs and frustrations', ps.length >= 2 && ps.every(p => words(p.needs) >= 4 && words(p.pains) >= 2)], ['Each says where they are online', ps.length >= 2 && ps.every(p => (p.where || []).length)], ['One is marked Main', ps.some(p => p.main)], ]; } }, { id: 'market', day: 1, title: 'Competitors and channels', tab: 'Competitors', lesson: { what: 'Look at two or three competitors, see what works for them, decide how you are different, and choose the places online where your brand will be.', why: 'Knowing the competition shows you what customers already like and where you can stand out; a presence map keeps you focused on the channels that reach your customers.', example: 'Bean & Bloom vs. the chain café nearby: they post discounts; we show the baking at 6 a.m. Channels: Instagram (daily life), Google Business profile (be found), Facebook (events).', exercise: 'Analyse two competitors, write how you are different, and fill in your digital presence map.', terms: [['Positioning', 'How a brand wants to be seen compared with others: cheaper, more premium, more local…'], ['Digital presence', 'All the places your brand can be found online: social media, website, Google, email.']] }, checks: () => { const m = plan.market || { competitors: [], presence: {} }, comps = (m.competitors || []).filter(c => c.name), used = Object.entries(m.presence || {}).filter(([, e]) => e.use); return [ ['Two competitors named', comps.length >= 2], ['What works for each of them', comps.length >= 2 && comps.every(c => words(c.works) >= 3)], ['How we are different (one or two sentences)', words(m.difference) >= 8], ['Two or more channels in the presence map', used.length >= 2], ['Each channel has a purpose', used.length >= 2 && used.every(([, e]) => words(e.purpose) >= 3)], ]; } }, { id: 'campaign', day: 2, title: 'Campaign and funnel', tab: 'Campaign', lesson: { what: 'A campaign is a set of posts with one goal, one message and a start and end date. The funnel shows how people move from first seeing you to buying.', why: 'One goal and one message keep your posts focused; the funnel makes sure you also plan the posts that bring sales.', example: 'Autumn Cake Week · goal: shop visits · “A new homemade cake every day this week.” · offer: free cake with your second coffee.', exercise: 'Name your campaign, choose a goal, write the key message, sketch the funnel and pick three success metrics with targets.', terms: [['Funnel', 'Awareness (they see you) → Engagement (they interact) → Conversion (they buy or visit).'], ['Value proposition', 'Why someone should choose you over others, in one line.'], ['Call to action', 'What you ask people to do next: Order now, Book a table…'], ['Metric', 'A number that shows success, like reach or engagement rate, with a target.']] }, checks: () => { const c = plan.campaign || {}; return [ ['Campaign name and goal', !!(c.name && c.goal)], ['Key message of 20 words or fewer', words(c.message) >= 3 && words(c.message) <= 20], ['Why choose us', words(c.value) >= 3], ['Call to action', !!c.cta], ['At least one channel', (c.channels || []).length > 0], ['All three funnel steps written', ['awareness', 'engagement', 'conversion'].every(k => words(((c.funnel || {})[k] || {}).what) >= 3)], ['Three metrics, each with a target', (c.metrics || []).length === 3 && c.metrics.every(m => +m.target > 0)], ]; } }, { id: 'calendar', day: 2, title: 'Content plan', tab: 'Content plan', lesson: { what: 'A good content plan mixes kinds of posts: educational, storytelling, behind the scenes, community and lifestyle, plus a few offers.', why: 'Variety keeps followers interested, and a calendar keeps you posting regularly instead of when you remember.', example: 'Monday: 3 quick tips · Wednesday: why we started · Friday: behind the scenes in the kitchen.', exercise: 'Write at least 10 content ideas, fill a 30-day calendar, make two posts and write their captions.', terms: [['Content mix', 'The share of each kind of post in your plan.'], ['Caption', 'The text under a post: a hook, a few lines, a call to action and hashtags.']] }, checks: () => { const k = plan.calendar || { ideas: [], days: {} }, d = Object.values(k.days || {}).filter(x => x.text); return [ ['10 or more content ideas', (k.ideas || []).length >= 10], ['4 or more kinds of content', new Set((k.ideas || []).map(i => i.type)).size >= 4], ['8 or more posts in the calendar', d.length >= 8], ['Content made for at least two days', d.filter(x => x.item).length >= 2], ['Captions written for at least two days', d.filter(x => Object.values(x.captions || {}).some(c => words(c) > 3)).length >= 2], ]; } }, { id: 'automate', day: 3, title: 'Campaigns', tab: 'Campaigns', lesson: { what: 'Automation lets a tool do a repeated task for you. n8n connects apps without code: here it logs every post in a Google Sheet, emails you a reminder on the morning of each post and posts on LinkedIn. Each month you send is a campaign: you can see it day by day, and delete a day or the whole month.', why: 'Small tasks done by hand every week add up. Automating them saves time and means a planned post is never forgotten.', example: 'Bean & Bloom sends its month to n8n on the 1st: 13 rows appear in the content sheet, and every posting day starts with an email that has the caption ready to copy.', exercise: 'Connect n8n, then Google Sheets and Gmail, send your month of posts, and check the sheet and a reminder. Then open the campaign below and look at its days.', terms: [['Automation', 'A task a tool does for you, the same way every time.'], ['Workflow', 'The steps n8n follows, drawn as connected boxes.'], ['Trigger', 'What starts a workflow: here, Ora sending posts to its link.'], ['Credential', 'Your sign-in to an app (Google, LinkedIn), saved inside n8n.']] }, checks: () => { const n = online.n8n || {}, a = n.accounts || {}, off = n.off || {}, k = plan.calendar || { days: {} }; return [ ['n8n connected', !!n.connected], ['Google Sheets connected in n8n', !!(a.sheets && a.sheets.ok && !off.sheets)], ['Gmail reminders connected in n8n', !!(a.gmail && a.gmail.ok && !off.gmail)], ['Your month sent to n8n', !!(plan.automate && plan.automate.sentAt)], ['Reminders set for upcoming posts', Object.values(k.days || {}).some(d => d.reminder)], ]; } }, { id: 'results', day: 3, title: 'Results', tab: 'Results', lesson: { what: 'Results show what worked. Reach is how many people saw a post; engagement rate is likes + comments + shares + saves, divided by reach.', why: 'Numbers tell you what to do more of, and what to drop, next month.', example: 'Reach 6,500 (target 5,000) · engagement rate 7.1% · storytelling posts work best.', exercise: 'Track the numbers of your posts and compare them with your three targets.', terms: [['Reach', 'How many different people saw a post.'], ['Impressions', 'How many times it was seen (one person can see it twice).'], ['Engagement rate', '(likes + comments + shares + saves) ÷ reach × 100.']] }, checks: () => { const rows = ((plan.results || {}).rows || []); return [ ['3 or more posts with their reach', rows.filter(r => +r.reach > 0).length >= 3], ['Interactions typed in (likes, comments…)', rows.filter(r => (+r.likes || 0) + (+r.comments || 0) > 0).length >= 3], ['Targets set in the campaign', ((plan.campaign || {}).metrics || []).some(m => +m.target > 0)], ]; } }, { id: 'present', day: 3, title: 'Presentation', tab: 'Presentation', lesson: { what: 'Bring everything together in a short presentation: brand, audience, campaign, content plan and results.', why: 'A short presentation is how you share the plan with your team, a client or investors, and get feedback.', example: 'Ten slides, five minutes: who we are, who we talk to, what we will post, how we will know it worked.', exercise: 'Make your presentation (PDF or PowerPoint) and share it.', terms: [] }, checks: () => [['Presenter name', !!plan.presentedBy], ['Presentation made', !!plan.presentedAt]] }, ]; const stepOf = id => STEPS.find(s => s.id === id) || STEPS[0]; const done = st => st.checks().every(c => c[1]); // --- steps list and lesson card ------------------------------------------------------------------------------------------ function renderCourseSteps() { const nav = $('planSteps'); nav.innerHTML = ''; nav.setAttribute('role', 'tablist'); for (const st of STEPS) { const ch = st.checks(), ok = ch.filter(c => c[1]).length; const b = document.createElement('button'); const on = view === 'plan' && planTab === st.id; b.type = 'button'; b.className = 'step'; b.setAttribute('role', 'tab'); b.setAttribute('aria-selected', String(on)); b.setAttribute('aria-current', String(on)); b.innerHTML = ''; b.querySelector('.step-n').textContent = ok === ch.length ? '✓' : String(STEPS.indexOf(st) + 1); b.querySelector('.step-n').classList.toggle('ok', ok === ch.length); b.querySelector('.step-n').classList.toggle('warn', ok < ch.length && showMissing.has(st.id)); b.querySelector('.step-t').textContent = st.tab || st.title; // the tooltip says what is still missing b.title = ok === ch.length ? `${st.title}: done` : `${st.title}: still missing ${ch.filter(c => !c[1]).map(c => c[0].charAt(0).toLowerCase() + c[0].slice(1)).join('; ')}`; b.addEventListener('click', () => goStep(st.id)); nav.appendChild(b); } const total = STEPS.length, fin = STEPS.filter(done).length; const p = document.createElement('div'); p.className = 'step-progress'; p.innerHTML = `${fin} of ${total} steps done`; p.querySelector('.bar span').style.width = `${fin / total * 100}%`; nav.appendChild(p); const i = STEPS.findIndex(s => s.id === planTab); $('planPrev').hidden = i <= 0; $('planNext').textContent = nextAnyway === planTab ? 'Go on anyway →' : i >= STEPS.length - 1 ? 'Finish' : `Next: ${STEPS[i + 1].title} →`; } // --- missing items, marked like a form: a red outline and a note on the fields a check still needs ------------------------ // for each check of a step (same order), the fields to mark when it is not met const personaCards = () => [...document.querySelectorAll('#personaGrid .persona')]; const compCards = () => [...document.querySelectorAll('#compList .comp')]; const TARGETS = { brand: [() => [!(plan.brand || {}).name && $('bName'), !(plan.brand || {}).offer && $('bOffer')], () => [$('bMission')], () => [$('bValues')], () => [$('bPersonality')], () => [$('bTone')], () => [$('bTagline')], () => [$('bColors')]], personas: [ () => [$('addPersona')], () => personaCards().flatMap((c, i) => { const p = plan.personas[i] || {}; return [!p.age && c.querySelector('[data-k=age]'), !p.job && c.querySelector('[data-k=job]')]; }), () => personaCards().flatMap((c, i) => { const p = plan.personas[i] || {}; return [words(p.needs) < 4 && c.querySelector('[data-k=needs]'), words(p.pains) < 2 && c.querySelector('[data-k=pains]')]; }), () => personaCards().map((c, i) => !((plan.personas[i] || {}).where || []).length && c.querySelector('[data-k=where]')), () => [personaCards()[0] && personaCards()[0].querySelector('input[type=radio]').closest('label')], ], market: [ () => compCards().slice(0, 2).map((c, i) => !((((plan.market || {}).competitors || [])[i] || {}).name) && c.querySelector('[data-k=name]')), () => compCards().map((c, i) => { const x = ((plan.market || {}).competitors || [])[i] || {}; return x.name && words(x.works) < 3 && c.querySelector('[data-k=works]'); }), () => [$('mDifference')], () => [$('presenceList')], () => [...document.querySelectorAll('#presenceList .pres:not(.off)')].map(r => words(r.querySelector('[data-k=purpose]').value) < 3 && r.querySelector('[data-k=purpose]')), ], campaign: [() => [$('cName')], () => [$('cMessage')], () => [$('cValue')], () => [$('cCta')], () => [$('cChannels')], () => [...document.querySelectorAll('#cFunnel textarea')].map(t => words(t.value) < 3 && t), () => [$('cMetrics')]], calendar: [() => [document.querySelector('.cal-ideas .idea-add')], () => [document.querySelector('.cal-ideas .idea-add')], () => [$('calGrid')], () => [$('calMakeAll')], () => [$('calGrid')]], automate: [() => [$('campList')], () => [$('campList')], () => [$('campList')], () => [$('campList')], () => [$('campList')]], results: [() => [document.querySelector('.rtable-wrap')], () => [document.querySelector('.rtable-wrap')], () => [$('rTiles')]], present: [() => [$('presentBy')], () => [$('presentMake')]], }; const showMissing = new Set(); // steps whose missing items are marked (after Next or Check my work) let nextAnyway = null; // the step where Next was pressed once with items missing function missingOf(st) { const t = TARGETS[st.id] || []; return st.checks().map(([label, ok], i) => ok ? null : { label, els: (t[i] ? t[i]() : []).filter(Boolean) }).filter(Boolean); } // marks the fields (one note per field, listing what it needs); scroll: move to the first one function markMissing(miss, scroll) { for (const el of document.querySelectorAll('.need, .need-el')) el.classList.remove('need', 'need-el'); for (const el of document.querySelectorAll('.need-note')) el.remove(); const byEl = new Map(); for (const m of miss) for (const el of m.els) byEl.set(el, [...(byEl.get(el) || []), m.label]); for (const [el, labels] of byEl) { const note = document.createElement('span'); note.className = 'need-note'; note.textContent = `Needed: ${labels.map(l => l.charAt(0).toLowerCase() + l.slice(1)).join('; ')}`; const field = el.closest('.field'); if (field) { field.classList.add('need'); field.appendChild(note); } else { el.classList.add('need-el'); el.after(note); } } const first = [...byEl.keys()][0]; if (scroll && first) { first.scrollIntoView({ behavior: 'smooth', block: 'center' }); if (/^(INPUT|TEXTAREA|SELECT)$/.test(first.tagName)) first.focus({ preventScroll: true }); } const n = miss.length; $('planNavNote').textContent = !n ? '' : `${n} thing${n > 1 ? 's' : ''} on this step ${n > 1 ? 'are' : 'is'} still missing (marked in red).${nextAnyway === planTab ? ' Fix them, or press Go on anyway.' : ''}`; } // after a change or a redraw: the marks follow the plan (fixed items lose their mark) function applyMissing() { if (!showMissing.has(planTab)) { $('planNavNote').textContent = ''; return; } const miss = missingOf(stepOf(planTab)); markMissing(miss, false); if (!miss.length) { showMissing.delete(planTab); if (nextAnyway === planTab) nextAnyway = null; renderCourseSteps(); } } function renderCourse() { renderCourseSteps(); const st = stepOf(planTab), L = st.lesson, open = store('ora.lessonOpen') === true, n = STEPS.indexOf(st) + 1; $('topKicker').textContent = `Step ${n} of ${STEPS.length} · Day ${st.day}`; $('topTitle').textContent = st.title; const card = $('lessonCard'); card.hidden = st.id === 'automate'; // Campaigns: only the sent campaigns, no lesson card card.innerHTML = `
Looking at your work…
'; const label = btn.textContent; btn.disabled = true; let ai = null; try { ai = await window.ora.planAi('coach', `Exercise: ${st.lesson.exercise}\nCriteria:\n${ch.map(c => `- ${c[0]}`).join('\n')}\n\nTheir work:\n${stepWork(st.id)}`); } catch { ai = null; } btn.disabled = false; btn.textContent = label; const ok = ch.filter(c => c[1]), miss = ch.filter(c => !c[1]); box.innerHTML = '${aiOn() ? 'The AI coach did not answer this time: press Check my work again in a moment for written feedback.' : 'Connect Cloudflare (free, in Settings › Accounts) for written feedback on your words.'}
`; fb.querySelector('p').textContent = !miss.length ? 'All checks passed: this step is done. Ask someone to read it with fresh eyes, then move on.' : `${ok.length} of ${ch.length} checks passed. Next: ${miss[0][0].charAt(0).toLowerCase()}${miss[0][0].slice(1)}.`; } box.appendChild(fb); renderCourseSteps(); box.scrollIntoView({ behavior: 'smooth', block: 'nearest' }); } // --- the demo: a finished plan for the café Bean & Bloom -------------------------------------------------------------------- async function openDemo() { $('demoOpen').disabled = true; $('demoOpen').textContent = 'Opening…'; try { const items = await window.ora.demoInstall(); S.pictures = (await window.ora.state()).pictures; store('ora.planSlot', 'demo'); const existing = await window.ora.planGet('demo'); if (!existing || existing.demoVersion !== DEMO_VERSION) await window.ora.planSet(await demoPlan(items), 'demo'); planReload(); } catch (e) { alert(`Could not open the demo: ${cleanErr(e)}`); } finally { $('demoOpen').disabled = false; $('demoOpen').textContent = 'Open the demo'; } } function closeDemo() { store('ora.planSlot', 'mine'); planReload(); applyBrand(); } function planReload() { resetPlanLoaded(); planTab = 'brand'; renderPlan(); renderDemoBar(); } function renderDemoBar() { const demo = planSlot() === 'demo'; $('demoTag').hidden = !demo; $('demoClose').hidden = !demo; $('demoOpen').hidden = demo; $('demoRemove').hidden = !demo; document.body.classList.toggle('is-demo', demo); if (typeof renderPlanChip === 'function') renderPlanChip(); } $('demoOpen').addEventListener('click', openDemo); $('demoClose').addEventListener('click', closeDemo); renderDemoBar();