Skip to content

Commit

Permalink
resolve link submission progress
Browse files Browse the repository at this point in the history
  • Loading branch information
hahnbeelee committed Jul 14, 2022
1 parent 50c6e94 commit 464ac75
Showing 1 changed file with 39 additions and 29 deletions.
68 changes: 39 additions & 29 deletions vscode/src/mintlify/webview/viewProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -192,35 +192,45 @@ export class ViewProvider implements WebviewViewProvider {
}
case 'link-submit': {
const { docId, code, url } = message.args;
await vscode.window.withProgress(
{
location: vscode.ProgressLocation.Notification,
title: 'Connecting documentation with code',
},
async () => {
try {
const authParams = await this.container.storage.getAuthParams();
const response = await axios.put(
`${API_ENDPOINT}/links`,
{ docId: docId, code: code, url: url },
{
params: authParams,
},
);
await this.prefillDoc(response.data.doc);
await vscode.commands.executeCommand('mintlify.refresh-views');
await executeCommand(Commands.RefreshLinks);
return vscode.window.showInformationMessage(
`Successfully connected code with ${response.data.doc.title}`,
);
} catch (err) {
const errMessage =
err?.response?.data?.error ??
`Error connecting code. Please log back in, re-install the extension, or report bug to [email protected]`;
return vscode.window.showInformationMessage(errMessage);
}
},
);
try {
const progress: string = await vscode.window.withProgress(
{
location: vscode.ProgressLocation.Notification,
title: 'Connecting documentation with code',
},
() => {
return new Promise((resolve, reject) => {
this.container.storage
.getAuthParams()
.then(authParams =>
axios.put(
`${API_ENDPOINT}/links`,
{ docId: docId, code: code, url: url },
{
params: authParams,
},
),
)
.then(response => {
return this.prefillDoc(response.data.doc)
.then(() => vscode.commands.executeCommand('mintlify.refresh-links'))
.then(() => vscode.commands.executeCommand('mintlify.refresh-views'))
.then(() => resolve(response.data.doc.title));
})
.catch(err => {
const errMessage =
err?.response?.data?.error ??
`Error connecting code. Please log back in, re-install the extension, or report bug to [email protected]`;
return reject(errMessage);
});
});
},
);
await vscode.window.showInformationMessage(`Successfully connected code with ${progress}`);
} catch (errMessage) {
await vscode.window.showInformationMessage(errMessage);
}

break;
}
case 'refresh-code': {
Expand Down

0 comments on commit 464ac75

Please sign in to comment.