From 5d2a6fce305a3dcd4857f52ebb75f529dffe4790 Mon Sep 17 00:00:00 2001 From: KernelDeimos Date: Mon, 22 Jul 2024 17:10:58 -0400 Subject: [PATCH] fix: fix templates --- src/gui/src/helpers.js | 20 +++++++++++++++++--- src/gui/src/helpers/new_context_menu_item.js | 10 ++++++++-- 2 files changed, 25 insertions(+), 5 deletions(-) diff --git a/src/gui/src/helpers.js b/src/gui/src/helpers.js index b1103b52..575f2667 100644 --- a/src/gui/src/helpers.js +++ b/src/gui/src/helpers.js @@ -869,12 +869,26 @@ window.available_templates = async () => { hasTemplateFiles.forEach(element => { console.log(element) - const elementInformation = element.name.split(".") - const name = elementInformation[0] - let extension = elementInformation[1] + + const extIndex = element.name.lastIndexOf('.'); + const name = extIndex === -1 + ? element.name + : element.name.slice(0, extIndex); + let extension = extIndex === -1 + ? '' + : element.name.slice(extIndex + 1); + console.log(extension) if(extension == "txt") extension = "text" + + // TODO: should use path join utility + const path = + baseRoute + "/" + + hasTemplateFolder.name + '/' + + element.name; + const itemStructure = { + path, html: `${extension.toUpperCase()} ${name}`, extension:extension, name: element.name diff --git a/src/gui/src/helpers/new_context_menu_item.js b/src/gui/src/helpers/new_context_menu_item.js index 11a091ec..64c0da2b 100644 --- a/src/gui/src/helpers/new_context_menu_item.js +++ b/src/gui/src/helpers/new_context_menu_item.js @@ -84,8 +84,14 @@ const new_context_menu_item = function(dirname, append_to_element){ items: window.file_templates.map(template => ({ html: template.html, icon: ``, - onClick: function() { - window.create_file({dirname: dirname, append_to_element: append_to_element, name: template.name}); + onClick: async function () { + const content = await puter.fs.read(template.path); + window.create_file({ + dirname: dirname, + append_to_element: append_to_element, + name: template.name, + content, + }); } })) });