From 3dc46791e9ded2e5435a39efb82ea277d8a3a78d Mon Sep 17 00:00:00 2001 From: Nolan Lawson Date: Sat, 3 Mar 2018 14:51:48 -0800 Subject: [PATCH] refactor --- routes/_actions/emoji.js | 8 +++--- routes/_actions/instances.js | 4 +-- routes/_actions/media.js | 21 ++++++++------- routes/_actions/postPrivacy.js | 2 +- routes/_components/compose/ComposeBox.html | 26 ++++++++++++++----- routes/_components/compose/ComposeButton.html | 4 +-- routes/_components/compose/ComposeInput.html | 19 ++++++-------- .../compose/ComposeLengthGauge.html | 10 +++---- .../compose/ComposeLengthIndicator.html | 26 +++++++++---------- routes/_components/compose/ComposeMedia.html | 19 +++++--------- .../_components/compose/ComposeToolbar.html | 14 ++-------- routes/_components/dialog/EmojiDialog.html | 2 +- routes/_components/dialog/showEmojiDialog.js | 5 ++-- routes/_store/computations/computations.js | 2 -- .../_store/computations/statusComputations.js | 14 ---------- routes/_store/mixins/instanceMixins.js | 7 +++-- routes/_store/store.js | 1 - 17 files changed, 81 insertions(+), 103 deletions(-) delete mode 100644 routes/_store/computations/statusComputations.js diff --git a/routes/_actions/emoji.js b/routes/_actions/emoji.js index 89da8601..2ced1a98 100644 --- a/routes/_actions/emoji.js +++ b/routes/_actions/emoji.js @@ -17,13 +17,11 @@ export async function updateCustomEmojiForInstance (instanceName) { ) } -export function insertEmoji (emoji) { +export function insertEmoji (realm, emoji) { let idx = store.get('composeSelectionStart') || 0 - let oldText = store.get('rawComposeText') || '' + let oldText = store.getComposeData(realm, 'text') let pre = oldText ? substring(oldText, 0, idx) : '' let post = oldText ? substring(oldText, idx) : '' let newText = `${pre}:${emoji.shortcode}: ${post}` - store.set({ - rawComposeText: newText - }) + store.setComposeData(realm, {text: newText}) } diff --git a/routes/_actions/instances.js b/routes/_actions/instances.js index 76eebf57..30574a87 100644 --- a/routes/_actions/instances.js +++ b/routes/_actions/instances.js @@ -22,8 +22,7 @@ export function switchToInstance (instanceName) { store.set({ currentInstance: instanceName, searchResults: null, - queryInSearch: '', - rawComposeText: '' + queryInSearch: '' }) store.save() switchToTheme(instanceThemes[instanceName]) @@ -49,7 +48,6 @@ export async function logOutOfInstance (instanceName) { currentInstance: newInstance, searchResults: null, queryInSearch: '', - rawComposeText: '', composeData: composeData }) store.save() diff --git a/routes/_actions/media.js b/routes/_actions/media.js index 4068d423..14bc322f 100644 --- a/routes/_actions/media.js +++ b/routes/_actions/media.js @@ -14,10 +14,12 @@ export async function doMediaUpload (realm, file) { data: response, file: { name: file.name } }) - let rawComposeText = store.get('rawComposeText') || '' - rawComposeText += ' ' + response.text_url - store.setComposeData(realm, 'media', composeMedia) - store.set({rawComposeText}) + let composeText = store.getComposeData(realm, 'text') || '' + composeText += ' ' + response.text_url + store.setComposeData(realm, { + media: composeMedia, + text: composeText + }) scheduleIdleTask(() => store.save()) } catch (e) { console.error(e) @@ -31,11 +33,12 @@ export function deleteMedia (realm, i) { let composeMedia = store.getComposeData(realm, 'media') let deletedMedia = composeMedia.splice(i, 1)[0] - let rawComposeText = store.get('rawComposeText') || '' + let composeText = store.getComposeData(realm, 'text') || '' + composeText = composeText.replace(' ' + deletedMedia.data.text_url, '') - rawComposeText = rawComposeText.replace(' ' + deletedMedia.data.text_url, '') - - store.setComposeData(realm, 'media', composeMedia) - store.set({rawComposeText}) + store.setComposeData(realm, { + media: composeMedia, + text: composeText + }) scheduleIdleTask(() => store.save()) } diff --git a/routes/_actions/postPrivacy.js b/routes/_actions/postPrivacy.js index 753b2263..054bea6c 100644 --- a/routes/_actions/postPrivacy.js +++ b/routes/_actions/postPrivacy.js @@ -2,5 +2,5 @@ import { store } from '../_store/store' export function setPostPrivacy (realm, postPrivacyKey) { - store.setComposeData(realm, 'postPrivacy', postPrivacyKey) + store.setComposeData(realm, {postPrivacy: postPrivacyKey}) } diff --git a/routes/_components/compose/ComposeBox.html b/routes/_components/compose/ComposeBox.html index da45ecfe..3b6825c7 100644 --- a/routes/_components/compose/ComposeBox.html +++ b/routes/_components/compose/ComposeBox.html @@ -1,11 +1,11 @@
- - - - - - + + + + + +