Scratch space for learning atproto app development
1import { AtUri } from '@atproto/syntax' 2import type { Status } from '#/db/schema' 3import { html } from '../view' 4import { shell } from './shell' 5 6const STATUS_OPTIONS = [ 7 '👍', 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> 39 profile?: { displayName?: string; handle: string } 40} 41 42export function home(props: Props) { 43 return shell({ 44 title: 'Home', 45 content: content(props), 46 }) 47} 48 49function content({ statuses, didHandleMap, profile }: Props) { 50 return html`<div id="root"> 51 <div class="error"></div> 52 <div id="header"> 53 <h1>Statusphere</h1> 54 <p>Set your status on the Atmosphere.</p> 55 </div> 56 <div class="container"> 57 <div class="card"> 58 ${profile 59 ? html`<form action="/logout" method="post" class="session-form"> 60 <div> 61 Hi, <strong>${profile.displayName || profile.handle}</strong>. 62 what's your status today? 63 </div> 64 <div> 65 <button type="submit">Log out</button> 66 </div> 67 </form>` 68 : html`<div class="session-form"> 69 <div><a href="/login">Log in</a> to set your status!</div> 70 <div> 71 <a href="/login" class="button">Log in</a> 72 </div> 73 </div>`} 74 </div> 75 <div class="status-options"> 76 ${STATUS_OPTIONS.map( 77 (status) => 78 html`<div 79 class="status-option" 80 data-value="${status}" 81 data-authed=${profile ? '1' : '0'} 82 > 83 ${status} 84 </div>` 85 )} 86 </div> 87 ${statuses.map((status, i) => { 88 const handle = didHandleMap[status.authorDid] || status.authorDid 89 return html` 90 <div class=${i === 0 ? 'status-line no-line' : 'status-line'}> 91 <div> 92 <div class="status">${status.status}</div> 93 </div> 94 <div class="desc"> 95 <a class="author" href=${toBskyLink(handle)}>@${handle}</a> 96 is feeling ${status.status} on ${ts(status)} 97 </div> 98 </div> 99 ` 100 })} 101 </div> 102 <script src="/public/home.js"></script> 103 </div>` 104} 105 106function toBskyLink(did: string) { 107 return `https://bsky.app/profile/${did}` 108} 109 110function ts(status: Status) { 111 const indexedAt = new Date(status.indexedAt) 112 const updatedAt = new Date(status.updatedAt) 113 if (updatedAt > indexedAt) return updatedAt.toDateString() 114 return indexedAt.toDateString() 115}