Path: blob/master/src/packages/frontend/chat/thread-anchor-button.tsx
14422 views
/*1* This file is part of CoCalc: Copyright © 2020-2026 Sagemath, Inc.2* License: MS-RSL – see LICENSE.md for details3*/45import { Button, Tooltip } from "antd";6import { Icon } from "@cocalc/frontend/components";7import { COLORS } from "@cocalc/util/theme";8import type { ChatActions } from "./actions";910interface Props {11anchorId: string;12actions: ChatActions;13}1415const BUTTON_STYLE = {16background: COLORS.BLUE_LLL,17borderColor: COLORS.BLUE_LL,18color: COLORS.BLUE_D,19} as const;2021export function ThreadAnchorButton({ anchorId, actions }: Props) {22const editorActions = actions.frameTreeActions as any;23if (!editorActions || typeof editorActions.jumpToAnchor !== "function") {24return null;25}26// Prefer the location-only label (`path:line`); the opaque hash is27// not useful in a "Jump to ..." button. Fall back to the full label28// (which includes the hash) only when no jump-label is available, and29// finally to a bare "Jump to anchor".30const jumpTarget: string | undefined =31editorActions.getAnchorJumpLabel?.(anchorId) ??32editorActions.getAnchorLabel?.(anchorId);33const label = jumpTarget ? `Jump to ${jumpTarget}` : "Jump to anchor";3435return (36<Tooltip title="Jump to this anchor in the source">37<Button38style={BUTTON_STYLE}39icon={<Icon name="comment" />}40onClick={() => editorActions.jumpToAnchor(anchorId)}41>42{label}43</Button>44</Tooltip>45);46}474849