Skip to content

Commit 9545b78

Browse files
authored
Merge pull request #633 from SwapnilChand/632-multiple-new-requests
[WIP][feature][extension] Multiple new requests
2 parents 3e7bee3 + 1b2739b commit 9545b78

File tree

4 files changed

+72
-12
lines changed

4 files changed

+72
-12
lines changed

extensions/src/SidebarProvider.ts

+7-2
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,8 @@ export class SidebarProvider implements vscode.WebviewViewProvider {
6060
console.log("Exporting API history...");
6161

6262
const downloadsFolder = process.platform === 'darwin'
63-
? path.join(process.env.HOME, 'Downloads') // macOS
64-
: path.join(process.env.USERPROFILE, 'Downloads'); // Windows/Linux
63+
? path.join(process.env.HOME, 'Downloads')
64+
: path.join(process.env.USERPROFILE, 'Downloads');
6565

6666
const filePath = path.join(downloadsFolder, 'history.msgpack');
6767
const packedData = msgpack.encode(this.apiHistory);
@@ -108,13 +108,15 @@ export class SidebarProvider implements vscode.WebviewViewProvider {
108108
break;
109109
}
110110
case "openApiManagement": {
111+
console.log("API MANAGEMENT CASE");
111112
if (!data.value) {
112113
return;
113114
}
114115
this.openWebview(data.value);
115116
break;
116117
}
117118
case "backButton": {
119+
console.log("Going Back");
118120
this.showHistory = false;
119121
this.refresh();
120122
break;
@@ -125,14 +127,17 @@ export class SidebarProvider implements vscode.WebviewViewProvider {
125127
break;
126128
}
127129
case "deleteEndpoint": {
130+
console.log("Deleting endpoint");
128131
this.deleteEndpoint(data.name, data.method);
129132
break;
130133
}
131134
case "selectEndpoint": {
135+
console.log("Selection endpoint");
132136
this.loadEndpoint(data.value);
133137
break;
134138
}
135139
case "exportHistory": {
140+
console.log("Export history");
136141
this.exportHistory();
137142
break;
138143
}

extensions/src/apiRequest/apiRequestProvider.ts

+8-4
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,11 @@ export class ApiRequestProvider {
3131
}
3232

3333
public openApiRequestView() {
34-
console.log("This is the request view");
35-
if (!this.view) {
36-
this.view = new ApiRequestView(this.context, this.handleApiRequest);
37-
}
34+
console.log("API Request View : This is the request view");
35+
// if (!this.view) {
36+
// this.view = new ApiRequestView(this.context, this.handleApiRequest);
37+
// }
38+
this.view = new ApiRequestView(this.context, this.handleApiRequest);
3839
this.view.show();
3940
this.updateCollectionsView();
4041
}
@@ -48,6 +49,7 @@ export class ApiRequestProvider {
4849
body: string,
4950
bodyType: string
5051
): Promise<void> {
52+
console.log("Handle API Request called");
5153
try {
5254
// Append query params to URL
5355
const urlObj = new URL(url);
@@ -93,12 +95,14 @@ export class ApiRequestProvider {
9395
}
9496

9597
public addCollection(name: string) {
98+
console.log("api Request view : AddCollections called");
9699
this.collections.push({ name, requests: [] });
97100
this.saveCollections();
98101
this.updateCollectionsView();
99102
}
100103

101104
public addRequestToCollection(collectionName: string, request: ApiRequest) {
105+
console.log("api Request view : AddRequestToCollections called");
102106
const collection = this.collections.find(c => c.name === collectionName);
103107
if (collection) {
104108
collection.requests.push(request);

extensions/src/apiRequest/apiRequestView.ts

+56-6
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,62 @@ export class ApiRequestView {
2121
this.context = context;
2222
this.apiRequestCallback = apiRequestCallback;
2323
}
24-
24+
// public show(method?: string, url?: string, headers?: Record<string, string>, body?: string) {
25+
// console.log("Show from View");
26+
27+
// // Create a new panel every time this method is called
28+
// const newPanel = vscode.window.createWebviewPanel(
29+
// 'apiRequest',
30+
// 'API Request',
31+
// vscode.ViewColumn.One,
32+
// {
33+
// enableScripts: true,
34+
// retainContextWhenHidden: true,
35+
// }
36+
// );
37+
38+
// // Set up webview content
39+
// newPanel.webview.html = this.getWebviewContent();
40+
41+
// // Populate fields if provided
42+
// if (method && url) {
43+
// newPanel.webview.postMessage({
44+
// command: 'populateFields',
45+
// method: method,
46+
// url: url,
47+
// headers: headers || {},
48+
// body: body || ''
49+
// });
50+
// }
51+
52+
// // Handle messages from the webview
53+
// newPanel.webview.onDidReceiveMessage(
54+
// message => {
55+
// switch (message.command) {
56+
// case 'sendRequest':
57+
// this.apiRequestCallback(message.method, message.url, message.headers, message.queryParams, message.formData, message.body, message.bodyType);
58+
// return;
59+
// case 'saveEndpoint':
60+
// this.saveEndpoint(message.method, message.url);
61+
// return;
62+
// }
63+
// },
64+
// undefined,
65+
// this.context.subscriptions
66+
// );
67+
68+
// // Clean up when the panel is disposed
69+
// newPanel.onDidDispose(() => {
70+
// // Optionally handle any cleanup or state management here
71+
// });
72+
// }
2573
public show() {
26-
if (this.panel) {
27-
this.panel.reveal();
28-
} else {
74+
console.log("Show from View");
75+
// if (this.panel) {
76+
// console.log("Show from View : if condition");
77+
// this.panel.reveal();
78+
// } else {
79+
// console.log("Show from View : else condition");
2980
this.panel = vscode.window.createWebviewPanel(
3081
'apiRequest',
3182
'API Request',
@@ -56,14 +107,13 @@ export class ApiRequestView {
56107
this.panel.onDidDispose(() => {
57108
this.panel = undefined;
58109
});
59-
}
110+
// }
60111
}
61112

62113
public postMessage(message: any) {
63114
this.panel?.webview.postMessage(message);
64115
}
65116
private saveEndpoint(method: string, url: string) {
66-
// Check if the URL is blank
67117
if (!url.trim()) {
68118
vscode.window.showErrorMessage("URL is blank. Cannot save endpoint.");
69119
return;

extensions/src/utils/httpClient.ts

+1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
export class HttpClient {
22
public async sendRequest(url: string, method: string, headers: Record<string, string>, body?: string | FormData) {
3+
console.log("Request sent from https client");
34
try {
45
const options: RequestInit = {
56
method,

0 commit comments

Comments
 (0)