Repository navigation
feat(kin): Docs gets a Map view of what is being worked on, on web and phone #496
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
21 commits
Select commit
Hold shift + click to select a range
7387347
feat(kin): canvas contract
Surajsm60720 01a6cc9
feat(kin): shared canvas model, layout, lens and live stream
Surajsm60720 ce993ab
feat(kin): canvas on web and desktop
Surajsm60720 511f311
feat(kin): canvas in the feature map
Surajsm60720 e0f657f
feat(kin): canvas server: places, widgets, since and agent activity
Surajsm60720 2f21335
feat(mobile): Kin canvas on iOS and Android
Surajsm60720 bc8ace5
fix(kin): the pushed canvas page in the feature map
Surajsm60720 a56317c
fix(kin): canvas fixes from the first web pass
Surajsm60720 ba47e0c
fix(kin): canvas fixes from review and the phone pass
Surajsm60720 88f4e82
fix(kin): a first drag pins every card, and countdowns open their source
Surajsm60720 1396a5e
Merge origin/kin into t3/kin-canvas
Surajsm60720 89e9d00
refactor(kin): the canvas reads only what Work and Docs already send
Surajsm60720 70f14fd
feat(kin): Docs has a Map view of what is being worked on, on web and…
Surajsm60720 2d76917
fix(kin): map copy in one place, camera helpers kept private
Surajsm60720 8af4529
fix(kin): the Docs map keeps its cards while it reloads and says what…
Surajsm60720 0d81c3b
fix(kin): the Docs map stays smooth and legible with hundreds of cards
Surajsm60720 f2e1a71
Merge origin/kin into t3/kin-canvas
Surajsm60720 339f3a2
fix(kin): the Docs map reads tasks through runKinCommand
Surajsm60720 04f1ce0
fix(kin): a double tap on a map card no longer zooms past its peek
Surajsm60720 20bd58a
Merge origin/kin into t3/kin-canvas
Surajsm60720 f45abe1
fix(kin): web Back returns the Docs map to the same spot and zoom
Surajsm60720 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,238 @@ | ||
| import { kinCanvasFit, type KinCanvasCamera } from "@t3tools/client-runtime/kin/kinCanvasCamera"; | ||
| import { kinCanvasLayout } from "@t3tools/client-runtime/kin/kinCanvasLayout"; | ||
| import { | ||
| KIN_CANVAS, | ||
| kinCanvasHeadline, | ||
| type KinCanvasCardView, | ||
| } from "@t3tools/client-runtime/kin/kinCanvasView"; | ||
| import { KIN_RETRY } from "@t3tools/client-runtime/kin/kinAnswers"; | ||
| import { KIN_WORK_HOME } from "@t3tools/client-runtime/kin/kinWorkHome"; | ||
| import { useEffect, useState } from "react"; | ||
| import { View } from "react-native"; | ||
| import { useSafeAreaInsets } from "react-native-safe-area-context"; | ||
|
|
||
| import { AppBar } from "../../components/ui/AppBar"; | ||
| import { AppText as Text } from "../../components/ui/AppText"; | ||
| import { Button } from "../../components/ui/Button"; | ||
| import { EmptyState } from "../../components/ui/EmptyState"; | ||
| import { useBarOverlap } from "../../components/ui/useBarInset"; | ||
| import { useReduceMotionEnabled } from "../../lib/appState"; | ||
| import { KinCanvasBoard } from "./canvas/KinCanvasBoard"; | ||
| import { | ||
| KinCanvasPartial, | ||
| KinCanvasShowSwitch, | ||
| KinCanvasZoomControls, | ||
| } from "./canvas/KinCanvasOverlays"; | ||
| import { KinCanvasPeek } from "./canvas/KinCanvasPeek"; | ||
| import { useCanvasCamera } from "./canvas/useCanvasCamera"; | ||
| import { KinWorkLoading } from "./components/KinWorkPieces"; | ||
| import { useKinTab } from "./components/KinTab"; | ||
| import { useKinWorkLink } from "./state/kinWorkLink"; | ||
| import { useKinCanvas } from "./state/useKinCanvas"; | ||
| import type { KinWorkTarget } from "./state/useKinWork"; | ||
|
|
||
| /** The bar's switch between Docs' two views. */ | ||
| export function kinDocsViewAction(view: "list" | "map", onPress: () => void) { | ||
| return view === "list" | ||
| ? { accessibilityLabel: `Show ${KIN_CANVAS.title}`, icon: "map" as const, onPress } | ||
| : { accessibilityLabel: `Show ${KIN_CANVAS.list}`, icon: "list.bullet" as const, onPress }; | ||
| } | ||
|
|
||
| /** | ||
| * Docs as a map: every project an area with its tasks in progress and its docs, zoomed like a | ||
| * map. Close in, a doc shows its text on the card; a tap reads it over the map. | ||
| */ | ||
| export function KinDocsMap(props: KinWorkTarget & { readonly onList: () => void }) { | ||
| const target = { environmentId: props.environmentId, orgId: props.orgId }; | ||
| const data = useKinCanvas(target); | ||
| const tab = useKinTab(); | ||
| const bar = ( | ||
| <AppBar title={KIN_WORK_HOME.places.docs} actions={[kinDocsViewAction("map", props.onList)]} /> | ||
| ); | ||
| const message = (body: React.ReactNode) => ( | ||
| <View collapsable={false} className="flex-1 bg-screen"> | ||
| {bar} | ||
| <View | ||
| className="flex-1 justify-center p-4" | ||
| style={{ paddingBottom: tab?.bottomClearance ?? 0 }} | ||
| > | ||
| {body} | ||
| </View> | ||
| </View> | ||
| ); | ||
| if (data.status === "offline") | ||
| return message( | ||
| <EmptyState | ||
| variant="plain" | ||
| title={KIN_CANVAS.offlineTitle} | ||
| detail={KIN_CANVAS.offlineDetail} | ||
| />, | ||
| ); | ||
| if (data.status === "refused") | ||
| return message( | ||
| <EmptyState | ||
| variant="plain" | ||
| title={KIN_CANVAS.refusedTitle} | ||
| detail={KIN_CANVAS.refusedDetail} | ||
| />, | ||
| ); | ||
| if (data.status === "failed") | ||
| return message( | ||
| <EmptyState | ||
| variant="plain" | ||
| title={KIN_CANVAS.loadFailed} | ||
| detail={KIN_CANVAS.loadFailedDetail} | ||
| action={<Button tone="secondary" label={KIN_RETRY} onPress={data.retry} />} | ||
| />, | ||
| ); | ||
| if (data.status === "loading") return message(<KinWorkLoading label={KIN_CANVAS.loading} />); | ||
| return <KinDocsMapReady {...target} data={data} bar={bar} />; | ||
| } | ||
|
|
||
| function KinDocsMapReady( | ||
| props: KinWorkTarget & { | ||
| readonly data: ReturnType<typeof useKinCanvas>; | ||
| readonly bar: React.ReactNode; | ||
| }, | ||
| ) { | ||
| const { data, environmentId, orgId } = props; | ||
| const target = { environmentId, orgId }; | ||
| const tab = useKinTab(); | ||
| const insets = useSafeAreaInsets(); | ||
| const barOverlap = useBarOverlap(); | ||
| const reduceMotion = useReduceMotionEnabled(); | ||
| const openLink = useKinWorkLink(); | ||
| const [peek, setPeek] = useState<KinCanvasCardView | null>(null); | ||
| const [heading, setHeading] = useState<KinCanvasCamera | null>(null); | ||
| const camera = useCanvasCamera(`${environmentId}:${orgId}:docs`, reduceMotion, () => | ||
| setHeading(null), | ||
| ); | ||
| const layout = kinCanvasLayout({ | ||
| groups: data.model.groups, | ||
| items: data.model.items, | ||
| aspect: 0.7, | ||
| }); | ||
|
|
||
| // The map starts below the bar, not under it: a moving map behind the title can't be read. | ||
| const top = 8; | ||
| const bottom = (tab?.bottomClearance ?? insets.bottom) + 12; | ||
| // The switch above and the controls below cover the board's edges; fits keep cards clear of them. | ||
| const free = { top: top + 48, right: 0, bottom: bottom + 64, left: 0 }; | ||
|
|
||
| const fly = (to: KinCanvasCamera) => { | ||
| setHeading(to); | ||
| camera.flyTo(to); | ||
| }; | ||
| const fitAll = (instant = false, measured?: { readonly w: number; readonly h: number }) => { | ||
| const to = kinCanvasFit( | ||
| layout.bounds, | ||
| measured?.w ?? camera.width.get(), | ||
| measured?.h ?? camera.height.get(), | ||
| free, | ||
| 16, | ||
| ); | ||
| if (instant) camera.set(to); | ||
| else fly(to); | ||
| }; | ||
|
|
||
| const { x: bx, y: by, w: bw, h: bh } = layout.bounds; | ||
| /* oxlint-disable react/exhaustive-effect-dependencies, react/set-state-in-effect -- only a change of | ||
| extent refits; the camera, which lives outside React, and the insets are read as they are then */ | ||
| // oxlint-disable-next-line t3code/no-unreasoned-state-sync -- refits the camera to the map as its extent changes, until the person moves it | ||
| useEffect(() => { | ||
| if (camera.moved() || camera.width.get() === 0) return; | ||
| fitAll(true); | ||
| }, [bx, by, bw, bh]); | ||
| /* oxlint-enable react/exhaustive-effect-dependencies, react/set-state-in-effect */ | ||
|
|
||
| /** Bring a card to the strip of map the peek sheet leaves showing, at a size to read its title. */ | ||
| const reveal = (card: KinCanvasCardView) => { | ||
| const box = layout.cards.get(card.key); | ||
| if (box === undefined) return; | ||
| const scale = Math.min(Math.max(camera.scale.get(), 0.9), 1.2); | ||
| const height = camera.height.get(); | ||
| const visibleMiddle = height * 0.25; | ||
| fly({ | ||
| x: box.x + box.w / 2, | ||
| y: box.y + box.h / 2 + (height / 2 - visibleMiddle) / scale, | ||
| scale, | ||
| }); | ||
| }; | ||
| const open = (card: KinCanvasCardView) => { | ||
| setPeek(null); | ||
| const base = { environmentId: String(environmentId), orgId: String(orgId) }; | ||
| if (card.kind === "doc") openLink("KinDoc", { ...base, doc: card.key }); | ||
| else openLink("KinWorkItem", { ...base, task: card.key }); | ||
| }; | ||
|
|
||
| const empty = data.model.cards.size === 0; | ||
| const headline = kinCanvasHeadline(data.model); | ||
| return ( | ||
| <View collapsable={false} className="flex-1 bg-screen"> | ||
| {props.bar} | ||
| <View className="flex-1" style={{ marginTop: barOverlap }}> | ||
| <KinCanvasBoard | ||
| target={target} | ||
| camera={camera} | ||
| layout={layout} | ||
| model={data.model} | ||
| heading={heading} | ||
| peek={peek?.key ?? null} | ||
| onCard={(key) => { | ||
| const card = data.model.cards.get(key); | ||
| if (card === undefined) return; | ||
| setPeek(card); | ||
| reveal(card); | ||
| }} | ||
| onSized={(size) => { | ||
| if (camera.held) camera.settled(); | ||
| else fitAll(true, size); | ||
| }} | ||
| > | ||
| <View | ||
| pointerEvents="box-none" | ||
| className="absolute inset-x-0 items-center gap-2 px-3" | ||
| style={{ top }} | ||
| > | ||
| {data.tasks ? <KinCanvasShowSwitch show={data.view} onShow={data.setView} /> : null} | ||
| {headline === "" ? null : ( | ||
| <View className="rounded-full bg-card/90 px-3 py-1"> | ||
| <Text textRole="caption" className="text-foreground-muted"> | ||
| {headline} | ||
| </Text> | ||
| </View> | ||
| )} | ||
| </View> | ||
| {empty ? ( | ||
| <View pointerEvents="none" className="absolute inset-0 justify-center px-8"> | ||
| <EmptyState | ||
| variant="plain" | ||
| title={data.view === "doing" ? KIN_CANVAS.empty : KIN_CANVAS.emptyOpen} | ||
| detail={KIN_CANVAS.emptyDetail} | ||
| /> | ||
| </View> | ||
| ) : null} | ||
| <View | ||
| pointerEvents="box-none" | ||
| className="absolute inset-x-0 flex-row items-end justify-between gap-2 px-3" | ||
| style={{ bottom }} | ||
| > | ||
| <View className="min-w-0 shrink"> | ||
| <KinCanvasPartial lines={data.partial} onRetry={data.failed ? data.retry : null} /> | ||
| </View> | ||
| {empty ? null : ( | ||
| <KinCanvasZoomControls | ||
| onZoomOut={() => camera.zoomBy(0.7)} | ||
| onZoomIn={() => camera.zoomBy(1.4)} | ||
| onShowAll={() => fitAll()} | ||
| /> | ||
| )} | ||
| </View> | ||
| </KinCanvasBoard> | ||
| </View> | ||
| {peek !== null ? ( | ||
| <KinCanvasPeek target={target} card={peek} onClose={() => setPeek(null)} onOpen={open} /> | ||
| ) : null} | ||
| </View> | ||
| ); | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.