fix: invalid Document types

fix: url deduction for page reload to apply new document type
This commit is contained in:
Grégoire Cutzach 2024-10-03 20:48:57 +02:00
parent aa9e42bd47
commit fbc911721e
No known key found for this signature in database
GPG Key ID: AA4155BE23C375E6

View File

@ -310,10 +310,10 @@ export class DocSettingsPage extends Disposable {
const currentDocType = docPageModel.type.get() as string; const currentDocType = docPageModel.type.get() as string;
let currentDocTypeOption; let currentDocTypeOption;
switch (currentDocType) { switch (currentDocType) {
case "Template": case "template":
currentDocTypeOption = DocTypeOption.Template; currentDocTypeOption = DocTypeOption.Template;
break; break;
case "Tutorial": case "tutorial":
currentDocTypeOption = DocTypeOption.Tutorial; currentDocTypeOption = DocTypeOption.Tutorial;
break; break;
default: default:
@ -328,12 +328,19 @@ export class DocSettingsPage extends Disposable {
if (selected.get() === DocTypeOption.Regular) { if (selected.get() === DocTypeOption.Regular) {
docType = ""; docType = "";
} else if (selected.get() === DocTypeOption.Template) { } else if (selected.get() === DocTypeOption.Template) {
docType = "Template"; docType = "template";
} else { } else {
docType = "Tutorial"; docType = "tutorial";
} }
await persistType(docType, docId); await persistType(docType, docId);
window.location.reload(); const currentUrl = window.location.href;
const urlId = currentUrl.split("/docs/")[1];
const cleanUrlId = urlId.match(/^doc\/.*/) ? urlId.split("/")[1] : urlId.split("/")[0];
const shortDocId = urlId?.split("~")[0];
const reloadUrl = urlId.match(/^doc\/.*/) ?
currentUrl.replace(`doc/${cleanUrlId}`, shortDocId) :
currentUrl.replace(cleanUrlId, shortDocId);
window.location.replace(reloadUrl ?? "");
}; };
const documentTypeOptions = () => [ const documentTypeOptions = () => [