|
| 1 | +<!-- |
| 2 | + @component The page for standard speakers list, consisting of: |
| 3 | + - A timer panel with a timer (delegate speaking time) |
| 4 | + - An editable speakers list |
| 5 | +--> |
| 6 | +<script lang="ts"> |
| 7 | + import { slide } from "svelte/transition"; |
| 8 | +
|
| 9 | + import TimerPanel from "$lib/components/motions/TimerPanel.svelte"; |
| 10 | + import SpeakerList from "$lib/components/SpeakerList.svelte"; |
| 11 | + import { getSessionContext } from "$lib/context/index.svelte"; |
| 12 | + import { Delegate, findDelegate } from "$lib/db/delegates"; |
| 13 | + import { db } from "$lib/db/index.svelte"; |
| 14 | + import type { SpeakerFA } from "$lib/types"; |
| 15 | + import { a11yLabel } from "$lib/util"; |
| 16 | + import { parseTime } from "$lib/util/time"; |
| 17 | + import MdiMinus from "~icons/mdi/minus"; |
| 18 | + import MdiThumbUp from "~icons/mdi/thumb-up"; |
| 19 | +
|
| 20 | + interface Props { |
| 21 | + delegates: Delegate[], |
| 22 | + order: SpeakerFA[], |
| 23 | + duration?: number |
| 24 | + } |
| 25 | + let { delegates, order = $bindable(), duration = $bindable(60) }: Props = $props(); |
| 26 | +
|
| 27 | + const sessionData = getSessionContext(); |
| 28 | + let timerPanel = $state<TimerPanel>(); |
| 29 | + let speakersList = $state<SpeakerList>(); |
| 30 | + let durInput: string = $state(""); |
| 31 | +
|
| 32 | + function reset() { |
| 33 | + timerPanel?.reset(); |
| 34 | + } |
| 35 | + function setDuration(e: SubmitEvent) { |
| 36 | + e.preventDefault(); |
| 37 | +
|
| 38 | + let secs = parseTime(durInput); |
| 39 | + if (typeof secs !== "undefined") { |
| 40 | + duration = secs; |
| 41 | + } |
| 42 | + durInput = ""; |
| 43 | + } |
| 44 | +
|
| 45 | + function invertFavor(s: SpeakerFA["stance"]) { |
| 46 | + return s !== "for" ? "for" : "against"; |
| 47 | + } |
| 48 | + function presetCls(s: SpeakerFA) { |
| 49 | + if (s.completed) return "preset-ui-depressed"; |
| 50 | +
|
| 51 | + if (s.stance === "for") return "preset-filled-success-200-800 hover:preset-filled-success-500"; |
| 52 | + if (s.stance === "against") return "preset-filled-error-200-800 hover:preset-filled-error-500"; |
| 53 | + return "preset-filled-surface-200-800 hover:preset-filled-surface-500"; |
| 54 | + } |
| 55 | + function rotateCls(stance: SpeakerFA["stance"]) { |
| 56 | + return ["transition-transform", stance !== "for" && "rotate-180"]; |
| 57 | + } |
| 58 | +
|
| 59 | + $effect(() => { |
| 60 | + sessionData.updateTabTitleExtras( |
| 61 | + timerPanel?.getRunState(0) ?? false, |
| 62 | + timerPanel?.secsRemaining(0) |
| 63 | + ); |
| 64 | + }); |
| 65 | +</script> |
| 66 | + |
| 67 | +<div class="flex flex-col lg:flex-row h-full gap-8 items-stretch"> |
| 68 | + <!-- |
| 69 | + Under mobile, the timer encompasses the whole page |
| 70 | + and the speakers list can be accessed by scrolling down. |
| 71 | +
|
| 72 | + Under desktop, both are on the same screen, |
| 73 | + with the left side being the timer and the right side being the speakers list. |
| 74 | + --> |
| 75 | + <!-- Left/Top --> |
| 76 | + <div class="flex flex-col grow shrink-0 basis-full lg:basis-auto"> |
| 77 | + <TimerPanel |
| 78 | + {delegates} |
| 79 | + {speakersList} |
| 80 | + durations={[duration]} |
| 81 | + onDurationUpdate={(_, d) => duration = d} |
| 82 | + bind:this={timerPanel} |
| 83 | + editable |
| 84 | + > |
| 85 | + {#snippet label(name)} |
| 86 | + {@const speaker: SpeakerFA | undefined = speakersList?.selectedSpeaker()} |
| 87 | + {#if speaker} |
| 88 | + <div class="flex items-center"> |
| 89 | + <h2 class="h2">{name}</h2> |
| 90 | + {#if speaker?.stance} |
| 91 | + <div transition:slide={{ duration: 150, axis: "x" }}> |
| 92 | + <MdiThumbUp class={["size-8 ml-3", rotateCls(speaker.stance)]} /> |
| 93 | + </div> |
| 94 | + {/if} |
| 95 | + </div> |
| 96 | + {/if} |
| 97 | + {/snippet} |
| 98 | + </TimerPanel> |
| 99 | + </div> |
| 100 | + <!-- Right/Bottom --> |
| 101 | + <div class="flex flex-col gap-4 h-full lg:overflow-hidden xl:min-w-100 lg:max-w-[33%]"> |
| 102 | + <!-- List --> |
| 103 | + <SpeakerList |
| 104 | + {delegates} |
| 105 | + bind:order |
| 106 | + bind:this={speakersList} |
| 107 | + onBeforeSpeakerUpdate={reset} |
| 108 | + onMarkComplete={(key, isRepeat) => { if (!isRepeat) db.updateDelegate(key, d => { d.stats.timesSpoken++; }) }} |
| 109 | + > |
| 110 | + {#snippet extra(speaker: SpeakerFA, index)} |
| 111 | + {@const speakerLabel = findDelegate(delegates, speaker.key)?.name ?? "unknown"} |
| 112 | + {@const invertedFavor = invertFavor(speaker.stance)} |
| 113 | + |
| 114 | + <button |
| 115 | + class={["btn-icon-std transition", presetCls(speaker)]} |
| 116 | + onclick={() => order[index].stance = invertedFavor} |
| 117 | + {...a11yLabel(`Set ${speakerLabel} to ${invertedFavor}`)} |
| 118 | + disabled={speaker.completed} |
| 119 | + > |
| 120 | + {#if speaker.stance} |
| 121 | + <MdiThumbUp class={rotateCls(speaker.stance)} /> |
| 122 | + {:else} |
| 123 | + <MdiMinus /> |
| 124 | + {/if} |
| 125 | + </button> |
| 126 | + {/snippet} |
| 127 | + </SpeakerList> |
| 128 | + <!-- Timer config --> |
| 129 | + <div class="flex flex-row gap-5"> |
| 130 | + <form class="contents" onsubmit={setDuration}> |
| 131 | + <label class="flex grow items-center"> |
| 132 | + <span>Speaker Time</span> |
| 133 | + <input class="input grow" bind:value={durInput} placeholder="mm:ss" disabled={timerPanel?.getRunState(0)} /> |
| 134 | + </label> |
| 135 | + </form> |
| 136 | + </div> |
| 137 | + </div> |
| 138 | +</div> |
0 commit comments