add media URLs when media is inserted
This commit is contained in:
parent
c2738b7f68
commit
d4e770c28d
|
@ -1,6 +1,7 @@
|
||||||
import { store } from '../_store/store'
|
import { store } from '../_store/store'
|
||||||
import { uploadMedia } from '../_api/media'
|
import { uploadMedia } from '../_api/media'
|
||||||
import { toast } from '../_utils/toast'
|
import { toast } from '../_utils/toast'
|
||||||
|
import { scheduleIdleTask } from '../_utils/scheduleIdleTask'
|
||||||
|
|
||||||
export async function doMediaUpload (realm, file) {
|
export async function doMediaUpload (realm, file) {
|
||||||
let instanceName = store.get('currentInstance')
|
let instanceName = store.get('currentInstance')
|
||||||
|
@ -13,9 +14,17 @@ export async function doMediaUpload (realm, file) {
|
||||||
uploadedMedia[instanceName][realm] = uploadedMedia[instanceName][realm] || []
|
uploadedMedia[instanceName][realm] = uploadedMedia[instanceName][realm] || []
|
||||||
uploadedMedia[instanceName][realm].push({
|
uploadedMedia[instanceName][realm].push({
|
||||||
data: response,
|
data: response,
|
||||||
file: file
|
file: {
|
||||||
|
name: file.name
|
||||||
|
}
|
||||||
})
|
})
|
||||||
store.set({ uploadedMedia })
|
let rawComposeText = store.get('rawComposeText') || ''
|
||||||
|
rawComposeText += ' ' + response.text_url
|
||||||
|
store.set({
|
||||||
|
uploadedMedia,
|
||||||
|
rawComposeText
|
||||||
|
})
|
||||||
|
scheduleIdleTask(() => store.save())
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.error(e)
|
console.error(e)
|
||||||
toast.say('Failed to upload media: ' + (e.message || ''))
|
toast.say('Failed to upload media: ' + (e.message || ''))
|
||||||
|
@ -28,7 +37,15 @@ export function deleteMedia (realm, i) {
|
||||||
let uploadedMedia = store.get('uploadedMedia')
|
let uploadedMedia = store.get('uploadedMedia')
|
||||||
let instanceName = store.get('currentInstance')
|
let instanceName = store.get('currentInstance')
|
||||||
let uploadedMediaArray = uploadedMedia[instanceName][realm]
|
let uploadedMediaArray = uploadedMedia[instanceName][realm]
|
||||||
|
let deletedMedia = uploadedMediaArray.splice(i, 1)[0]
|
||||||
|
|
||||||
uploadedMediaArray.splice(i, 1)
|
let rawComposeText = store.get('rawComposeText') || ''
|
||||||
store.set({uploadedMedia})
|
|
||||||
|
rawComposeText = rawComposeText.replace(' ' + deletedMedia.data.text_url, '')
|
||||||
|
|
||||||
|
store.set({
|
||||||
|
uploadedMedia,
|
||||||
|
rawComposeText
|
||||||
|
})
|
||||||
|
scheduleIdleTask(() => store.save())
|
||||||
}
|
}
|
||||||
|
|
|
@ -79,7 +79,8 @@
|
||||||
store: () => store,
|
store: () => store,
|
||||||
computed: {
|
computed: {
|
||||||
rawComposeText: ($rawComposeText) => $rawComposeText,
|
rawComposeText: ($rawComposeText) => $rawComposeText,
|
||||||
currentComposeText: ($currentComposeText) => $currentComposeText
|
currentComposeText: ($currentComposeText) => $currentComposeText,
|
||||||
|
uploadedMedia: ($currentUploadedMedia, realm) => $currentUploadedMedia[realm] || []
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
|
@ -14,7 +14,8 @@ const KEYS_TO_STORE_IN_LOCAL_STORAGE = new Set([
|
||||||
'autoplayGifs',
|
'autoplayGifs',
|
||||||
'markMediaAsSensitive',
|
'markMediaAsSensitive',
|
||||||
'pinnedPages',
|
'pinnedPages',
|
||||||
'composeText'
|
'composeText',
|
||||||
|
'uploadedMedia'
|
||||||
])
|
])
|
||||||
|
|
||||||
class PinaforeStore extends LocalStorageStore {
|
class PinaforeStore extends LocalStorageStore {
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
import { getNthDeleteMediaButton, getNthMedia, mediaButton, uploadKittenImage } from '../utils'
|
import { composeInput, getNthDeleteMediaButton, getNthMedia, mediaButton, uploadKittenImage } from '../utils'
|
||||||
import { foobarRole } from '../roles'
|
import { foobarRole } from '../roles'
|
||||||
|
|
||||||
fixture`13-compose-media.js`
|
fixture`13-compose-media.js`
|
||||||
|
@ -39,4 +39,18 @@ test('removes media', async t => {
|
||||||
.click(getNthDeleteMediaButton(2))
|
.click(getNthDeleteMediaButton(2))
|
||||||
.expect(getNthMedia(2).exists).notOk()
|
.expect(getNthMedia(2).exists).notOk()
|
||||||
.expect(getNthMedia(1).exists).ok()
|
.expect(getNthMedia(1).exists).ok()
|
||||||
|
.click(getNthDeleteMediaButton(1))
|
||||||
|
.expect(getNthMedia(2).exists).notOk()
|
||||||
|
})
|
||||||
|
|
||||||
|
test('changes URLs as media is added/removed', async t => {
|
||||||
|
await t.useRole(foobarRole)
|
||||||
|
await (uploadKittenImage(1)())
|
||||||
|
await t.expect(composeInput.value).match(/^ http:\/\/localhost:3000\/media\/\S+$/)
|
||||||
|
await (uploadKittenImage(1)())
|
||||||
|
await t.expect(composeInput.value).match(/^ http:\/\/localhost:3000\/media\/\S+ http:\/\/localhost:3000\/media\/\S+$/)
|
||||||
|
.click(getNthDeleteMediaButton(1))
|
||||||
|
.expect(composeInput.value).match(/^ http:\/\/localhost:3000\/media\/\S+$/)
|
||||||
|
.click(getNthDeleteMediaButton(1))
|
||||||
|
.expect(composeInput.value).eql('')
|
||||||
})
|
})
|
||||||
|
|
Loading…
Reference in New Issue