Skip to content

Commit 382f37c

Browse files
committed
feat: add copy quote functionality, make quote/edit toggle, highlight post
1 parent 6319183 commit 382f37c

File tree

2 files changed

+50
-9
lines changed

2 files changed

+50
-9
lines changed

src/components/layout/Editor.vue

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -309,17 +309,22 @@ export default {
309309
watch(() => v.msgTagsInput.value, receivers => v.newMessage.receiver_ids = receivers)
310310
311311
watch(() => props.thread, t => {
312-
v.posting.post.thread_id = t.id
313-
v.posting.post.title = t.title
314-
if (t) nextTick(() => Object.assign(v.threadCopy, t))
312+
if (t) {
313+
v.posting.post.thread_id = t.id
314+
v.posting.post.title = 'RE:' + props.thread.title
315+
nextTick(() => v.threadCopy = t)
316+
}
315317
})
316318
317319
watch(() => props.post, p => {
318-
if (p) nextTick(() => Object.assign(v.posting.post, p))
320+
if (p) {
321+
p.title = 'RE:' + props.thread.title
322+
nextTick(() => v.posting.post = p)
323+
}
319324
})
320325
321326
watch(() => props.quote, p => {
322-
if (p) nextTick(() => Object.assign(v.posting.post, p))
327+
if (p) nextTick(() => v.posting.post = { title: 'RE:' + props.thread, body: p.body, thread_id: props.thread.id})
323328
})
324329
325330
// invalidate poll when closing poll creator

src/views/Posts.vue

Lines changed: 40 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -258,7 +258,7 @@
258258
</a>
259259
</li>
260260
<li v-if="loggedIn && postData.data.thread.locked">
261-
<a href="" @click.prevent="copyQuote(post)" data-balloon="Quote">
261+
<a href="" @click.prevent="copyQuote({ id: post.id, body: post.body, body_html: post.body_html, created_at: post.created_at, thread_slug: threadSlug, user: { username: post.user.username }})" data-balloon="Quote">
262262
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 48 48">
263263
<title></title>
264264
<path
@@ -422,6 +422,7 @@ import PollViewer from '@/components/polls/PollViewer.vue'
422422
import PollCreator from '@/components/polls/PollCreator.vue'
423423
import RankDisplay from '@/components/users/RankDisplay.vue'
424424
import humanDate from '@/composables/filters/humanDate'
425+
import decode from '@/composables/filters/decode'
425426
import dayjs from 'dayjs'
426427
import { userRoleHighlight } from '@/composables/utils/userUtils'
427428
import truncate from '@/composables/filters/truncate'
@@ -867,11 +868,17 @@ export default {
867868
postsApi.unlock(post.id).then(() => post.locked = false)
868869
}
869870
const loadEditor = (post) => {
871+
v.showEditor = false
872+
v.editPost = null
873+
v.quote = null
870874
v.editPost = post
875+
if (post?.id) $router.push({ path: $route.path, query: $route.query, hash: `#${post.id}` })
871876
v.showEditor = true
872877
}
873-
const addQuote = (post) => {
878+
const addQuote = post => {
879+
v.showEditor = false
874880
v.quote = null
881+
v.editPost = null
875882
let quote = '[quote author=' + post.user.username
876883
if (post.thread_slug) {
877884
quote += ' link='
@@ -880,13 +887,42 @@ export default {
880887
quote += ' date=' + new Date(post.created_at).getTime() + ']'
881888
quote += post.body || post.body_html
882889
quote += '[/quote]'
883-
console.log(quote)
884890
v.quote = post
885891
v.quote.body = quote
892+
$router.push({ path: $route.path, query: $route.query, hash: `#${post.id}` })
886893
delete v.quote.id
887894
v.showEditor = true
888895
}
889-
const copyQuote = (post) => console.log(post, 'copyQuote')
896+
const copyQuote = post => {
897+
let quote = '[quote author=' + post.user.username
898+
if (post.thread_slug) {
899+
quote += ' link='
900+
quote += '/threads/' + post.thread_slug + '/posts?page=' + v.postData.data.page + '#' + post.id
901+
}
902+
quote += ' date=' + new Date(post.created_at).getTime() + ']'
903+
quote += post.body || post.body_html
904+
quote += '[/quote]'
905+
$router.push({ path: $route.path, query: $route.query, hash: `#${post.id}` })
906+
let copyText = decode(quote)
907+
908+
// create temp element
909+
let copyElement = document.createElement('span')
910+
copyElement.appendChild(document.createTextNode(copyText))
911+
copyElement.id = 'tempCopyToClipboard'
912+
document.body.append(copyElement)
913+
914+
// select the text
915+
let range = document.createRange()
916+
range.selectNode(copyElement)
917+
window.getSelection().removeAllRanges()
918+
window.getSelection().addRange(range)
919+
920+
// copy & cleanup
921+
document.execCommand('copy')
922+
window.getSelection().removeAllRanges()
923+
copyElement.remove()
924+
$alertStore.success('Quote successfully copied to clipboard')
925+
}
890926
const showUserControls = () => (v.loggedIn && (!v.postData.data.thread.watched || canCreatePoll()))
891927
const highlightPost = () => {
892928
if ($route.hash) {

0 commit comments

Comments
 (0)