shack/components/posts/post.vue

159 lines
2.5 KiB
Vue
Raw Normal View History

2023-06-05 23:30:46 +00:00
<template>
2023-06-11 03:32:02 +00:00
<div class="post">
<a
:href="post.link || `/s/${post.shelf.slug}/post/${post.id}`"
target="_blank"
class="title-link"
2023-06-05 23:30:46 +00:00
>
2023-06-11 03:32:02 +00:00
<img
class="thumbnail"
:src="blockedIcon"
>
</a>
2023-06-05 23:30:46 +00:00
<div class="body">
2023-06-11 03:32:02 +00:00
<div class="header">
<h2 class="title">
<a
:href="`/s/${post.shelf.slug}/post/${post.id}`"
class="title-link"
>{{ post.title }}</a>
</h2>
2023-06-05 23:30:46 +00:00
<a
2023-06-11 03:32:02 +00:00
v-if="post.link"
:href="post.link"
target="_blank"
2023-06-05 23:30:46 +00:00
class="link"
2023-06-11 03:32:02 +00:00
>{{ post.link }}</a>
</div>
2023-06-05 23:30:46 +00:00
<div class="meta">
<a
2023-06-11 03:32:02 +00:00
:href="`/s/${post.shelf.slug}`"
2023-06-05 23:30:46 +00:00
class="shelf link"
>s/{{ post.shelf.slug }}</a>
<a
:href="`/user/${post.user.username}`"
class="username link"
>u/{{ post.user.username }}</a>
<span
:title="format(post.createdAt, 'MMMM d, yyyy hh:mm:ss')"
class="timestamp"
2023-06-11 03:32:02 +00:00
>{{ formatDistance(post.createdAt, now, { includeSeconds: true }) }} ago</span>
</div>
<div class="actions">
<a
:href="`/s/shack/post/${post.id}`"
class="link comments"
>{{ post.commentCount }} comments</a>
2023-06-05 23:30:46 +00:00
</div>
</div>
2023-06-11 03:32:02 +00:00
<a
:href="`/s/shack/post/${post.id}`"
class="fill"
/>
</div>
2023-06-05 23:30:46 +00:00
</template>
<script setup>
import { format, formatDistance } from 'date-fns';
2023-06-11 03:32:02 +00:00
import blockedIcon from '../../assets/icons/blocked.svg?url'; // eslint-disable-line import/no-unresolved
import { usePageContext } from '../../renderer/usePageContext';
const { now } = usePageContext();
2023-06-05 23:30:46 +00:00
defineProps({
post: {
type: Object,
default: null,
},
});
</script>
<style scoped>
.post {
display: flex;
color: var(--text);
border-radius: .25rem;
2023-06-11 03:32:02 +00:00
margin-bottom: .25rem;
2023-06-05 23:30:46 +00:00
background: var(--background);
text-decoration: none;
& :hover {
cursor: pointer;
.title {
color: var(--text);
}
}
}
.body {
margin-left: 1rem;
}
2023-06-11 03:32:02 +00:00
.header {
display: flex;
align-items: center;
}
2023-06-05 23:30:46 +00:00
.title {
2023-06-11 03:32:02 +00:00
display: inline-block;
padding: .25rem 0;
margin: .25rem 1rem 0 0;
font-size: 1rem;
font-weight: bold;
2023-06-05 23:30:46 +00:00
color: var(--grey-dark-30);
2023-06-11 03:32:02 +00:00
}
2023-06-05 23:30:46 +00:00
2023-06-11 03:32:02 +00:00
.title-link {
color: inherit;
text-decoration: none;
2023-06-05 23:30:46 +00:00
}
.thumbnail {
width: 7rem;
height: 4rem;
box-sizing: border-box;
padding: 1rem;
border-radius: .25rem;
margin: .5rem;
background: var(--grey-light-10);
opacity: .25;
}
.meta {
display: flex;
gap: 1rem;
2023-06-11 03:32:02 +00:00
margin-bottom: .25rem;
2023-06-05 23:30:46 +00:00
font-size: .9rem;
}
2023-06-11 03:32:02 +00:00
.username {
color: inherit;
}
2023-06-05 23:30:46 +00:00
.shelf {
color: inherit;
font-weight: bold;
}
.timestamp {
color: var(--grey-dark-20);
}
2023-06-11 03:32:02 +00:00
.comments {
color: inherit;
font-size: .9rem;
}
.fill {
flex-grow: 1;
}
2023-06-05 23:30:46 +00:00
</style>