diff --git a/apps/mobile/src/components/ui/AppBar.tsx b/apps/mobile/src/components/ui/AppBar.tsx index f9372f6aa72b0..f9c47aa0b7dd7 100644 --- a/apps/mobile/src/components/ui/AppBar.tsx +++ b/apps/mobile/src/components/ui/AppBar.tsx @@ -215,7 +215,8 @@ export function AppBar(props: AppBarProps) { onCancelButtonPress: () => reportSearchText(""), }, } - : undefined), + : // Options merge: a bar without search on a screen that had one must clear it. + { headerSearchBarOptions: undefined }), }} /> {props.onClose ? ( diff --git a/apps/mobile/src/components/ui/AppSymbol.android.tsx b/apps/mobile/src/components/ui/AppSymbol.android.tsx index ef829fccc3de7..da04d035d65b7 100644 --- a/apps/mobile/src/components/ui/AppSymbol.android.tsx +++ b/apps/mobile/src/components/ui/AppSymbol.android.tsx @@ -95,6 +95,7 @@ import IconMicrophone from "@tabler/icons-react-native/IconMicrophone"; import IconLink from "@tabler/icons-react-native/IconLink"; import IconMail from "@tabler/icons-react-native/IconMail"; import IconList from "@tabler/icons-react-native/IconList"; +import IconMap from "@tabler/icons-react-native/IconMap"; import IconListNumbers from "@tabler/icons-react-native/IconListNumbers"; import IconMenu2 from "@tabler/icons-react-native/IconMenu2"; import IconMessageCircleQuestion from "@tabler/icons-react-native/IconMessageCircleQuestion"; @@ -248,6 +249,7 @@ const ANDROID_ICON_BY_SF_SYMBOL = { envelope: IconMail, phone: IconPhone, "list.bullet": IconList, + map: IconMap, "list.number": IconListNumbers, "line.3.horizontal": IconMenu2, "line.3.horizontal.decrease": IconFilter, diff --git a/apps/mobile/src/features/chats/KinDocsList.tsx b/apps/mobile/src/features/chats/KinDocsList.tsx index fd47847e1f39e..938ebb1fe6fdd 100644 --- a/apps/mobile/src/features/chats/KinDocsList.tsx +++ b/apps/mobile/src/features/chats/KinDocsList.tsx @@ -1,5 +1,6 @@ import type { KinViewerScope } from "@t3tools/client-runtime/kin/kinViewerScope"; import { kinNothingShown } from "@t3tools/client-runtime/kin/kinViewerScope"; +import { kinDocsViewAction } from "./KinDocsMap"; import { useKinViewerScope } from "./state/kinChatOnly"; import { KIN_MORE_FAILED, KIN_RETRY, kinFailureText } from "@t3tools/client-runtime/kin/kinAnswers"; import { LegendList } from "@legendapp/list/react-native"; @@ -508,6 +509,8 @@ export function KinDocsList( readonly live: KinWorkLive; readonly directory: KinWorkDirectory; readonly stale: boolean; + /** Shows Docs as the map instead; absent where the list stands alone. */ + readonly onMap?: () => void; }, ) { const navigation = useNavigation(); @@ -664,22 +667,23 @@ export function KinDocsList( agent.ask(kinWorkAskDraft("docs")), }, { accessibilityLabel: KIN_LISTS.ask, - icon: "plus", + icon: "plus" as const, onPress: () => agent.ask(KIN_LISTS.askMessage), }, - ], - })} + ]), + ]} {...(refused ? {} : { diff --git a/apps/mobile/src/features/chats/KinDocsMap.tsx b/apps/mobile/src/features/chats/KinDocsMap.tsx new file mode 100644 index 0000000000000..9eea8d2e2fbb4 --- /dev/null +++ b/apps/mobile/src/features/chats/KinDocsMap.tsx @@ -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 = ( + + ); + const message = (body: React.ReactNode) => ( + + {bar} + + {body} + + + ); + if (data.status === "offline") + return message( + , + ); + if (data.status === "refused") + return message( + , + ); + if (data.status === "failed") + return message( + } + />, + ); + if (data.status === "loading") return message(); + return ; +} + +function KinDocsMapReady( + props: KinWorkTarget & { + readonly data: ReturnType; + 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(null); + const [heading, setHeading] = useState(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 ( + + {props.bar} + + { + 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); + }} + > + + {data.tasks ? : null} + {headline === "" ? null : ( + + + {headline} + + + )} + + {empty ? ( + + + + ) : null} + + + + + {empty ? null : ( + camera.zoomBy(0.7)} + onZoomIn={() => camera.zoomBy(1.4)} + onShowAll={() => fitAll()} + /> + )} + + + + {peek !== null ? ( + setPeek(null)} onOpen={open} /> + ) : null} + + ); +} diff --git a/apps/mobile/src/features/chats/KinWorkScreen.tsx b/apps/mobile/src/features/chats/KinWorkScreen.tsx index f06030089a49f..d4aba80e16236 100644 --- a/apps/mobile/src/features/chats/KinWorkScreen.tsx +++ b/apps/mobile/src/features/chats/KinWorkScreen.tsx @@ -22,6 +22,8 @@ import type { KinWorkLive } from "@t3tools/client-runtime/kin/kinWorkStream"; import { EnvironmentId, KinOrgId, KinPersonId } from "@t3tools/contracts"; import * as Option from "effect/Option"; import * as Schema from "effect/Schema"; +import { Atom } from "effect/reactivity"; +import { useState } from "react"; import { View } from "react-native"; import { AppActivityIndicator } from "../../components/ui/AppActivityIndicator"; @@ -32,6 +34,7 @@ import { ScreenContent } from "../../components/ui/ScreenContent"; import { ScreenScrollView } from "../../components/ui/ScreenScrollView"; import { appAtomRegistry } from "../../state/atom-registry"; import { KinDocsList } from "./KinDocsList"; +import { KinDocsMap } from "./KinDocsMap"; import { KinTasksList } from "./KinTasksList"; import { KinClientsList } from "./KinWorkLists"; import { KinMoneyArea } from "./KinWorkMoney"; @@ -308,7 +311,8 @@ export function KinPlace( ); } - if (place.place === "docs") return ; + if (place.place === "docs") + return ; if (place.place === "clients") return ; if (place.place === "money") return ; return ( @@ -354,3 +358,27 @@ export function KinPlace( ); } + +/** Which of Docs' two views each company's Docs shows, kept while the app runs. */ +const kinDocsViewAtom = Atom.family((_company: string) => + Atom.make<"list" | "map">("list").pipe(Atom.keepAlive), +); + +/** Docs, as the list or as the map of what's being worked on; the bar switches between them. */ +function KinDocsPlace(props: React.ComponentProps) { + const held = kinDocsViewAtom(`${props.environmentId}:${props.orgId}`); + const [view, setView] = useState(() => appAtomRegistry.get(held)); + const choose = (next: "list" | "map") => { + appAtomRegistry.set(held, next); + setView(next); + }; + return view === "map" ? ( + choose("list")} + /> + ) : ( + choose("map")} /> + ); +} diff --git a/apps/mobile/src/features/chats/canvas/KinCanvasBoard.tsx b/apps/mobile/src/features/chats/canvas/KinCanvasBoard.tsx new file mode 100644 index 0000000000000..044141ec4815d --- /dev/null +++ b/apps/mobile/src/features/chats/canvas/KinCanvasBoard.tsx @@ -0,0 +1,276 @@ +import { + KIN_CANVAS_MIN_SCALE, + kinCanvasDetail, + kinCanvasVisible, + type KinCanvasCamera, + type KinCanvasDetail, +} from "@t3tools/client-runtime/kin/kinCanvasCamera"; +import { + kinCanvasOverlaps, + type KinCanvasLayout, +} from "@t3tools/client-runtime/kin/kinCanvasLayout"; +import { KIN_CANVAS, type KinCanvasModel } from "@t3tools/client-runtime/kin/kinCanvasView"; +import { useState, type ReactNode } from "react"; +import { View } from "react-native"; +import { + GestureDetector, + usePanGesture, + usePinchGesture, + useSimultaneousGestures, + useTapGesture, +} from "react-native-gesture-handler"; +import Animated, { + cancelAnimation, + runOnJS, + useAnimatedReaction, + useAnimatedStyle, +} from "react-native-reanimated"; + +import { AppText as Text } from "../../../components/ui/AppText"; +import { cn } from "../../../lib/cn"; +import type { KinWorkTarget } from "../state/useKinWork"; +import { KinCanvasCard, KIN_CANVAS_WORLD_HALF } from "./KinCanvasCard"; +import { detailBand, maxScale } from "./canvasZoom"; +import type { CanvasCamera } from "./useCanvasCamera"; + +/** Past this many cards, only those near the view are mounted. */ +const CULL_FROM = 60; +/** Docs read whole at the nearest zoom at once, nearest the middle first, as on web. */ +const NEAR_READS = 3; +const DETAILS: ReadonlyArray = ["dots", "titles", "cards", "near"]; + +export interface KinCanvasBoardProps { + readonly target: KinWorkTarget; + readonly camera: CanvasCamera; + readonly layout: KinCanvasLayout; + readonly model: KinCanvasModel; + /** Where a flight is headed: cards near it mount before the camera arrives. */ + readonly heading: KinCanvasCamera | null; + readonly peek: string | null; + readonly onCard: (key: string) => void; + /** The board has a size for the first time: place the camera. */ + readonly onSized: (size: { readonly w: number; readonly h: number }) => void; + readonly children?: ReactNode; +} + +export function KinCanvasBoard(props: KinCanvasBoardProps) { + const { camera, layout } = props; + const { x, y, scale, width, height } = camera; + const [size, setSize] = useState<{ readonly w: number; readonly h: number } | null>(null); + const [detail, setDetail] = useState(() => + kinCanvasDetail(camera.get().scale, width.get()), + ); + // Where the camera is, a step at a time: React re-culls as a pan crosses a quarter screen. + const [view, setView] = useState(null); + + // kinCanvasDetail's bands, worked out again on the UI thread; React hears only a change of band. + useAnimatedReaction( + () => { + return detailBand(scale.get(), width.get()); + }, + (band, previous) => { + if (band !== previous) runOnJS(setDetail)(DETAILS[band] ?? "cards"); + }, + ); + useAnimatedReaction( + () => { + const s = scale.get(); + const stepX = Math.max(1, width.get() / s / 4); + const stepY = Math.max(1, height.get() / s / 4); + return `${Math.round(x.get() / stepX)}:${Math.round(y.get() / stepY)}:${Math.round(Math.log2(s) * 2)}`; + }, + (cell, previous) => { + if (cell !== previous) runOnJS(setView)({ x: x.get(), y: y.get(), scale: scale.get() }); + }, + ); + + const { touched } = camera; + const stop = () => { + "worklet"; + cancelAnimation(x); + cancelAnimation(y); + cancelAnimation(scale); + }; + const pan = usePanGesture({ + averageTouches: true, + onActivate: () => stop(), + onUpdate: (event) => { + x.set(x.get() - event.changeX / scale.get()); + y.set(y.get() - event.changeY / scale.get()); + }, + onDeactivate: () => runOnJS(touched)(), + }); + const pinch = usePinchGesture({ + onActivate: () => stop(), + onUpdate: (event) => { + const s = scale.get(); + const next = Math.min( + maxScale(width.get()), + Math.max(KIN_CANVAS_MIN_SCALE, s * event.scaleChange), + ); + const fx = event.focalX - width.get() / 2; + const fy = event.focalY - height.get() / 2; + x.set(x.get() + fx / s - fx / next); + y.set(y.get() + fy / s - fy / next); + scale.set(next); + }, + onDeactivate: () => runOnJS(touched)(), + }); + const zoomIn = (sx: number, sy: number) => { + const s = camera.get(); + const fx = sx - width.get() / 2; + const fy = sy - height.get() / 2; + // The first tap of a double tap on a card already opened its peek; zooming too would pull it away. + const point = { x: s.x + fx / s.scale, y: s.y + fy / s.scale, w: 0, h: 0 }; + for (const box of layout.cards.values()) if (kinCanvasOverlaps(box, point)) return; + const next = Math.min(maxScale(width.get()), s.scale * 1.8); + camera.flyTo({ + x: s.x + fx / s.scale - fx / next, + y: s.y + fy / s.scale - fy / next, + scale: next, + }); + }; + const doubleTap = useTapGesture({ + numberOfTaps: 2, + onActivate: (event) => runOnJS(zoomIn)(event.x, event.y), + }); + const gestures = useSimultaneousGestures(pan, pinch, doubleTap); + + const world = useAnimatedStyle(() => ({ + transform: [ + { translateX: width.get() / 2 - x.get() * scale.get() }, + { translateY: height.get() / 2 - y.get() * scale.get() }, + { scale: scale.get() }, + ], + })); + + const at = view ?? camera.get(); + // Zoomed out, type is drawn larger so the names of things stay readable. + const inv = detail === "cards" || detail === "near" ? 1 : Math.min(3.2, 1 / at.scale); + const boxes = [...layout.cards.values()]; + const near = + boxes.length <= CULL_FROM || size === null + ? null + : [at, ...(props.heading === null ? [] : [props.heading])].map((one) => { + const seen = kinCanvasVisible(one, size.w, size.h); + return { x: seen.x - seen.w / 2, y: seen.y - seen.h / 2, w: seen.w * 2, h: seen.h * 2 }; + }); + const shown = + near === null ? boxes : boxes.filter((box) => near.some((n) => kinCanvasOverlaps(box, n))); + const groupOf = new Map(props.model.groups.map((group) => [group.key, group])); + const reading = new Set( + detail !== "near" + ? [] + : shown + .filter((box) => props.model.cards.get(box.key)?.kind === "doc") + .map((box) => ({ + key: box.key, + d: Math.hypot(box.x + box.w / 2 - at.x, box.y + box.h / 2 - at.y), + })) + .sort((a, b) => a.d - b.d) + .slice(0, NEAR_READS) + .map((doc) => doc.key), + ); + + return ( + { + const { width: w, height: h } = event.nativeEvent.layout; + width.set(w); + height.set(h); + if (w === 0) return; + setSize({ w, h }); + if (size === null) props.onSized({ w, h }); + }} + > + + + + {layout.groups.map((box) => { + const group = groupOf.get(box.key); + return ( + 0 + ? "border-primary/30 bg-primary/5" + : "border-border bg-screen/70", + )} + style={{ + left: box.x + KIN_CANVAS_WORLD_HALF, + top: box.y + KIN_CANVAS_WORLD_HALF, + width: box.w, + height: box.h, + }} + > + + + {box.title} + + {group?.line != null && inv === 1 ? ( + + {group.line} + + ) : null} + + + ); + })} + {shown.map((box) => { + const card = props.model.cards.get(box.key); + if (card === undefined) return null; + return ( + + ); + })} + + + + {props.children} + + ); +} diff --git a/apps/mobile/src/features/chats/canvas/KinCanvasCard.tsx b/apps/mobile/src/features/chats/canvas/KinCanvasCard.tsx new file mode 100644 index 0000000000000..bba93d1b2dc08 --- /dev/null +++ b/apps/mobile/src/features/chats/canvas/KinCanvasCard.tsx @@ -0,0 +1,216 @@ +import type { KinCanvasDetail } from "@t3tools/client-runtime/kin/kinCanvasCamera"; +import { KIN_CANVAS_CARD_H, KIN_CANVAS_CARD_W } from "@t3tools/client-runtime/kin/kinCanvasLayout"; +import { KIN_CANVAS, type KinCanvasCardView } from "@t3tools/client-runtime/kin/kinCanvasView"; +import type { KinRecordKey, KinRecordState } from "@t3tools/contracts"; +import { memo } from "react"; +import { Pressable, View } from "react-native"; + +import { AppText as Text } from "../../../components/ui/AppText"; +import { SymbolView } from "../../../components/ui/AppSymbol"; +import { cn } from "../../../lib/cn"; +import { KinWorkStateSymbol } from "../components/KinWorkStateSymbol"; +import { useKinDoc } from "../state/useKinDocs"; +import type { KinWorkTarget } from "../state/useKinWork"; + +/** Half the world view's side: it is centred on the canvas origin so cards far out still take touches. */ +export const KIN_CANVAS_WORLD_HALF = 20_000; + +const STATE_OF_TONE: Record = { + late: "open", + done: "done", + doing: "doing", + waiting: "waiting", + open: "open", + doc: null, +}; + +export interface KinCanvasCardProps { + readonly target: KinWorkTarget; + readonly x: number; + readonly y: number; + readonly card: KinCanvasCardView; + readonly detail: KinCanvasDetail; + /** How much larger type is drawn zoomed out, so titles stay readable. */ + readonly inv: number; + /** One of the few docs nearest the middle at the nearest zoom: its text is read onto the card. */ + readonly readsText: boolean; + readonly peeked: boolean; + readonly onPress: (key: string) => void; +} + +/** One card on the map, at its place in world units; the board's transform scales it. */ +export const KinCanvasCard = memo(function KinCanvasCard(props: KinCanvasCardProps) { + const { card, detail } = props; + return ( + props.onPress(card.key)} + className={cn( + "absolute overflow-hidden rounded-xl active:opacity-80", + detail === "dots" ? "p-0" : "border p-3", + card.kind === "doc" ? "bg-card-alt" : "bg-card", + props.peeked + ? "border-2 border-primary" + : card.working + ? "border-primary/60" + : card.tone === "late" + ? "border-danger-border" + : "border-border", + )} + style={{ + left: props.x + KIN_CANVAS_WORLD_HALF, + top: props.y + KIN_CANVAS_WORLD_HALF, + width: KIN_CANVAS_CARD_W, + height: KIN_CANVAS_CARD_H, + }} + > + {detail === "dots" ? ( + + ) : detail === "titles" ? ( + + + + {card.title} + + + ) : ( + + + + {card.title} + + {detail === "near" && props.readsText ? ( + + ) : ( + <> + + {card.line} + + {card.summary !== null ? ( + + {card.summary} + + ) : null} + + )} + {card.working ? : null} + + )} + + ); +}); + +/** Whole lines of a zoomed-out title the card holds under its mark, so none is cut through. */ +const titleLines = (inv: number) => + Math.max(1, Math.min(4, Math.floor((KIN_CANVAS_CARD_H - 24 - 16 * inv) / (18 * inv)))); + +function dotTone(card: KinCanvasCardView) { + if (card.working) return "bg-primary/60"; + if (card.tone === "late") return "bg-danger/45"; + if (card.tone === "doc") return "bg-foreground/10"; + if (card.tone === "doing") return "bg-primary/25"; + return "bg-foreground/20"; +} + +/** Zoomed out, what kind of card it is, without words: a page for a doc, the task's state. */ +function KindMark(props: { readonly card: KinCanvasCardView; readonly size: number }) { + const state = STATE_OF_TONE[props.card.tone]; + return ( + + {state === null ? ( + + ) : ( + + + + )} + {props.card.working ? ( + + ) : null} + + ); +} + +function CardHead(props: { readonly card: KinCanvasCardView }) { + const { card } = props; + const state = STATE_OF_TONE[card.tone]; + return ( + + {state === null ? ( + + ) : ( + + )} + + {card.key} + + + {card.tone === "late" ? "· Late" : card.kind === "doc" ? "· Doc" : ""} + + + ); +} + +/** Still, never pulsing: a mark that an agent's worker is running on this task now. */ +function WorkingLine() { + return ( + + + + {KIN_CANVAS.agentWorking} + + + ); +} + +/** Close enough to read: the doc's own opening lines, from the read its page uses. */ +function DocText(props: { readonly target: KinWorkTarget; readonly docKey: KinRecordKey }) { + const { state } = useKinDoc(props.target, props.docKey, null); + const text = + state._tag === "ready" + ? kinDocPlainText(state.value.body) + : state._tag === "loading" + ? "" + : KIN_CANVAS.readFailed; + return ( + + {text} + + ); +} + +/** A doc's markdown as plain running text for a few lines on a card. */ +export function kinDocPlainText(markdown: string): string { + return ( + markdown + .replace(/```[\s\S]*?```/g, " ") + .replace(/!\[[^\]]*\]\([^)]*\)/g, " ") + .replace(/\[([^\]]*)\]\([^)]*\)/g, "$1") + // A heading reads as a lead-in to what follows it: "Goal: Patients book…". + .replace(/^#{1,6}\s+(.*?)[\s:]*$/gm, "$1:") + .replace(/[*_`>|]/g, "") + .replace(/\s+/g, " ") + .trim() + ); +} diff --git a/apps/mobile/src/features/chats/canvas/KinCanvasOverlays.tsx b/apps/mobile/src/features/chats/canvas/KinCanvasOverlays.tsx new file mode 100644 index 0000000000000..f7ebc45c93092 --- /dev/null +++ b/apps/mobile/src/features/chats/canvas/KinCanvasOverlays.tsx @@ -0,0 +1,85 @@ +import { KIN_RETRY } from "@t3tools/client-runtime/kin/kinAnswers"; +import { KIN_CANVAS } from "@t3tools/client-runtime/kin/kinCanvasView"; +import { Pressable, View } from "react-native"; + +import { AppText as Text } from "../../../components/ui/AppText"; +import { Button } from "../../../components/ui/Button"; +import { SymbolView, type AppSymbolName } from "../../../components/ui/AppSymbol"; +import { SegmentedControl } from "../../../components/ui/SegmentedControl"; +import type { KinCanvasTasks as KinCanvasShow } from "../state/useKinCanvas"; + +const PANEL = "rounded-full border border-border bg-card"; + +function RoundButton(props: { + readonly icon: AppSymbolName; + readonly label: string; + readonly onPress: () => void; +}) { + return ( + + + + ); +} + +export function KinCanvasZoomControls(props: { + readonly onZoomOut: () => void; + readonly onZoomIn: () => void; + readonly onShowAll: () => void; +}) { + return ( + + + + + + ); +} + +/** In progress, or every open task: what the map draws tasks of. */ +export function KinCanvasShowSwitch(props: { + readonly show: KinCanvasShow; + readonly onShow: (show: KinCanvasShow) => void; +}) { + return ( + + size="compact" + className="w-60" + role="tab" + options={[ + { value: "doing", label: KIN_CANVAS.doing }, + { value: "open", label: KIN_CANVAS.allOpen }, + ]} + selected={props.show} + onSelect={props.onShow} + /> + ); +} + +/** Where the map stops short of everything, in one quiet line. */ +/** Where the map stops short or what didn't load, with Retry when something failed. */ +export function KinCanvasPartial(props: { + readonly lines: ReadonlyArray; + readonly onRetry: (() => void) | null; +}) { + if (props.lines.length === 0) return null; + return ( + + + {props.lines.join(" · ")} + + {props.onRetry === null ? null : ( +