MCPcopy Create free account
hub / github.com/PaperDebugger/paperdebugger / Main

Function Main

webapp/_webapp/src/main.tsx:25–181  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

23import { AdapterProvider, getOverleafAdapter } from "./adapters";
24
25export const Main = () => {
26 const { inputRef, setActiveTab } = useConversationUiStore();
27 const {
28 lastSelectedText,
29 lastSurroundingText,
30 lastSelectionRange,
31 setLastSelection,
32 setSelectedText,
33 setSurroundingText,
34 setSelectionRange,
35 clearOverleafSelection,
36 } = useSelectionStore();
37 const [menuElement, setMenuElement] = useState<Element | null>(null);
38 const { isOpen, setIsOpen } = useConversationUiStore();
39 const { settings, loadSettings, initLocalSettings } = useSettingStore();
40 const { login } = useAuthStore();
41 const { loadPrompts } = usePromptLibraryStore();
42
43 useThemeSync();
44
45 useEffect(() => {
46 apiclient.updateBaseURL(getEndpointFromLocalStorage(), "v1");
47 apiclientV2.updateBaseURL(getEndpointFromLocalStorage(), "v2");
48 initLocalSettings();
49 login();
50 loadSettings();
51 loadPrompts();
52 }, []); // eslint-disable-line react-hooks/exhaustive-deps
53
54 useEffect(() => {
55 const handleSelectionChange = () => {
56 const selection = window.getSelection();
57 // check if the selection is in the editor
58 const editor = document.querySelector(".cm-editor");
59 if (editor && editor.contains(selection?.anchorNode ?? null)) {
60 const text = selection?.toString() ?? null;
61
62 let surrounding = "";
63 try {
64 const cmContentElement = document.querySelector(".cm-content");
65 if (cmContentElement) {
66 // eslint-disable-next-line @typescript-eslint/no-explicit-any
67 const state = (cmContentElement as any).cmView.view.state;
68 if (state) {
69 const cmSelection = state.selection.main;
70 const doc = state.doc;
71 const before = doc.sliceString(Math.max(0, cmSelection.from - 100), cmSelection.from);
72 const after = doc.sliceString(cmSelection.to, Math.min(doc.length, cmSelection.to + 100));
73 surrounding = `${before}[SELECTED_TEXT_START]${text}[SELECTED_TEXT_END]${after}`;
74 }
75 }
76 } catch {
77 // fallback
78 }
79
80 setLastSelection(text, surrounding, selection?.getRangeAt(0) ?? null);
81 return;
82 } else {

Callers

nothing calls this directly

Calls 3

useThemeSyncFunction · 0.90
onElementAddedFunction · 0.90
updateBaseURLMethod · 0.80

Tested by

no test coverage detected