MCPcopy Create free account
hub / github.com/EsperoTech/yaade / WebsocketPanel

Function WebsocketPanel

client/src/components/websocketPanel/WebsocketPanel.tsx:73–328  ·  view source on GitHub ↗
({
  currentRequest,
  dispatchCurrentRequest,
  dispatchCollections,
  connectionStatus,
  onConnect,
  onWrite,
  onDisconnect,
  selectedEnvData,
}: WebsocketPanelProps)

Source from the content-addressed store, hash-verified

71};
72
73function WebsocketPanel({
74 currentRequest,
75 dispatchCurrentRequest,
76 dispatchCollections,
77 connectionStatus,
78 onConnect,
79 onWrite,
80 onDisconnect,
81 selectedEnvData,
82}: WebsocketPanelProps) {
83 const ref = useRef<HTMLDivElement>(null);
84 const { colorMode } = useColorMode();
85 const toast = useToast();
86
87 async function handleSaveRequestClick(preventSuccessToast = false) {
88 try {
89 if (currentRequest.id === -1 && currentRequest.collectionId === -1) {
90 return;
91 }
92 await api.updateRequest(currentRequest);
93 dispatchCollections({
94 type: CollectionsActionType.PATCH_REQUEST_DATA,
95 id: currentRequest.id,
96 data: { ...currentRequest.data },
97 });
98 dispatchCurrentRequest({
99 type: CurrentRequestActionType.SET_IS_CHANGED,
100 isChanged: false,
101 });
102 if (!preventSuccessToast) {
103 successToast('The request was successfully saved.', toast);
104 }
105 } catch (e) {
106 console.error(e);
107 errorToast('The request could not be saved.', toast);
108 }
109 }
110
111 useKeyPress(handleSaveRequestClick, 's', true);
112
113 const setUri = useCallback(
114 (uri: string) => {
115 const params = getParamsFromUri(uri, currentRequest.data.params);
116 dispatchCurrentRequest({
117 type: CurrentRequestActionType.PATCH_DATA,
118 data: { uri, params },
119 });
120 },
121 [currentRequest.data.params, dispatchCurrentRequest],
122 );
123
124 const { setContainer } = useCodeMirror({
125 container: ref.current,
126 onChange: (value: string) => setUri(value),
127 extensions: [
128 yaade(colorMode),
129 colorMode === 'light' ? baseThemeLight : baseThemeDark,
130 singleLineExtension,

Callers

nothing calls this directly

Calls 8

useKeyPressFunction · 0.90
getParamsFromUriFunction · 0.90
yaadeFunction · 0.90
wordHoverFunction · 0.90
getUriFromParamsFunction · 0.90
cnFunction · 0.90
setContentTypeFunction · 0.85
handleSaveRequestClickFunction · 0.70

Tested by

no test coverage detected