import m, {MithrilComponent} from '@garage44/mithril' import {Badge, Button, ButtonGroup, Card, FieldText} from '@garage44/mithril/components' import type {BuildingAddress, OwnedBuilding} from '@/types' import {$s} from '@/app' import {bind, local} from '@/lib/reactive' import {claimBuilding, releaseBuilding, searchBuildings} from '@/lib/signup' /** Where the floor-plan editor for one building lives. */ export function editorPath(building: Pick) { return `/building/${building.pand_id}?lat=${building.latitude}&lng=${building.longitude}` } /** * The game, opened over a place: the `/go?place=` link the app and the web * client both answer (`systems::place_link`), looking down at it from 45 m. */ export function gamePlaceUrl(lat: number, lng: number) { return `/go?place=${lat.toFixed(5)},${lng.toFixed(5)},45m,-50,0` } /** * A link out to the game, drawn as a library button. `Button` takes an `href` * but no `target`, and the game has to open beside this page rather than over a * floor plan that may hold unsaved work — so this is the `` with the * button's classes, not the component. */ export class GameLink extends MithrilComponent<{lat: number; lng: number}> { view({attrs}: m.Vnode<{lat: number; lng: number}>) { return ( View in the game ) } } /** * The buildings this account owns, and a way to claim another. * * The search is on a button and not on every keystroke. It reaches two public * registers that somebody else pays for, through a server that rate-limits it, * and "Grote Markt 1" typed at speed is fourteen queries for one answer. A * debounce would only make it four. */ export class BuildingPicker extends MithrilComponent { s = local({ busy: false, claiming: '', confirming: '', query: '', results: null as BuildingAddress[] | null, }) search = async (e: Event) => { e.preventDefault() const s = this.s if (s.busy || !s.query.trim()) { return } s.busy = true s.results = await searchBuildings(s.query) s.busy = false } take = async (address: BuildingAddress) => { const s = this.s s.claiming = address.nummeraanduiding_id const ok = await claimBuilding(address) s.claiming = '' if (ok) { s.results = null s.query = '' } } view() { const s = this.s const owned = $s.myBuildings const atLimit = $s.buildingLimit > 0 && owned.length >= $s.buildingLimit const results = s.results return (
{owned.length > 0 && ( Design lays out the floors, walls, doors and stairs inside the building. What you save is what everybody sees when they walk in — or tap the building in the game and choose Look inside.

} flush title="Your buildings" >
    {owned.map((building) => (
  • {building.address} {/* * Giving a building up is two presses: the first only * swaps the row's actions for a confirmation, because * a released building is anybody's to claim at once. */} {s.confirming === building.pand_id ? ( ) : ( )}
  • ))}
)} 0 ? 'Claim another building' : 'Claim a building'}>

Groningen only, for now — that's where the map has buildings. One owner per building, first come first served {$s.buildingLimit > 0 ? `, up to ${$s.buildingLimit} per account` : ''}. Type any address in it.

{atLimit ? (

You own as many buildings as an account may.

) : (
) } }