diff --git a/src/components/settings_modal/helpers/choice_setting.js b/src/components/settings_modal/helpers/choice_setting.js index 4677d4c1..48cee348 100644 --- a/src/components/settings_modal/helpers/choice_setting.js +++ b/src/components/settings_modal/helpers/choice_setting.js @@ -12,7 +12,8 @@ export default { 'path', 'disabled', 'options', - 'expert' + 'expert', + 'hideDefaultLabel' ], computed: { pathDefault () { diff --git a/src/components/settings_modal/helpers/choice_setting.vue b/src/components/settings_modal/helpers/choice_setting.vue index 258c7422..8b1dd614 100644 --- a/src/components/settings_modal/helpers/choice_setting.vue +++ b/src/components/settings_modal/helpers/choice_setting.vue @@ -16,7 +16,11 @@ :value="option.value" > {{ option.label }} - {{ option.value === defaultState ? $t('settings.instance_default_simple') : '' }} + diff --git a/src/components/settings_modal/tabs/general_tab.js b/src/components/settings_modal/tabs/general_tab.js index c915c32c..025d7f1e 100644 --- a/src/components/settings_modal/tabs/general_tab.js +++ b/src/components/settings_modal/tabs/general_tab.js @@ -48,6 +48,8 @@ const GeneralTab = { value: tab, label: this.$t(`user_card.${tab}`) })), + profilesExpanded: false, + newProfileName: '', loopSilentAvailable: // Firefox Object.getOwnPropertyDescriptor(HTMLVideoElement.prototype, 'mozHasAudio') || @@ -88,6 +90,19 @@ const GeneralTab = { this.$store.dispatch('setOption', { name: 'interfaceLanguage', value: val }) } }, + settingsProfiles () { + return (this.$store.state.instance.settingsProfiles || []) + }, + settingsProfile: { + get: function () { return this.$store.getters.mergedConfig.profile }, + set: function (val) { + this.$store.dispatch('setOption', { name: 'profile', value: val }) + this.$store.dispatch('getSettingsProfile') + } + }, + settingsVersion () { + return this.$store.getters.mergedConfig.profileVersion + }, translationLanguages () { return (this.$store.state.instance.supportedTranslationLanguages.target || []).map(lang => ({ key: lang.code, value: lang.code, label: lang.name })) }, @@ -105,6 +120,19 @@ const GeneralTab = { }, setTranslationLanguage (value) { this.$store.dispatch('setOption', { name: 'translationLanguage', value }) + }, + toggleExpandedSettings () { + this.profilesExpanded = !this.profilesExpanded + }, + loadSettingsProfile (name) { + this.$store.commit('setOption', { name: 'profile', value: name }) + this.$store.dispatch('getSettingsProfile', true) + }, + createSettingsProfile () { + this.$store.dispatch('setOption', { name: 'profile', value: this.newProfileName }) + this.$store.dispatch('setOption', { name: 'profileVersion', value: 1 }) + this.$store.dispatch('syncSettings') + this.newProfileName = '' } } } diff --git a/src/components/settings_modal/tabs/general_tab.vue b/src/components/settings_modal/tabs/general_tab.vue index 608c73af..479cb1d3 100644 --- a/src/components/settings_modal/tabs/general_tab.vue +++ b/src/components/settings_modal/tabs/general_tab.vue @@ -1,7 +1,6 @@ + diff --git a/src/i18n/en.json b/src/i18n/en.json index af66f2ae..750b41c2 100644 --- a/src/i18n/en.json +++ b/src/i18n/en.json @@ -693,6 +693,14 @@ "setting_changed": "Setting is different from default", "setting_server_side": "This setting is tied to your profile and affects all sessions and clients", "settings": "Settings", + "settings_profile": "Settings Profiles", + "settings_profile_currently": "Currently using {name} (version: {version})", + "settings_profiles_show": "Show all settings profiles", + "settings_profiles_unshow": "Hide all settings profiles", + "settings_profile_in_use": "In use", + "settings_profile_creation": "Create new profile", + "settings_profile_creation_submit": "Create", + "settings_profile_use": "Use", "show_admin_badge": "Show \"Admin\" badge in my profile", "show_moderator_badge": "Show \"Moderator\" badge in my profile", "show_nav_shortcuts": "Show extra navigation shortcuts in top panel", diff --git a/src/modules/api.js b/src/modules/api.js index 30060911..496580c1 100644 --- a/src/modules/api.js +++ b/src/modules/api.js @@ -265,6 +265,12 @@ const api = { store.dispatch('setInstanceOption', { name: 'supportedTranslationLanguages', value: data }) }) }, + listSettingsProfiles (store) { + store.state.backendInteractor.listSettingsProfiles({ store }) + .then((data) => { + store.commit('setInstanceOption', { name: 'settingsProfiles', value: data }) + }) + }, // Pleroma websocket setWsToken (store, token) { store.commit('setWsToken', token) diff --git a/src/modules/config.js b/src/modules/config.js index f0055c3c..81ebb031 100644 --- a/src/modules/config.js +++ b/src/modules/config.js @@ -232,15 +232,19 @@ const config = { break } }, - getSettingsProfile (store) { + getSettingsProfile (store, forceUpdate = false) { console.log('getSettingsProfile') const profile = store.state.profile store.rootState.api.backendInteractor.getSettingsProfile({ store, profileName: profile }) .then(({ settings, version }) => { console.log('found settings version', version) - if (version > store.state.profileVersion) { + if (forceUpdate || (version > store.state.profileVersion)) { store.commit('setOption', { name: 'profileVersion', value: version }) - store.dispatch('loadSettings', settings) + Object.entries(settings).forEach(([name, value]) => { + if (store.state[name] !== value) { + store.dispatch('setOption', { name, value }) + } + }) } else { console.log('settings are up to date') } diff --git a/src/modules/users.js b/src/modules/users.js index f51d9717..94321839 100644 --- a/src/modules/users.js +++ b/src/modules/users.js @@ -583,6 +583,7 @@ const users = { store.dispatch('setLayoutHeight', windowHeight()) store.dispatch('getSupportedTranslationlanguages') store.dispatch('getSettingsProfile') + store.dispatch('listSettingsProfiles') // Fetch our friends store.rootState.api.backendInteractor.fetchFriends({ id: user.id }) diff --git a/src/services/api/api.service.js b/src/services/api/api.service.js index 319277e3..e7a8c812 100644 --- a/src/services/api/api.service.js +++ b/src/services/api/api.service.js @@ -103,6 +103,7 @@ const PLEROMA_POST_ANNOUNCEMENT_URL = '/api/v1/pleroma/admin/announcements' const PLEROMA_EDIT_ANNOUNCEMENT_URL = id => `/api/v1/pleroma/admin/announcements/${id}` const PLEROMA_DELETE_ANNOUNCEMENT_URL = id => `/api/v1/pleroma/admin/announcements/${id}` const AKKOMA_SETTING_PROFILE_URL = (name) => `/api/v1/akkoma/frontend_settings/pleroma-fe/${name}` +const AKKOMA_SETTING_PROFILE_LIST = `/api/v1/akkoma/frontend_settings/pleroma-fe` const oldfetch = window.fetch @@ -1471,6 +1472,13 @@ const saveSettingsProfile = ({ profileName, credentials, settings, version }) => }) } +const listSettingsProfiles = ({ credentials }) => { + return promisedRequest({ + url: AKKOMA_SETTING_PROFILE_LIST, + credentials + }) +} + export const getMastodonSocketURI = ({ credentials, stream, args = {} }) => { return Object.entries({ ...(credentials @@ -1699,7 +1707,8 @@ const apiService = { translateStatus, getSupportedTranslationlanguages, getSettingsProfile, - saveSettingsProfile + saveSettingsProfile, + listSettingsProfiles } export default apiService