1
0
mirror of https://github.com/nolanlawson/pinafore synced 2024-12-14 11:27:45 +01:00
Pinafore-Web-Client-Frontend/routes/_components/status/Status.html
2018-02-04 10:23:21 -08:00

216 lines
6.8 KiB
HTML

<article class="status-article {{originalStatus.visibility === 'direct' ? 'status-direct' : ''}} {{isStatusInContext ? 'status-in-context' : ''}}"
tabindex="0"
aria-posinset="{{index}}" aria-setsize="{{length}}"
on:recalculateHeight>
{{#if (notification && (notification.type === 'reblog' || notification.type === 'favourite')) || status.reblog}}
<StatusHeader :notification :status />
{{/if}}
<StatusAuthor status="{{originalStatus}}" :isStatusInContext />
<Avatar account={{originalAccount}} className="status-sidebar" size="small" />
{{#if originalStatus.spoiler_text}}
<div class="status-spoiler">{{originalStatus.spoiler_text}}</div>
{{/if}}
{{#if originalStatus.spoiler_text}}
<div class="status-spoiler-button">
<button type="button" on:click="onClickSpoilerButton()">{{spoilerShown ? 'Show less' : 'Show more'}}</button>
</div>
{{/if}}
{{#if !originalStatus.spoiler_text || spoilerShown}}
<div class="status-content" ref:contentNode>
{{{emojifiedContent}}}
</div>
{{/if}}
{{#if originalMediaAttachments && originalMediaAttachments.length}}
<MediaAttachments
status="{{originalStatus}}"
mediaAttachments="{{originalMediaAttachments}}"
on:recalculateHeight
/>
{{/if}}
<Toolbar :status />
</article>
<style>
.status-article {
width: 560px;
max-width: calc(100vw - 40px);
padding: 10px 20px;
border-bottom: 1px solid var(--main-border);
display: grid;
grid-template-areas:
".............. status-header"
"status-sidebar status-author"
"status-sidebar status-spoiler"
"status-sidebar status-spoiler-button"
"status-sidebar status-content"
"status-media status-media"
".............. status-toolbar";
grid-template-columns: 58px 1fr;
}
.status-article.status-direct {
background-color: var(--status-direct-background);
}
:global(.status-sidebar) {
grid-area: status-sidebar;
margin: 0 10px 0 0;
}
.status-spoiler {
grid-area: status-spoiler;
word-wrap: break-word;
overflow: hidden;
white-space: pre-wrap;
font-size: 1.1em;
margin: 5px;
}
.status-spoiler-button {
grid-area: status-spoiler-button;
margin: 5px;
}
.status-spoiler-button button {
padding: 5px 10px;
font-size: 1.1em;
}
.status-content {
margin: 10px 10px 10px 5px;
grid-area: status-content;
word-wrap: break-word;
overflow: hidden;
white-space: pre-wrap;
font-size: 0.9em;
}
.status-in-context .status-content {
font-size: 1.3em;
margin: 20px 10px 20px 5px;
}
:global(.status-content .status-emoji) {
width: 20px;
height: 20px;
margin: -3px 0;
}
:global(.status-content p) {
margin: 0 0 20px;
}
:global(.status-content p:first-child) {
margin: 0 0 20px;
}
:global(.status-content p:last-child) {
margin: 0;
}
@media (max-width: 767px) {
.status-article {
padding: 10px 10px;
max-width: calc(100vw - 20px);
}
}
</style>
<script>
import Avatar from './Avatar.html'
import MediaAttachments from './MediaAttachments.html'
import StatusAuthor from './StatusAuthor.html'
import Toolbar from './Toolbar.html'
import StatusHeader from './StatusHeader.html'
import ExternalLink from '../ExternalLink.html'
import { mark, stop } from '../../_utils/marks'
import { replaceAll } from '../../_utils/strings'
import { store } from '../../_store/store'
export default {
oncreate() {
this.hydrateContent()
},
components: {
Avatar,
MediaAttachments,
Toolbar,
ExternalLink,
StatusHeader,
StatusAuthor
},
store: () => store,
computed: {
isStatusInContext: (timelineType, timelineValue, statusId) => timelineType === 'status' && timelineValue === statusId,
originalStatus: (status) => status.reblog ? status.reblog : status,
originalAccount: (originalStatus) => originalStatus.account,
originalMediaAttachments: (originalStatus) => originalStatus.media_attachments,
statusId: (originalStatus) => originalStatus.id,
emojifiedContent: (originalStatus, $autoplayGifs) => {
let status = originalStatus
let content = status.content
if (status.emojis && status.emojis.length) {
for (let emoji of status.emojis) {
let { shortcode, url, url_static } = emoji
let urlToUse = $autoplayGifs ? url : url_static
let shortcodeWithColons = `:${shortcode}:`
content = replaceAll(
content,
shortcodeWithColons,
`<img class="status-emoji" draggable="false" src="${url}" alt="${shortcodeWithColons}" title="${shortcodeWithColons}" />`
)
}
}
return content
},
spoilerShown: ($spoilersShown, $currentInstance, statusId) => $spoilersShown && $spoilersShown[$currentInstance] && $spoilersShown[$currentInstance][statusId]
},
methods: {
onClickSpoilerButton() {
let statusId = this.get('statusId')
let instanceName = this.store.get('currentInstance')
let $spoilersShown = this.store.get('spoilersShown') || {}
if (!$spoilersShown[instanceName]) {
$spoilersShown[instanceName] = {}
}
$spoilersShown[instanceName][statusId] = !$spoilersShown[instanceName][statusId]
this.store.set({'spoilersShown': $spoilersShown})
this.hydrateContent()
this.fire('recalculateHeight')
},
hydrateContent() {
if (!this.refs.contentNode) {
return
}
let status = this.get('originalStatus')
mark('hydrateContent')
if (status.tags && status.tags.length) {
let anchorTags = Array.from(this.refs.contentNode.querySelectorAll(
'a[class~=hashtag][href^=http]'))
for (let tag of status.tags) {
for (let anchorTag of anchorTags) {
if (anchorTag.getAttribute('href').endsWith(`/tags/${tag.name}`)) {
anchorTag.setAttribute('href', `/tags/${tag.name}`)
anchorTag.removeAttribute('target')
anchorTag.removeAttribute('rel')
}
}
}
}
if (status.mentions && status.mentions.length) {
let anchorTags = Array.from(this.refs.contentNode.querySelectorAll(
'a[class~=mention][href^=http]'))
for (let mention of status.mentions) {
for (let anchorTag of anchorTags) {
if (anchorTag.getAttribute('href') === mention.url) {
anchorTag.setAttribute('href', `/accounts/${mention.id}`)
anchorTag.removeAttribute('target')
anchorTag.removeAttribute('rel')
}
}
}
}
stop('hydrateContent')
}
}
}
</script>