From 04d2f4bcca406ddc485a185cbb077c4333256b97 Mon Sep 17 00:00:00 2001 From: Angelina Filippova Date: Sun, 21 Feb 2021 18:04:41 +0300 Subject: [PATCH] Fetch the list of frontends and save them in state --- src/api/settings.js | 19 +++++++++++++++++++ src/store/modules/settings.js | 9 +++++++++ src/views/settings/components/Frontend.vue | 3 +++ 3 files changed, 31 insertions(+) diff --git a/src/api/settings.js b/src/api/settings.js index 8c543a7e..8596d18a 100644 --- a/src/api/settings.js +++ b/src/api/settings.js @@ -68,4 +68,23 @@ export async function removeSettings(configs, authHost, token) { }) } +export async function fetchFrontends(authHost, token) { + return await request({ + baseURL: baseName(authHost), + url: `/api/pleroma/admin/frontends`, + method: 'get', + headers: authHeaders(token) + }) +} + +export async function installFrontend(name, ref, file, buildUrl, buildDir, authHost, token) { + return await request({ + baseURL: baseName(authHost), + url: `/api/pleroma/admin/frontends/install`, + method: 'post', + headers: authHeaders(token), + data: { name, ref, file, build_url: buildUrl, build_dir: buildDir } + }) +} + const authHeaders = (token) => token ? { 'Authorization': `Bearer ${getToken()}` } : {} diff --git a/src/store/modules/settings.js b/src/store/modules/settings.js index 6e30a21f..df664689 100644 --- a/src/store/modules/settings.js +++ b/src/store/modules/settings.js @@ -1,6 +1,7 @@ import { deleteInstanceDocument, fetchDescription, + fetchFrontends, fetchSettings, getInstanceDocument, removeSettings, @@ -13,6 +14,7 @@ const settings = { state: { activeTab: 'instance', configDisabled: true, + frontends: [], db: {}, description: [], instancePanel: '', @@ -41,6 +43,9 @@ const settings = { SET_DESCRIPTION: (state, data) => { state.description = data }, + SET_FRONTENDS: (state, data) => { + state.frontends = data + }, SET_LOADING: (state, status) => { state.loading = status }, @@ -86,6 +91,10 @@ const settings = { } }, actions: { + async FetchFrontends({ commit, getters }) { + const { data } = await fetchFrontends(getters.authHost, getters.token) + commit('SET_FRONTENDS', data) + }, async FetchInstanceDocument({ commit, getters }, name) { const { data } = await getInstanceDocument(name, getters.authHost, getters.token) if (name === 'instance-panel') { diff --git a/src/views/settings/components/Frontend.vue b/src/views/settings/components/Frontend.vue index 894f8f51..ea341498 100644 --- a/src/views/settings/components/Frontend.vue +++ b/src/views/settings/components/Frontend.vue @@ -123,6 +123,9 @@ export default { return _.get(this.settings.settings, [':pleroma', ':static_fe']) || {} } }, + async mounted() { + await this.$store.dispatch('FetchFrontends') + }, methods: { async onSubmit() { try {