Skip to content

Commit 8579c56

Browse files
author
unjinjang
committed
[FEAT]: Add logic to update UI when sidebar history collection is clicked
1 parent 41e1560 commit 8579c56

File tree

3 files changed

+50
-5
lines changed

3 files changed

+50
-5
lines changed

src/MainWebViewPanel.js

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,17 @@ class MainWebViewPanel {
7070

7171
return;
7272
}
73-
73+
const requestObject = {
74+
requestMethod,
75+
requestUrl,
76+
authOption,
77+
authData,
78+
bodyOption,
79+
bodyRawOption,
80+
bodyRawData,
81+
keyValueTableData,
82+
command,
83+
};
7484
this.#url = getUrl(requestUrl);
7585
this.#method = requestMethod;
7686
this.#headers = getHeaders(keyValueTableData, authOption, authData);
@@ -81,12 +91,12 @@ class MainWebViewPanel {
8191
bodyRawData,
8292
);
8393

84-
this.#postWebviewMessage();
94+
this.#postWebviewMessage(requestObject);
8595
},
8696
);
8797
}
8898

89-
async #postWebviewMessage() {
99+
async #postWebviewMessage(requestObject) {
90100
const { userRequestHistory } = this.stateManager.getExtensionContext(
91101
COLLECTION.HISTORY_COLLECTION,
92102
);
@@ -114,6 +124,7 @@ class MainWebViewPanel {
114124
favoritedTime: null,
115125
isUserFavorite: false,
116126
id: uuidv4(),
127+
requestObject,
117128
},
118129
],
119130
},
@@ -129,6 +140,7 @@ class MainWebViewPanel {
129140
favoritedTime: null,
130141
isUserFavorite: false,
131142
id: uuidv4(),
143+
requestObject,
132144
},
133145
...userRequestHistory,
134146
],
@@ -137,6 +149,9 @@ class MainWebViewPanel {
137149
}
138150
}
139151

152+
console.log(
153+
this.stateManager.getExtensionContext(COLLECTION.HISTORY_COLLECTION),
154+
);
140155
this.mainPanel.webview.postMessage(responseObject);
141156
this.sidebarWebViewPanel.postMainWebViewPanelMessage(
142157
this.stateManager.getExtensionContext(COLLECTION.HISTORY_COLLECTION),

webview/features/Request/Method/RequestMethod.js

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,23 @@
11
import React from "react";
22
import styled from "styled-components";
3+
import shallow from "zustand/shallow";
34

45
import { OPTION, REQUEST } from "../../../constants";
56
import useStore from "../../../store/useStore";
67

78
const RequestMethod = () => {
8-
const handleRequestMethodChange = useStore(
9-
(state) => state.handleRequestMethodChange,
9+
const { requestMethod, handleRequestMethodChange } = useStore(
10+
(state) => ({
11+
requestMethod: state.requestMethod,
12+
handleRequestMethodChange: state.handleRequestMethodChange,
13+
}),
14+
shallow,
1015
);
1116

1217
return (
1318
<MethodSelectOptionWrapper
1419
name="httpRequestMethods"
20+
value={requestMethod}
1521
onChange={(event) => handleRequestMethodChange(event.target.value)}
1622
>
1723
{OPTION.REQUEST_METHOD_OPTIONS.map((requestMethod, index) => (

webview/features/Response/Panel/ResponsePanel.js

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,16 @@ const ResponsePanel = () => {
1515
requestInProcess,
1616
handleResponseData,
1717
handleRequestProcessStatus,
18+
handleSidebarCollectionHeaders,
19+
handleSidebarCollectionClick,
1820
} = useStore(
1921
(state) => ({
2022
responseData: state.responseData,
2123
requestInProcess: state.requestInProcess,
2224
handleResponseData: state.handleResponseData,
2325
handleRequestProcessStatus: state.handleRequestProcessStatus,
26+
handleSidebarCollectionClick: state.handleSidebarCollectionClick,
27+
handleSidebarCollectionHeaders: state.handleSidebarCollectionHeaders,
2428
}),
2529
shallow,
2630
);
@@ -34,6 +38,26 @@ const ResponsePanel = () => {
3438
handleRequestProcessStatus(RESPONSE.ERROR);
3539
} else if (event.data.type === RESPONSE.COLLECTION_REQUEST) {
3640
handleRequestProcessStatus(COMMON.LOADING);
41+
} else if (event.data.type === RESPONSE.SIDE_BAR_DATA) {
42+
const {
43+
keyValueTableData,
44+
authData,
45+
authOption,
46+
requestUrl,
47+
requestMethod,
48+
bodyOption,
49+
bodyRawOption,
50+
} = event.data;
51+
52+
handleSidebarCollectionClick({
53+
authData,
54+
authOption,
55+
requestUrl,
56+
requestMethod,
57+
bodyOption,
58+
bodyRawOption,
59+
});
60+
handleSidebarCollectionHeaders(keyValueTableData);
3761
}
3862
};
3963

0 commit comments

Comments
 (0)