Skip to content

Commit

Permalink
fixed templates loading in drive version
Browse files Browse the repository at this point in the history
  • Loading branch information
ishubin committed Dec 10, 2023
1 parent 2d1298a commit 235b14e
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 14 deletions.
11 changes: 11 additions & 0 deletions src/ui/app/client/clientCommons.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
import axios from "axios";
import { InMemoryCache } from "../../LimitedSettingsStorage";

const templateCache = new InMemoryCache(100);

export function unwrapAxios(response) {
return response.data;
Expand Down Expand Up @@ -26,3 +29,11 @@ export function getExportHTMLResources(assetsPath) {
};
})
}

export function getAllTemplates() {
return axios.get('/assets/templates/index.json').then(unwrapAxios);
}

export function getTemplate(path) {
return templateCache.get(path, () => axios.get(path).then(unwrapAxios));
}
14 changes: 3 additions & 11 deletions src/ui/app/client/fsClient.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
import axios from "axios";
import {forEach} from '../../collections';
import { getCachedSchemeInfo, schemeSearchCacher } from "./clientCache";
import { getExportHTMLResources, unwrapAxios } from "./clientCommons";
import { InMemoryCache } from "../../LimitedSettingsStorage";

const templateCache = new InMemoryCache(100);
import { getAllTemplates, getExportHTMLResources, getTemplate, unwrapAxios } from "./clientCommons";

export const fsClientProvider = {
type: 'fs',
Expand Down Expand Up @@ -77,13 +74,8 @@ export const fsClientProvider = {
return axios.get('/v1/fs/art').then(unwrapAxios);
},

getAllTemplates() {
return axios.get('/assets/templates/index.json').then(unwrapAxios);
},

getTemplate(path) {
return templateCache.get(path, () => axios.get(path).then(unwrapAxios));
},
getAllTemplates,
getTemplate: getTemplate,

saveArt(artId, art) {
return axios.put(`/v1/fs/art/${artId}`, art).then(unwrapAxios);
Expand Down
5 changes: 4 additions & 1 deletion src/ui/app/client/googleDriveClient.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { getExportHTMLResources } from "./clientCommons";
import { getAllTemplates, getExportHTMLResources, getTemplate } from "./clientCommons";
import {forEach, map} from "../../collections";
import { getCachedSchemeInfo, schemeSearchCacher } from "./clientCache";
import { encode } from 'js-base64';
Expand Down Expand Up @@ -235,6 +235,9 @@ export const googleDriveClientProvider = {
});
},

getAllTemplates,
getTemplate,

renameScheme(schemeId, newName) {
return this.renameGoogleFile(schemeId, newName);
},
Expand Down
7 changes: 5 additions & 2 deletions src/ui/app/client/offlineClient.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { getExportHTMLResources } from "./clientCommons";
import { getAllTemplates, getExportHTMLResources, getTemplate } from "./clientCommons";

export const offlineClientProvider = {
type: 'offline',
Expand All @@ -9,7 +9,10 @@ export const offlineClientProvider = {
saveScheme(scheme) {
window.localStorage.setItem('offlineScheme', JSON.stringify(scheme));
return Promise.resolve(scheme);
}
},

getAllTemplates,
getTemplate,
});
}
}

0 comments on commit 235b14e

Please sign in to comment.