garage44.eu/jeroen/midas

logclone: git clone https://garage44.eu/jeroen/midas.git

.. /web/src/components/activity.tsx

raw

import m, {MithrilComponent} from '@garage44/mithril'
import {FieldSegmented} from '@garage44/mithril/components'

import {History} from '@/components/history'
import {Log} from '@/components/log'
import {go, here} from '@/lib/route'

/** Which half is open: the address says (`/activity/events`, or the old `/log`). */
const half = () => (/^(log|activity\/events)$/.test(here()) ? 'events' : 'stats')

/**
 * How the work flows, in one place: the numbers and charts (once History) and
 * what happened, line by line (once Log). Both are for looking back; neither is
 * where anything waits for the person.
 */
export class Activity extends MithrilComponent {
    which = {
        get value() {
            return half()
        },
        set value(v: string) {
            go(v === 'events' ? 'activity/events' : 'activity')
        },
    }

    view() {
        return (
            <div class="stack">
                <FieldSegmented
                    model={this.which}
                    size="sm"
                    options={[
                        {value: 'stats', label: 'How it flows'},
                        {value: 'events', label: 'What happened'},
                    ]}
                />
                {half() === 'events' ? <Log /> : <History />}
            </div>
        )
    }
}