Skip to content
Snippets Groups Projects
Commit e3b2736a authored by vaartis's avatar vaartis
Browse files

Implement emoji pack metadata updating on frontend

parent 4b5eae34
No related branches found
No related tags found
No related merge requests found
This commit is part of merge request !32. Comments created here will be created in the context of that merge request.
...@@ -42,4 +42,15 @@ export async function downloadFrom(host, instance_address, pack_name, as, token) ...@@ -42,4 +42,15 @@ export async function downloadFrom(host, instance_address, pack_name, as, token)
}) })
} }
export async function savePackMetadata(host, token, name, new_data) {
return await request({
baseURL: baseName(host),
url: `/api/pleroma/emoji/packs/update_metadata/${name}`,
method: 'post',
headers: authHeaders(token),
data: { name, new_data },
timeout: 0 // This might take a long time
})
}
const authHeaders = (token) => token ? { 'Authorization': `Bearer ${getToken()}` } : {} const authHeaders = (token) => token ? { 'Authorization': `Bearer ${getToken()}` } : {}
import { listPacks, downloadFrom, reloadEmoji, deletePack } from '@/api/emoji_packs' import { listPacks, downloadFrom, reloadEmoji, deletePack, savePackMetadata } from '@/api/emoji_packs'
import { Message } from 'element-ui' import { Message } from 'element-ui'
const packs = { const packs = {
state: { state: {
localPacks: {}, localPacks: {},
remotePacks: {}, remotePacks: {}
downloadFromState: null
}, },
mutations: { mutations: {
SET_LOCAL_PACKS: (state, packs) => { SET_LOCAL_PACKS: (state, packs) => {
...@@ -15,8 +14,13 @@ const packs = { ...@@ -15,8 +14,13 @@ const packs = {
SET_REMOTE_PACKS: (state, packs) => { SET_REMOTE_PACKS: (state, packs) => {
state.remotePacks = packs state.remotePacks = packs
}, },
SET_DOWNLOAD_FROM_STATE: (state, st) => {
state.downloadFromState = st UPDATE_LOCAL_PACK_VAL: (state, { name, key, value }) => {
state.localPacks[name]['pack'][key] = value
},
UPDATE_LOCAL_PACK: (state, { name, pack }) => {
state.localPacks[name]['pack'] = pack
} }
}, },
actions: { actions: {
...@@ -33,7 +37,7 @@ const packs = { ...@@ -33,7 +37,7 @@ const packs = {
if (result.data === 'ok') { if (result.data === 'ok') {
Message({ Message({
message: `Successfully downlaoded ${packName}`, message: `Successfully downloaded ${packName}`,
type: 'success', type: 'success',
duration: 5 * 1000 duration: 5 * 1000
}) })
...@@ -46,6 +50,32 @@ const packs = { ...@@ -46,6 +50,32 @@ const packs = {
}, },
async DeletePack({ commit, getters, state }, { name }) { async DeletePack({ commit, getters, state }, { name }) {
await deletePack(getters.authHost, getters.token, name) await deletePack(getters.authHost, getters.token, name)
},
async UpdateLocalPackVal({ commit, getters, state }, args) {
commit('UPDATE_LOCAL_PACK_VAL', args)
},
async DeleteLocalPackVals({ commit, getters, state }, args) {
commit('DEL_LOCAL_PACK_VALS', args)
},
async SavePackMetadata({ commit, getters, state }, { packName }) {
const result =
await savePackMetadata(getters.authHost,
getters.token,
packName,
state.localPacks[packName]['pack']
)
if (result.status === 200) {
Message({
message: `Successfully updated ${packName} metadata`,
type: 'success',
duration: 5 * 1000
})
commit('UPDATE_LOCAL_PACK', { name: packName, pack: result.data })
}
} }
} }
} }
......
...@@ -2,18 +2,23 @@ ...@@ -2,18 +2,23 @@
<div> <div>
<h2>{{ name }}</h2> <h2>{{ name }}</h2>
<el-row v-for="(prop, propName) in pack.pack" :key="propName"> <prop-editing-row name="Share pack">
<el-row :gutter="20" class="prop-row"> <el-switch v-model="share" />
<el-col :span="4"> </prop-editing-row>
<b> <prop-editing-row name="Homepage">
{{ propName | prettifyPropName }} <el-input v-model="homepage" />
</b> </prop-editing-row>
</el-col> <prop-editing-row name="Description">
<el-col :span="10"> <el-input :rows="2" v-model="description" type="textarea" />
{{ prop }} </prop-editing-row>
</el-col> <prop-editing-row name="License">
</el-row> <el-input v-model="license" />
</el-row> </prop-editing-row>
<prop-editing-row name="Fallback source">
<el-input v-model="fallbackSrc" />
</prop-editing-row>
<el-button type="success" @click="savePackMetadata">Save pack metadata</el-button>
<el-collapse v-model="shownPackEmoji" class="contents-collapse"> <el-collapse v-model="shownPackEmoji" class="contents-collapse">
<el-collapse-item :name="name" title="Show pack contents"> <el-collapse-item :name="name" title="Show pack contents">
...@@ -82,13 +87,11 @@ ...@@ -82,13 +87,11 @@
</style> </style>
<script> <script>
import PropEditingRow from './PropertyEditingRow.vue'
export default { export default {
filters: {
prettifyPropName(nm) { components: { PropEditingRow },
const capitalized = nm.charAt(0).toUpperCase() + nm.slice(1)
return capitalized.replace(/-/g, ' ')
}
},
props: { props: {
name: { name: {
type: String, type: String,
...@@ -107,12 +110,71 @@ export default { ...@@ -107,12 +110,71 @@ export default {
required: true required: true
} }
}, },
data() { data() {
return { return {
shownPackEmoji: [], shownPackEmoji: [],
downloadSharedAs: '' downloadSharedAs: ''
} }
}, },
computed: {
share: {
get() { return this.pack.pack['share-files'] },
set(value) {
this.$store.dispatch(
'UpdateLocalPackVal',
{ name: this.name, key: 'share-files', value }
)
}
},
homepage: {
get() { return this.pack.pack['homepage'] },
set(value) {
this.$store.dispatch(
'UpdateLocalPackVal',
{ name: this.name, key: 'homepage', value }
)
}
},
description: {
get() { return this.pack.pack['description'] },
set(value) {
this.$store.dispatch(
'UpdateLocalPackVal',
{ name: this.name, key: 'description', value }
)
}
},
license: {
get() { return this.pack.pack['license'] },
set(value) {
this.$store.dispatch(
'UpdateLocalPackVal',
{ name: this.name, key: 'license', value }
)
}
},
fallbackSrc: {
get() { return this.pack.pack['fallback-src'] },
set(value) {
if (value.trim() !== '') {
this.$store.dispatch(
'UpdateLocalPackVal',
{ name: this.name, key: 'fallback-src', value }
)
} else {
this.$store.dispatch(
'UpdateLocalPackVal',
{ name: this.name, key: 'fallback-src', value: null }
)
this.$store.dispatch(
'UpdateLocalPackVal',
{ name: this.name, key: 'fallback-src-sha256', value: null }
)
}
}
}
},
methods: { methods: {
downloadFromInstance() { downloadFromInstance() {
this.$store.dispatch( this.$store.dispatch(
...@@ -132,6 +194,10 @@ export default { ...@@ -132,6 +194,10 @@ export default {
.then(() => this.$store.dispatch('ReloadEmoji')) .then(() => this.$store.dispatch('ReloadEmoji'))
.then(() => this.$store.dispatch('SetLocalEmojiPacks')) .then(() => this.$store.dispatch('SetLocalEmojiPacks'))
}).catch(() => {}) }).catch(() => {})
},
savePackMetadata() {
this.$store.dispatch('SavePackMetadata', { packName: this.name })
} }
} }
} }
......
<template>
<el-row :gutter="20" class="prop-row">
<el-col :span="4">
<b>{{ name }}</b>
</el-col>
<el-col :span="10">
<slot/>
</el-col>
</el-row>
</template>
<style>
.prop-row {
margin-bottom: 1em;
}
</style>
<script>
export default {
props: {
name: {
type: String,
required: true
}
}
}
</script>
...@@ -52,10 +52,6 @@ ...@@ -52,10 +52,6 @@
margin: 22px 0 0 15px; margin: 22px 0 0 15px;
} }
.prop-row {
margin-bottom: 1em;
}
.local-packs-actions { .local-packs-actions {
margin-top: 1em; margin-top: 1em;
margin-bottom: 1em; margin-bottom: 1em;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment