import React, { useContext, useState, useEffect } from "react"; import SelectSearch from "react-select-search"; import { GetTranscript, GetTranscriptTopic } from "../../../api"; import "react-select-search/style.css"; import { DomainContext } from "../../../domainContext"; import useApi from "../../../lib/useApi"; type ShareModalProps = { show: boolean; setShow: (show: boolean) => void; transcript: GetTranscript | null; topics: GetTranscriptTopic[] | null; }; interface Stream { stream_id: number; name: string; } interface Topic { name: string; } interface SelectSearchOption { name: string; value: string; } const ShareModal = (props: ShareModalProps) => { const [stream, setStream] = useState(undefined); const [topic, setTopic] = useState(undefined); const [includeTopics, setIncludeTopics] = useState(false); const [isLoading, setIsLoading] = useState(true); const [streams, setStreams] = useState([]); const [topics, setTopics] = useState([]); const api = useApi(); useEffect(() => { const fetchZulipStreams = async () => { if (!api) return; try { const response = await api.v1ZulipGetStreams(); setStreams(response); setIsLoading(false); } catch (error) { console.error("Error fetching Zulip streams:", error); } }; fetchZulipStreams(); }, [!api]); useEffect(() => { const fetchZulipTopics = async () => { if (!api || !stream) return; try { const selectedStream = streams.find((s) => s.name === stream); if (selectedStream) { const response = await api.v1ZulipGetTopics({ streamId: selectedStream.stream_id, }); setTopics(response); } } catch (error) { console.error("Error fetching Zulip topics:", error); } }; fetchZulipTopics(); }, [stream, streams, api]); const handleSendToZulip = async () => { if (!api || !props.transcript) return; if (stream && topic) { try { await api.v1TranscriptPostToZulip({ transcriptId: props.transcript.id, stream, topic, includeTopics, }); } catch (error) { console.log(error); } } }; if (props.show && isLoading) { return
Loading...
; } const streamOptions: SelectSearchOption[] = streams.map((stream) => ({ name: stream.name, value: stream.name, })); const topicOptions: SelectSearchOption[] = topics.map((topic) => ({ name: topic.name, value: topic.name, })); return (
{props.show && (

Send to Zulip

{/* Checkbox for 'Include Topics' */}
# { setTopic(undefined); // Reset topic when stream changes setStream(val.toString()); }} placeholder="Pick a stream" />
{stream && (
# setTopic(val.toString())} placeholder="Pick a topic" />
)}
)}
); }; export default ShareModal;