This commit is contained in:
Nolan Lawson 2018-03-03 14:15:50 -08:00
parent 35282666cc
commit 66801fbc96
19 changed files with 79 additions and 77 deletions

View File

@ -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}`)

View File

@ -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())
}

View File

@ -0,0 +1,6 @@
import { store } from '../_store/store'
export function setPostPrivacy (realm, postPrivacyKey) {
store.setComposeData(realm, 'postPrivacy', postPrivacyKey)
}

View File

@ -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 || ''
}
}
</script>

View File

@ -1,6 +1,6 @@
{{#if uploadedMedia.length}}
<div class="compose-media-container" style="grid-template-columns: repeat({{uploadedMedia.length}}, 1fr);">
{{#each uploadedMedia as media, i}}
{{#if composeMedia.length}}
<div class="compose-media-container" style="grid-template-columns: repeat({{composeMedia.length}}, 1fr);">
{{#each composeMedia as media, i}}
<div class="compose-media">
<img src="{{media.data.preview_url}}" alt="{{media.file.name}}"/>
<div class="compose-media-delete">
@ -100,7 +100,8 @@
}
},
computed: {
uploadedMedia: ($currentUploadedMedia, realm) => $currentUploadedMedia[realm] || []
composeData: ($currentComposeData, realm) => $currentComposeData[realm] || {},
composeMedia: (composeData) => composeData.media || []
}
}
</script>

View File

@ -9,7 +9,7 @@
label="Add media"
href="{{$uploadingMedia ? '#fa-spinner' : '#fa-camera'}}"
on:click="onMediaClick()"
disabled="{{$uploadingMedia || (uploadedMedia.length === 4)}}"
disabled="{{$uploadingMedia || (composeMedia.length === 4)}}"
/>
<IconButton
label="Adjust privacy (currently {{postPrivacy.label}})"
@ -78,12 +78,13 @@
}
},
computed: {
uploadedMedia: ($currentUploadedMedia, realm) => $currentUploadedMedia[realm] || [],
composeData: ($currentComposeData, realm) => $currentComposeData[realm] || {},
composeMedia: (composeData) => composeData.media || [],
postPrivacy: (postPrivacyKey) => {
return POST_PRIVACY_OPTIONS.find(_ => _.key === postPrivacyKey)
},
postPrivacyKey: ($currentPostPrivacy, $currentVerifyCredentials, realm) => {
return $currentPostPrivacy[realm] || $currentVerifyCredentials.source.privacy
postPrivacyKey: (composeData, $currentVerifyCredentials) => {
return composeData.postPrivacy || $currentVerifyCredentials.source.privacy
}
}
}

View File

@ -60,6 +60,7 @@
import ModalDialog from './ModalDialog.html'
import { store } from '../../_store/store'
import { POST_PRIVACY_OPTIONS } from '../../_static/statuses'
import { setPostPrivacy } from '../../_actions/postPrivacy'
export default {
components: {
@ -77,21 +78,17 @@
this.set({shown: true})
},
onClick(option) {
let postPrivacy = store.get('postPrivacy')
let instanceName = store.get('currentInstance')
let realm = this.get('realm')
postPrivacy[instanceName] = postPrivacy[instanceName] || {}
postPrivacy[instanceName][realm] = option.key
store.set({postPrivacy})
setPostPrivacy(this.get('realm'), option.key)
this.set({closed: true})
}
},
computed: {
composeData: ($currentComposeData, realm) => $currentComposeData[realm] || {},
postPrivacy: (postPrivacyKey) => {
return POST_PRIVACY_OPTIONS.find(_ => _.key === postPrivacyKey)
},
postPrivacyKey: ($currentPostPrivacy, $currentVerifyCredentials, realm) => {
return $currentPostPrivacy[realm] || $currentVerifyCredentials.source.privacy
postPrivacyKey: (composeData, $currentVerifyCredentials) => {
return composeData.postPrivacy || $currentVerifyCredentials.source.privacy
}
}
}

View File

@ -11,10 +11,8 @@ export function instanceComputations (store) {
computeForInstance(store, 'pinnedPage', 'pinnedPages', '/local')
computeForInstance(store, 'lists', 'instanceLists', [])
computeForInstance(store, 'currentStatusModifications', 'statusModifications', null)
computeForInstance(store, 'currentComposeText', 'composeText', {})
computeForInstance(store, 'currentUploadedMedia', 'uploadedMedia', {})
computeForInstance(store, 'currentCustomEmoji', 'customEmoji', [])
computeForInstance(store, 'currentPostPrivacy', 'postPrivacy', {})
computeForInstance(store, 'currentComposeData', 'composeData', {})
store.compute(
'isUserLoggedIn',

View File

@ -1,5 +1,5 @@
import { CHAR_LIMIT } from '../_static/statuses'
import { measureText } from '../_utils/measureText'
import { CHAR_LIMIT } from '../../_static/statuses'
import { measureText } from '../../_utils/measureText'
export function statusComputations (store) {
store.compute('rawComposeTextLength',

View File

@ -0,0 +1,18 @@
export function instanceMixins (Store) {
Store.prototype.setComposeData = function (realm, key, value) {
let composeData = this.get('composeData')
let instanceName = this.get('currentInstance')
composeData[instanceName] = composeData[instanceName] || {}
composeData[instanceName][realm] = composeData[instanceName][realm] || {}
composeData[instanceName][realm][key] = value
this.set({composeData})
}
Store.prototype.getComposeData = function (realm, key) {
let composeData = this.get('composeData')
let instanceName = this.get('currentInstance')
return composeData[instanceName] &&
composeData[instanceName][realm] &&
composeData[instanceName][realm][key]
}
}

View File

@ -0,0 +1,7 @@
import { timelineMixins } from './timelineMixins'
import { instanceMixins } from './instanceMixins'
export function mixins (Store) {
instanceMixins(Store)
timelineMixins(Store)
}

View File

@ -1,4 +1,4 @@
function timelineMixins (Store) {
export function timelineMixins (Store) {
Store.prototype.setForTimeline = function (instanceName, timelineName, obj) {
let timelines = this.get('timelines') || {}
let timelineData = timelines[instanceName] || {}
@ -19,7 +19,3 @@ function timelineMixins (Store) {
this.setForTimeline(instanceName, timelineName, obj)
}
}
export function mixins (Store) {
timelineMixins(Store)
}

View File

@ -1,6 +1,6 @@
import { updateInstanceInfo, updateVerifyCredentialsForInstance } from '../_actions/instances'
import { updateLists } from '../_actions/lists'
import { createStream } from '../_actions/streaming'
import { updateInstanceInfo, updateVerifyCredentialsForInstance } from '../../_actions/instances'
import { updateLists } from '../../_actions/lists'
import { createStream } from '../../_actions/streaming'
export function instanceObservers (store) {
// stream to watch for home timeline updates and notifications

View File

@ -1,5 +1,5 @@
import { setFavicon } from '../_utils/setFavicon'
import { scheduleIdleTask } from '../_utils/scheduleIdleTask'
import { setFavicon } from '../../_utils/setFavicon'
import { scheduleIdleTask } from '../../_utils/scheduleIdleTask'
let currentFaviconHasNotifications = false

View File

@ -1,5 +1,5 @@
import { updateInstanceInfo } from '../_actions/instances'
import { createStream } from '../_actions/streaming'
import { updateInstanceInfo } from '../../_actions/instances'
import { createStream } from '../../_actions/streaming'
export function timelineObservers (store) {
// stream to watch for local/federated/etc. updates. home and notification

View File

@ -1,6 +1,6 @@
import { observers } from './observers'
import { computations } from './computations'
import { mixins } from './mixins'
import { observers } from './observers/observers'
import { computations } from './computations/computations'
import { mixins } from './mixins/mixins'
import { LocalStorageStore } from './LocalStorageStore'
const KEYS_TO_STORE_IN_LOCAL_STORAGE = new Set([
@ -14,9 +14,7 @@ const KEYS_TO_STORE_IN_LOCAL_STORAGE = new Set([
'autoplayGifs',
'markMediaAsSensitive',
'pinnedPages',
'composeText',
'uploadedMedia',
'postPrivacy'
'composeData'
])
class PinaforeStore extends LocalStorageStore {
@ -41,11 +39,9 @@ export const store = new PinaforeStore({
pinnedStatuses: {},
instanceInfos: {},
statusModifications: {},
composeText: {},
rawComposeText: '',
customEmoji: {},
uploadedMedia: {},
postPrivacy: {},
composeData: {},
verifyCredentials: {}
})