diff --git a/routes/_actions/instances.js b/routes/_actions/instances.js index ba3b59d..76eebf5 100644 --- a/routes/_actions/instances.js +++ b/routes/_actions/instances.js @@ -33,8 +33,7 @@ export async function logOutOfInstance (instanceName) { let loggedInInstances = store.get('loggedInInstances') let instanceThemes = store.get('instanceThemes') let loggedInInstancesInOrder = store.get('loggedInInstancesInOrder') - let composeText = store.get('composeText') - let uploadedMedia = store.get('uploadedMedia') + let composeData = store.get('composeData') let currentInstance = store.get('currentInstance') loggedInInstancesInOrder.splice(loggedInInstancesInOrder.indexOf(instanceName), 1) let newInstance = instanceName === currentInstance @@ -42,8 +41,7 @@ export async function logOutOfInstance (instanceName) { : currentInstance delete loggedInInstances[instanceName] delete instanceThemes[instanceName] - delete composeText[instanceName] - delete uploadedMedia[instanceName] + delete composeData[instanceName] store.set({ loggedInInstances: loggedInInstances, instanceThemes: instanceThemes, @@ -52,8 +50,7 @@ export async function logOutOfInstance (instanceName) { searchResults: null, queryInSearch: '', rawComposeText: '', - composeText: composeText, - uploadedMedia: uploadedMedia + composeData: composeData }) store.save() toast.say(`Logged out of ${instanceName}`) diff --git a/routes/_actions/media.js b/routes/_actions/media.js index 7ad9c7b..4068d42 100644 --- a/routes/_actions/media.js +++ b/routes/_actions/media.js @@ -9,21 +9,15 @@ export async function doMediaUpload (realm, file) { store.set({uploadingMedia: true}) try { let response = await uploadMedia(instanceName, accessToken, file) - let uploadedMedia = store.get('uploadedMedia') - uploadedMedia[instanceName] = uploadedMedia[instanceName] || {} - uploadedMedia[instanceName][realm] = uploadedMedia[instanceName][realm] || [] - uploadedMedia[instanceName][realm].push({ + let composeMedia = store.getComposeData(realm, 'media') || [] + composeMedia.push({ data: response, - file: { - name: file.name - } + file: { name: file.name } }) let rawComposeText = store.get('rawComposeText') || '' rawComposeText += ' ' + response.text_url - store.set({ - uploadedMedia, - rawComposeText - }) + store.setComposeData(realm, 'media', composeMedia) + store.set({rawComposeText}) scheduleIdleTask(() => store.save()) } catch (e) { console.error(e) @@ -34,18 +28,14 @@ export async function doMediaUpload (realm, file) { } export function deleteMedia (realm, i) { - let uploadedMedia = store.get('uploadedMedia') - let instanceName = store.get('currentInstance') - let uploadedMediaArray = uploadedMedia[instanceName][realm] - let deletedMedia = uploadedMediaArray.splice(i, 1)[0] + let composeMedia = store.getComposeData(realm, 'media') + let deletedMedia = composeMedia.splice(i, 1)[0] let rawComposeText = store.get('rawComposeText') || '' rawComposeText = rawComposeText.replace(' ' + deletedMedia.data.text_url, '') - store.set({ - uploadedMedia, - rawComposeText - }) + store.setComposeData(realm, 'media', composeMedia) + store.set({rawComposeText}) scheduleIdleTask(() => store.save()) } diff --git a/routes/_actions/postPrivacy.js b/routes/_actions/postPrivacy.js new file mode 100644 index 0000000..753b226 --- /dev/null +++ b/routes/_actions/postPrivacy.js @@ -0,0 +1,6 @@ + +import { store } from '../_store/store' + +export function setPostPrivacy (realm, postPrivacyKey) { + store.setComposeData(realm, 'postPrivacy', postPrivacyKey) +} diff --git a/routes/_components/compose/ComposeInput.html b/routes/_components/compose/ComposeInput.html index f46f05f..35ca2bf 100644 --- a/routes/_components/compose/ComposeInput.html +++ b/routes/_components/compose/ComposeInput.html @@ -41,22 +41,17 @@ }, methods: { setupSyncFromStore() { - let currentComposeText = store.get('currentComposeText') - let realm = this.get('realm') + let composeText = this.get('composeText') this.store.set({ - rawComposeText: currentComposeText[realm] || '' + rawComposeText: composeText }) }, setupSyncToStore() { const saveText = debounce(() => scheduleIdleTask(() => this.store.save()), 1000) this.observe('rawComposeText', rawComposeText => { - let composeText = this.store.get('composeText') - let currentInstance = this.store.get('currentInstance') let realm = this.get('realm') - composeText[currentInstance] = composeText[currentInstance] || {} - composeText[currentInstance][realm] = rawComposeText || '' - this.store.set({composeText: composeText}) + this.store.setComposeData(realm, 'text', rawComposeText) saveText() }, {init: false}) }, @@ -79,8 +74,8 @@ store: () => store, computed: { rawComposeText: ($rawComposeText) => $rawComposeText, - currentComposeText: ($currentComposeText) => $currentComposeText, - uploadedMedia: ($currentUploadedMedia, realm) => $currentUploadedMedia[realm] || [] + composeData: ($currentComposeData, realm) => $currentComposeData[realm] || {}, + composeText: (composeData) => composeData.text || '' } } \ No newline at end of file diff --git a/routes/_components/compose/ComposeMedia.html b/routes/_components/compose/ComposeMedia.html index b2126dd..fb762fe 100644 --- a/routes/_components/compose/ComposeMedia.html +++ b/routes/_components/compose/ComposeMedia.html @@ -1,6 +1,6 @@ -{{#if uploadedMedia.length}} -