Skip to content

Commit

Permalink
update files when loading changes from gist
Browse files Browse the repository at this point in the history
  • Loading branch information
blurymind committed Sep 6, 2024
1 parent b622881 commit e7ecfac
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
7 changes: 4 additions & 3 deletions src/public/plugins/resources-editor.js
Original file line number Diff line number Diff line change
Expand Up @@ -186,15 +186,16 @@ export var ResourcesEditor = function({
document.querySelector('resources-component').addEventListener('headerButtonClicked', ({detail: action}) => {
if(action === 'pull') {
this.isBusy('Downloading changes to gist...');
this.getFromGist().then(resolve => {
document.querySelector('resources-component').updateResourcesList(resolve.content);
this.getFromGist().then(file => {
document.querySelector('resources-component').updateResourcesList(file.content);
ToastWc.show({
type: 'success',
content: `Re-Downloaded resources.json file`,
time: 3000,
});
this.isBusy('');
document.querySelector('resources-component').updateRawUrl(resolve.raw_url);
document.querySelector('resources-component').setFileContent(file);
this.setVolatileResource(file);
}).catch(() => {
ToastWc.show({
type: 'error',
Expand Down
9 changes: 6 additions & 3 deletions src/public/web-components.js
Original file line number Diff line number Diff line change
Expand Up @@ -432,17 +432,20 @@ class ResourcesComponent extends HTMLElement {
shadowRoot.getElementById('resource-file-buttons').style.pointerEvents = isLocked ? 'none' : 'auto';
shadowRoot.getElementById('resource-file-buttons').style.opacity = isLocked ? '0.8' : '1';
}
this.setFileContent = (file) => {
this.updateRawUrl(file.raw_url);
this.resourcesFileContent = file.content || '{}';
this.updateResourcesList(this.resourcesFileContent, !file.raw_url);
}
}

init({ file, darkMode, headerButtons, gistId }) {//todo you cannot pass functions to web components, but can use events?
console.log({ file, darkMode, headerButtons, gistId })
this.resourcesFileContent = file.content || '{}';
const shadowRoot = document.querySelector('resources-component').shadowRoot;
this.updateRawUrl(file.raw_url);
this.setFileContent(file);
shadowRoot.getElementById('gistIdFileLink').href = gistId || '';
if(!gistId) shadowRoot.getElementById('gistIdFileLink').innerText = 'Gist is missing'
if (darkMode) shadowRoot.getElementById('resources-editor').setAttribute("data-theme", "dark");
this.updateResourcesList(this.resourcesFileContent, !file.raw_url);
if(headerButtons) {
headerButtons.forEach(button => {
const el = document.createElement('button', {id: button.action});
Expand Down

0 comments on commit e7ecfac

Please sign in to comment.