MCPcopy
hub / github.com/srcbookdev/srcbook / Session

Function Session

packages/web/src/routes/session.tsx:122–456  ·  view source on GitHub ↗
(props: SessionProps)

Source from the content-addressed store, hash-verified

120 | ({ readOnly?: false; channel: SessionChannel } & SessionPropsBase);
121
122function Session(props: SessionProps) {
123 const { readOnly, session, srcbooks, config } = props;
124 const channel = !readOnly ? props.channel : null;
125
126 const {
127 cells: allCells,
128 updateCell,
129 removeCell,
130 createCodeCell,
131 createMarkdownCell,
132 createGenerateAiCell,
133 setOutput,
134 setTsServerDiagnostics,
135 setTsServerSuggestions,
136 } = useCells();
137
138 const {
139 npmInstall,
140 failed: dependencyInstallFailed,
141 outdated: outdatedDependencies,
142 installing: installingDependencies,
143 output: dependencyInstallOutput,
144 } = usePackageJson();
145
146 const [depsInstallModalOpen, setDepsInstallModalOpen] = useState(false);
147 const [[selectedPanelName, selectedPanelOpen], setSelectedPanelNameAndOpen] = useState<
148 [Panel['name'], boolean]
149 >([SESSION_MENU_PANELS[0]!.name, false]);
150
151 const isPanelOpen = useCallback(
152 (name: Panel['name']) => selectedPanelOpen && selectedPanelName === name,
153 [selectedPanelOpen, selectedPanelName],
154 );
155
156 useHotkeys('mod+;', () => {
157 if (!isPanelOpen('packages')) {
158 setSelectedPanelNameAndOpen(['packages', true]);
159 }
160 });
161
162 async function onDeleteCell(cell: CellType | GenerateAICellType) {
163 if (!channel) {
164 return;
165 }
166 if (cell.type !== 'code' && cell.type !== 'markdown') {
167 throw new Error(`Cannot delete cell of type '${cell.type}'`);
168 }
169
170 // Optimistically delete cell
171 removeCell(cell);
172
173 channel.push('cell:delete', {
174 cellId: cell.id,
175 });
176 }
177
178 useEffect(() => {
179 if (!channel) {

Callers

nothing calls this directly

Calls 6

useCellsFunction · 0.90
usePackageJsonFunction · 0.90
cnFunction · 0.90
createNewCellFunction · 0.85
onMethod · 0.45
offMethod · 0.45

Tested by

no test coverage detected