|
| 1 | +<template> |
| 2 | + <div> |
| 3 | + <div class="markdown-body mt-3"> |
| 4 | + <h2>Share this event on Facebook page</h2> |
| 5 | + <p>Note: You must be a Facebook page admin.</p> |
| 6 | + <ol> |
| 7 | + <li> |
| 8 | + <p> |
| 9 | + <button |
| 10 | + class="btn btn-outline" |
| 11 | + type="button" |
| 12 | + @click="copyText()">Copy</button> the announcement text. |
| 13 | + </p> |
| 14 | + </li> |
| 15 | + <li> |
| 16 | + <p> |
| 17 | + <button |
| 18 | + class="btn btn-outline" |
| 19 | + type="button" |
| 20 | + @click="openShareDialog()">Share</button> the event on Facebook, pasting the copied text. |
| 21 | + </p> |
| 22 | + <ul> |
| 23 | + <li>Make sure to share on <strong>calendar.thaiprogrammer.org</strong> page.</li> |
| 24 | + </ul> |
| 25 | + </li> |
| 26 | + </ol> |
| 27 | + <h3>Announcement text</h3> |
| 28 | + <p> |
| 29 | + <textarea |
| 30 | + ref="textarea" |
| 31 | + :value="announcement" |
| 32 | + class="form-control input-monospace" |
| 33 | + style="width: 100%; height: 12em;" |
| 34 | + @dragover="$event.preventDefault()" |
| 35 | + @drop="handleDrop($event)" |
| 36 | + /> |
| 37 | + </p> |
| 38 | + </div> |
| 39 | + </div> |
| 40 | +</template> |
| 41 | + |
| 42 | +<script> |
| 43 | +import { MONTHS, DAYS } from '../utils' |
| 44 | +
|
| 45 | +export default { |
| 46 | + props: { |
| 47 | + event: Object |
| 48 | + }, |
| 49 | + computed: { |
| 50 | + announcement() { |
| 51 | + return getEventText(this.event) |
| 52 | + } |
| 53 | + }, |
| 54 | + methods: { |
| 55 | + copyText() { |
| 56 | + this.$refs.textarea.focus() |
| 57 | + this.$refs.textarea.select() |
| 58 | + document.execCommand('copy') |
| 59 | + }, |
| 60 | + openShareDialog() { |
| 61 | + const { event } = this |
| 62 | + const pageUrl = `https://calendar.thaiprogrammer.org/event/${event.id}` |
| 63 | + const fbEventLink = event.links.filter(link => |
| 64 | + /https:\/\/(?:www|web)\.facebook\.com\/events\/\d+/.test(link.url) |
| 65 | + )[0] |
| 66 | + const fbEventUrl = fbEventLink && fbEventLink.url |
| 67 | + const link = fbEventUrl || pageUrl |
| 68 | + const shareQuery = [ |
| 69 | + 'app_id=1894360754189647', |
| 70 | + 'display=popup', |
| 71 | + `href=${encodeURIComponent(link)}` |
| 72 | + ].join('&') |
| 73 | + const shareUrl = `https://www.facebook.com/dialog/share?${shareQuery}` |
| 74 | + window.open(shareUrl, '_blank') |
| 75 | + } |
| 76 | + } |
| 77 | +} |
| 78 | +
|
| 79 | +function getEventText(event) { |
| 80 | + const url = `https://calendar.thaiprogrammer.org/event/${event.id}` |
| 81 | + const location = event.location && event.location.title |
| 82 | + const text = [ |
| 83 | + `[Event] ${event.title}`, |
| 84 | + `${dates(event)}${location ? ` @ ${location}` : ''}`, |
| 85 | + '', |
| 86 | + `${event.summary}`, |
| 87 | + `${hashtags([...event.categories, ...event.topics])}`, |
| 88 | + url |
| 89 | + ].join('\n') |
| 90 | + return text |
| 91 | +} |
| 92 | +
|
| 93 | +function hashtags(tags) { |
| 94 | + return tags.map(x => `#${x.replace(/[^a-zA-Z0-9_]/g, '')}`).join(' ') |
| 95 | +} |
| 96 | +
|
| 97 | +function dateOf({ year, month, date }) { |
| 98 | + return new Date(year, month - 1, date) |
| 99 | +} |
| 100 | +
|
| 101 | +function dates(event) { |
| 102 | + const formatDate = ({ year, month, date }) => { |
| 103 | + const day = dateOf({ year, month, date }).getDay() |
| 104 | + return `${MONTHS[month - 1]} ${date} (${DAYS[day]})` |
| 105 | + } |
| 106 | + const formatTime = t => `${t.hour}:${t.minute < 10 ? '0' : ''}${t.minute}` |
| 107 | + const start = formatDate(event.start) |
| 108 | + const end = formatDate(event.end) |
| 109 | + const time = |
| 110 | + event.time && event.time.length === 1 |
| 111 | + ? `${formatTime(event.time[0].from)} ~ ${formatTime(event.time[0].to)}` |
| 112 | + : '' |
| 113 | + return `${start}${end !== start ? ` ~ ${end}` : ''}${time ? `, ${time}` : ''}` |
| 114 | +} |
| 115 | +</script> |
| 116 | + |
| 117 | +<style scoped> |
| 118 | +button.btn { |
| 119 | + vertical-align: baseline; |
| 120 | +} |
| 121 | +</style> |
0 commit comments