MCPcopy Create free account
hub / github.com/anomalyco/opencode / Share

Function Share

packages/web/src/components/Share.tsx:41–499  ·  view source on GitHub ↗
(props: {
  id: string
  api: string
  info: Session.Info
  messages: { locale: string } & Record<string, string>
})

Source from the content-addressed store, hash-verified

39}
40
41export default function Share(props: {
42 id: string
43 api: string
44 info: Session.Info
45 messages: { locale: string } & Record<string, string>
46}) {
47 let lastScrollY = 0
48 let hasScrolledToAnchor = false
49 let scrollTimeout: number | undefined
50 let scrollSentinel: HTMLElement | undefined
51 let scrollObserver: IntersectionObserver | undefined
52
53 const params = new URLSearchParams(window.location.search)
54 const debug = params.get("debug") === "true"
55
56 const [showScrollButton, setShowScrollButton] = createSignal(false)
57 const [isButtonHovered, setIsButtonHovered] = createSignal(false)
58 const [isNearBottom, setIsNearBottom] = createSignal(false)
59
60 const [store, setStore] = createStore<{
61 info?: Session.Info
62 messages: Record<string, MessageWithParts>
63 }>({
64 info: {
65 id: props.id,
66 slug: props.info.slug,
67 projectID: props.info.projectID,
68 directory: props.info.directory,
69 title: props.info.title,
70 version: props.info.version,
71 time: {
72 created: props.info.time.created,
73 updated: props.info.time.updated,
74 },
75 },
76 messages: {},
77 })
78 const messages = createMemo(() => Object.values(store.messages).toSorted((a, b) => a.id?.localeCompare(b.id)))
79 const [connectionStatus, setConnectionStatus] = createSignal<[Status, string?]>(["disconnected"])
80
81 onMount(() => {
82 const apiUrl = props.api
83
84 if (!props.id) {
85 setConnectionStatus(["error", props.messages.error_id_not_found])
86 return
87 }
88
89 if (!apiUrl) {
90 console.error("API URL not found in environment variables")
91 setConnectionStatus(["error", props.messages.error_api_url_not_found])
92 return
93 }
94
95 let reconnectTimer: number | undefined
96 let socket: WebSocket | null = null
97
98 // Function to create and set up WebSocket with auto-reconnect

Callers

nothing calls this directly

Calls 15

normalizeLocaleFunction · 0.90
formatCurrencyFunction · 0.90
formatNumberFunction · 0.90
setupWebSocketFunction · 0.85
checkScrollNeedFunction · 0.85
scrollToAnchorFunction · 0.85
getStatusTextFunction · 0.85
addEventListenerMethod · 0.80
pushMethod · 0.80
lastFunction · 0.70
getMethod · 0.65
messagesFunction · 0.50

Tested by

no test coverage detected