Scratch space for learning atproto app development
1import type { Status } from '#/db' 2import { html } from '../lib/view' 3import { shell } from './shell' 4 5const TODAY = new Date().toDateString() 6 7export const STATUS_OPTIONS = [ 8 '👍', 9 '👎', 10 '💙', 11 '🥹', 12 '😧', 13 '🙃', 14 '😉', 15 '😎', 16 '🤓', 17 '🤨', 18 '🥳', 19 '😭', 20 '😤', 21 '🤯', 22 '🫡', 23 '💀', 24 '✊', 25 '🤘', 26 '👀', 27 '🧠', 28 '👩‍💻', 29 '🧑‍💻', 30 '🥷', 31 '🧌', 32 '🦋', 33 '🚀', 34] 35 36type Props = { 37 statuses: Status[] 38 didHandleMap: Record<string, string | undefined> 39 error?: string 40 profile?: { displayName?: string } 41 myStatus?: Status 42} 43 44export function home(props: Props) { 45 return shell({ 46 title: 'Home', 47 content: content(props), 48 }) 49} 50 51function content({ error, statuses, didHandleMap, profile, myStatus }: Props) { 52 return html`<div id="root"> 53 <div id="header"> 54 <h1>Statusphere</h1> 55 <p>Set your status on the Atmosphere.</p> 56 </div> 57 <div class="container"> 58 <div class="card"> 59 ${profile 60 ? html`<form action="/logout" method="post" class="session-form"> 61 <div> 62 Hi, <strong>${profile.displayName || 'friend'}</strong>. What's 63 your status today? 64 </div> 65 <div> 66 <button type="submit">Log out</button> 67 </div> 68 </form>` 69 : html`<div class="session-form"> 70 <div><a href="/login">Log in</a> to set your status!</div> 71 <div> 72 <a href="/login" class="button">Log in</a> 73 </div> 74 </div>`} 75 </div> 76 <form action="/status" method="post" class="status-options"> 77 ${STATUS_OPTIONS.map( 78 (status) => 79 html`<button 80 class=${myStatus?.status === status 81 ? 'status-option selected' 82 : 'status-option'} 83 name="status" 84 value="${status}" 85 > 86 ${status} 87 </button>`, 88 )} 89 </form> 90 ${error ? html`<div class="error">${error}</div>` : undefined} 91 ${statuses.map((status, i) => { 92 const handle = didHandleMap[status.authorDid] || status.authorDid 93 const date = ts(status) 94 return html` 95 <div class=${i === 0 ? 'status-line no-line' : 'status-line'}> 96 <div> 97 <div class="status">${status.status}</div> 98 </div> 99 <div class="desc"> 100 <a class="author" href=${toBskyLink(handle)}>@${handle}</a> 101 ${date === TODAY 102 ? `is feeling ${status.status} today` 103 : `was feeling ${status.status} on ${date}`} 104 </div> 105 </div> 106 ` 107 })} 108 </div> 109 </div>` 110} 111 112function toBskyLink(did: string) { 113 return `https://bsky.app/profile/${did}` 114} 115 116function ts(status: Status) { 117 const createdAt = new Date(status.createdAt) 118 const indexedAt = new Date(status.indexedAt) 119 if (createdAt < indexedAt) return createdAt.toDateString() 120 return indexedAt.toDateString() 121}