pinafore/src/routes/_components/status/StatusComposeBox.html
Nolan Lawson 4bd181d3cc
fix: update Sapper to latest (#775)
* fix: update to latest sapper

fixes #416

* fix error and debug pages

* requestIdleCallback makes column switching feel way nicer than double rAF

* add export feature

* add better csp info

* workaround for sapper sub-page issue

* clarify in readme about exporting

* fix now config

* switch from rIC to triple raf

* style-loader is no longer used

* update theming guide
2018-12-11 07:31:48 -08:00

70 lines
2 KiB
HTML

<div class="status-article-compose-box">
<ComposeBox realm={originalStatusId}
size="slim"
autoFocus="true"
hideBottomBorder="true"
isReply="true"
replyVisibility={visibility}
replySpoiler={spoilerText}
inReplyToUuid={uuid}
/>
</div>
<style>
.status-article-compose-box {
grid-area: compose;
}
</style>
<script>
import ComposeBox from '../compose/ComposeBox.html'
import { store } from '../../_store/store'
import debounce from 'lodash-es/debounce'
import throttle from 'lodash-es/throttle'
import { on } from '../../_utils/eventBus'
import { observe } from 'svelte-extras'
const DEBOUNCE_DELAY = 400
const THROTTLE_DELAY = 150
export default {
oncreate () {
on('postedStatus', this, this.onPostedStatus)
this.setupRecalculateHeightListener()
},
store: () => store,
computed: {
composeData: ({ $currentComposeData, originalStatusId }) => $currentComposeData[originalStatusId] || {}
},
methods: {
observe,
onPostedStatus (realm) {
let { originalStatusId } = this.get()
if (realm !== originalStatusId) {
return
}
requestAnimationFrame(() => {
let { uuid } = this.get()
let { repliesShown } = this.store.get()
repliesShown[uuid] = false
this.store.set({ repliesShown })
this.fire('recalculateHeight')
})
},
setupRecalculateHeightListener () {
const recalc = () => requestAnimationFrame(() => this.fire('recalculateHeight'))
// debounce AND throttle due to 333ms content warning animation
const debounced = debounce(recalc, DEBOUNCE_DELAY)
const throttled = throttle(() => {
debounced()
recalc()
}, THROTTLE_DELAY, {
leading: true,
trailing: true
})
this.observe('composeData', throttled)
}
},
components: {
ComposeBox
}
}
</script>