Skip to content

Commit

Permalink
resources component bugs with state
Browse files Browse the repository at this point in the history
  • Loading branch information
blurymind committed Sep 13, 2024
1 parent e37ddce commit ce4c937
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
12 changes: 8 additions & 4 deletions src/public/plugins/resources-editor.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,10 +73,12 @@ export var ResourcesEditor = function({
}
// resource in local or at gist
this.initResourcesFile = (createVolatile = false) => {
console.log({INITWITH: this.selectedResourcesJson})
this.selectedResourcesJson = 'resources.res.json';//todo use url param, also needs to update list here - it doesnt
return new Promise((resolve, reject) => {
const getOrCreateVolatile = () => {
return getVloatileResource().then(volatile => {
if(volatile && volatile.content) {
if(volatile && volatile.content) {
resolve(volatile);
return
}
Expand All @@ -89,6 +91,7 @@ export var ResourcesEditor = function({
resolve(newFile);
return
}
this.onUpdateResourcesList();
return this.createOrEditGistFile(resolve, reject);
})
}
Expand All @@ -98,7 +101,7 @@ export var ResourcesEditor = function({
return getOrCreateVolatile()
})
}
this.onUpdateResourcesList();
// this.onUpdateResourcesList();
return getOrCreateVolatile();
})
});
Expand All @@ -122,7 +125,7 @@ export var ResourcesEditor = function({
});
this.resourcesFileUrl = file.raw_url;
document.querySelector('resources-component').setIsNew(false);
document.querySelector('resources-component').updateRawUrl(file.raw_url);
document.querySelector('resources-component').setFileContent(file);
} else {
ToastWc.show({
type: 'error',
Expand Down Expand Up @@ -213,7 +216,7 @@ export var ResourcesEditor = function({
console.log('Set', {fileName, file})
document.querySelector('resources-component').updateResourcesList(file.content);
document.getElementById("edited-resources").value = this.selectedResourcesJson;
document.querySelector('resources-component').updateRawUrl(file.raw_url);
document.querySelector('resources-component').setFileContent(file);
});
}
this.onAddNewFile = () => {
Expand Down Expand Up @@ -341,6 +344,7 @@ export var ResourcesEditor = function({
}
});
this.initResourcesComponent = (file) => {
console.log('INIT RES', {file})
updateUrlParams('selectedResource', 'none');
document.querySelector('resources-component').init({
file,
Expand Down
2 changes: 1 addition & 1 deletion src/public/web-components.js
Original file line number Diff line number Diff line change
Expand Up @@ -601,7 +601,7 @@ class ResourcesComponent extends HTMLElement {
console.log({fakeSelect, allSelected, specificFileId})
this.isBusy('Removing files...');
const fileData = JSON.parse(this.resourcesFileContent);
if(specificFileId && !(specificFileId instanceof PointerEvent)) {
if(specificFileId && typeof specificFileId === 'string') {
console.log({allSelected, specificFileId})
this.selectAfterUpdate = Object.values(allSelected).filter(item => item.id !== specificFileId);
delete fileData[specificFileId];
Expand Down

0 comments on commit ce4c937

Please sign in to comment.