sottey / tje

JSON Note editor for Trilium
MIT License
10 stars 0 forks source link

The code in `tje.js` is wrong #5

Open xcdmrCHP opened 5 months ago

xcdmrCHP commented 5 months ago

The code in tje.js doesn't seem to be working properly, here's what I've modified to work properly

...
async function init() {
    var saveIcon = '...';
    currSpreadsheet = x_spreadsheet('#tje_container', { showTopBar: true, showBottomBar: false,extendToolbar: {left: [{ tip: 'Save current spreadsheet', icon: saveIcon, onClick: onSaveContents}]}});  

//↓The following has been modified
    const jsonNotesRaw = await api.searchForNotes("note.type = code AND note.mime = 'application/json' AND #!tjeExclude");
    const jsonNotes=jsonNotesRaw.map(n => ({
        id: n.noteId,
        title: n.title,
    }));
//↑The above has been modified

    addJSONNotesToList(jsonNotes);

    jsonNotesData.addEventListener("change", onJSONNoteSelect); 
    saveButton.addEventListener("click", onSaveContents); 
    autosaveCheckbox.addEventListener("change", onAutosaveChange); 
    showSpreadsheet(false);
}

init();

...

function addJSONNotesToList(jsonObjs) {
    resetJSONNotesList(jsonNotesData);
    if (jsonObjs.length > 0) {
        //addOptionToSelect(jsonNotesData, "Select a note...", "");
        $(jsonObjs).each(function(){ addOptionToSelect(jsonNotesData, this.title, this.id); });

//↓The following has been modified
//If there is only one file in the selection box, this is what you need to do
        addOptionToSelect(jsonNotesData, "none", "none");
//↑The above has been modified

        onJSONNoteSelect();
    } else 
    { 
        addOptionToSelect(jsonNotesData, "No JSON Notes Found...", ""); 
    }
}