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;
let currentDocTypeOption;
switch (currentDocType) {
case "Template":
case "template":
currentDocTypeOption = DocTypeOption.Template;
break;
case "Tutorial":
case "tutorial":
currentDocTypeOption = DocTypeOption.Tutorial;
break;
default:
@ -328,12 +328,19 @@ export class DocSettingsPage extends Disposable {
if (selected.get() === DocTypeOption.Regular) {
docType = "";
} else if (selected.get() === DocTypeOption.Template) {
docType = "Template";
docType = "template";
} else {
docType = "Tutorial";
docType = "tutorial";
}
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 = () => [