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 7const 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] 36 37type Props = { 38 statuses: Status[] 39 didHandleMap: Record<string, 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({ statuses, didHandleMap, profile, myStatus }: Props) { 52 return html`<div id="root"> 53 <div class="error"></div> 54 <div id="header"> 55 <h1>Statusphere</h1> 56 <p>Set your status on the Atmosphere.</p> 57 </div> 58 <div class="container"> 59 <div class="card"> 60 ${profile 61 ? html`<form action="/logout" method="post" class="session-form"> 62 <div> 63 Hi, <strong>${profile.displayName || 'friend'}</strong>. What's 64 your status today? 65 </div> 66 <div> 67 <button type="submit">Log out</button> 68 </div> 69 </form>` 70 : html`<div class="session-form"> 71 <div><a href="/login">Log in</a> to set your status!</div> 72 <div> 73 <a href="/login" class="button">Log in</a> 74 </div> 75 </div>`} 76 </div> 77 <form action="/status" method="post" class="status-options"> 78 ${STATUS_OPTIONS.map( 79 (status) => 80 html`<button 81 class=${myStatus?.status === status 82 ? 'status-option selected' 83 : 'status-option'} 84 name="status" 85 value="${status}" 86 > 87 ${status} 88 </button>` 89 )} 90 </form> 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 indexedAt = new Date(status.indexedAt) 118 const updatedAt = new Date(status.updatedAt) 119 if (updatedAt > indexedAt) return updatedAt.toDateString() 120 return indexedAt.toDateString() 121}