build: switch from yarn to npm to manage js dependencies and move js contents to root
yarn v1 is being deprecated and starts to have some issues Signed-off-by: Thomas Citharel <tcit@tcit.fr>
This commit is contained in:
410
src/views/Posts/EditView.vue
Normal file
410
src/views/Posts/EditView.vue
Normal file
@@ -0,0 +1,410 @@
|
||||
<template>
|
||||
<div>
|
||||
<form @submit.prevent="publish(false)" v-if="isCurrentActorAGroupModerator">
|
||||
<div class="container mx-auto">
|
||||
<breadcrumbs-nav v-if="actualGroup" :links="breadcrumbLinks" />
|
||||
<h1 v-if="isUpdate === true">
|
||||
{{ t("Edit post") }}
|
||||
</h1>
|
||||
<h1 v-else>
|
||||
{{ t("Add a new post") }}
|
||||
</h1>
|
||||
<h2>{{ t("General information") }}</h2>
|
||||
<picture-upload
|
||||
v-model="pictureFile"
|
||||
:textFallback="t('Headline picture')"
|
||||
:defaultImage="editablePost.picture"
|
||||
/>
|
||||
|
||||
<o-field
|
||||
:label="t('Title')"
|
||||
label-for="post-title"
|
||||
:type="errors.title ? 'is-danger' : null"
|
||||
:message="errors.title"
|
||||
>
|
||||
<o-input
|
||||
size="large"
|
||||
aria-required="true"
|
||||
required
|
||||
v-model="editablePost.title"
|
||||
id="post-title"
|
||||
dir="auto"
|
||||
/>
|
||||
</o-field>
|
||||
|
||||
<tag-input v-model="editablePost.tags" :fetch-tags="fetchTags" />
|
||||
|
||||
<o-field :label="t('Post')">
|
||||
<p v-if="errors.body" class="help is-danger">{{ errors.body }}</p>
|
||||
<editor
|
||||
class="w-full"
|
||||
v-if="currentActor"
|
||||
v-model="editablePost.body"
|
||||
:aria-label="t('Post body')"
|
||||
:current-actor="currentActor"
|
||||
:placeholder="t('Write your post')"
|
||||
:headingLevel="[2, 3, 4]"
|
||||
/>
|
||||
</o-field>
|
||||
<h2 class="mt-2">{{ t("Who can view this post") }}</h2>
|
||||
<fieldset>
|
||||
<legend>
|
||||
{{
|
||||
t(
|
||||
"When the post is private, you'll need to share the link around."
|
||||
)
|
||||
}}
|
||||
</legend>
|
||||
<div class="field">
|
||||
<o-radio
|
||||
v-model="editablePost.visibility"
|
||||
name="postVisibility"
|
||||
:native-value="PostVisibility.PUBLIC"
|
||||
>{{ t("Visible everywhere on the web") }}</o-radio
|
||||
>
|
||||
</div>
|
||||
<div class="field">
|
||||
<o-radio
|
||||
v-model="editablePost.visibility"
|
||||
name="postVisibility"
|
||||
:native-value="PostVisibility.UNLISTED"
|
||||
>{{ t("Only accessible through link") }}</o-radio
|
||||
>
|
||||
</div>
|
||||
<div class="field">
|
||||
<o-radio
|
||||
v-model="editablePost.visibility"
|
||||
name="postVisibility"
|
||||
:native-value="PostVisibility.PRIVATE"
|
||||
>{{ t("Only accessible to members of the group") }}</o-radio
|
||||
>
|
||||
</div>
|
||||
</fieldset>
|
||||
</div>
|
||||
<nav class="navbar">
|
||||
<div class="container mx-auto">
|
||||
<div class="navbar-menu flex flex-wrap py-2">
|
||||
<div class="flex flex-wrap justify-end ml-auto gap-1">
|
||||
<o-button variant="text" @click="$router.go(-1)">{{
|
||||
t("Cancel")
|
||||
}}</o-button>
|
||||
<o-button
|
||||
v-if="isUpdate"
|
||||
variant="danger"
|
||||
outlined
|
||||
@click="openDeletePostModal"
|
||||
>{{ t("Delete post") }}</o-button
|
||||
>
|
||||
<!-- If an post has been published we can't make it draft anymore -->
|
||||
<o-button
|
||||
variant="primary"
|
||||
v-if="post?.draft === true"
|
||||
outlined
|
||||
@click="publish(true)"
|
||||
>{{ t("Save draft") }}</o-button
|
||||
>
|
||||
<o-button variant="primary" native-type="submit">
|
||||
<span v-if="isUpdate === false || post?.draft === true">{{
|
||||
t("Publish")
|
||||
}}</span>
|
||||
|
||||
<span v-else>{{ t("Update post") }}</span>
|
||||
</o-button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</nav>
|
||||
</form>
|
||||
<o-loading
|
||||
v-else-if="postLoading"
|
||||
:is-full-page="false"
|
||||
v-model:active="postLoading"
|
||||
:can-cancel="false"
|
||||
></o-loading>
|
||||
<div class="container mx-auto" v-else>
|
||||
<o-notification variant="danger">
|
||||
{{ t("Only group moderators can create, edit and delete posts.") }}
|
||||
</o-notification>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
<script lang="ts" setup>
|
||||
import {
|
||||
buildFileFromIMedia,
|
||||
buildFileVariable,
|
||||
readFileAsync,
|
||||
} from "@/utils/image";
|
||||
import { MemberRole, PostVisibility } from "@/types/enums";
|
||||
import {
|
||||
CREATE_POST,
|
||||
DELETE_POST,
|
||||
FETCH_POST,
|
||||
UPDATE_POST,
|
||||
} from "../../graphql/post";
|
||||
|
||||
import { IPost } from "../../types/post.model";
|
||||
import Editor from "../../components/TextEditor.vue";
|
||||
import { displayName, IActor, usernameWithDomain } from "../../types/actor";
|
||||
import TagInput from "../../components/Event/TagInput.vue";
|
||||
import RouteName from "../../router/name";
|
||||
import PictureUpload from "../../components/PictureUpload.vue";
|
||||
import { useGroup } from "@/composition/apollo/group";
|
||||
import {
|
||||
useCurrentActorClient,
|
||||
usePersonStatusGroup,
|
||||
} from "@/composition/apollo/actor";
|
||||
import { useHead } from "@vueuse/head";
|
||||
import { useI18n } from "vue-i18n";
|
||||
import { computed, inject, onMounted, ref, watch } from "vue";
|
||||
import { useRouter } from "vue-router";
|
||||
import { useMutation, useQuery } from "@vue/apollo-composable";
|
||||
import { fetchTags } from "@/composition/apollo/tags";
|
||||
import { Dialog } from "@/plugins/dialog";
|
||||
|
||||
const props = withDefaults(
|
||||
defineProps<{
|
||||
slug?: string;
|
||||
preferredUsername?: string;
|
||||
isUpdate?: boolean;
|
||||
}>(),
|
||||
{ isUpdate: false }
|
||||
);
|
||||
const preferredUsername = computed(() => props.preferredUsername);
|
||||
|
||||
const { currentActor } = useCurrentActorClient();
|
||||
const { group } = useGroup(preferredUsername);
|
||||
|
||||
const { result: postResult, loading: postLoading } = useQuery<{
|
||||
post: IPost;
|
||||
}>(FETCH_POST, () => ({ slug: props.slug }));
|
||||
|
||||
const post = computed(() => postResult.value?.post);
|
||||
|
||||
const pictureFile = ref<File | null>(null);
|
||||
const errors = ref<Record<string, unknown>>({});
|
||||
const editablePost = ref<IPost>({
|
||||
title: "",
|
||||
body: "",
|
||||
local: true,
|
||||
draft: true,
|
||||
visibility: PostVisibility.PUBLIC,
|
||||
tags: [],
|
||||
});
|
||||
|
||||
onMounted(async () => {
|
||||
pictureFile.value = await buildFileFromIMedia(post.value?.picture);
|
||||
});
|
||||
|
||||
watch(post, async (newPost: IPost | undefined, oldPost: IPost | undefined) => {
|
||||
if (oldPost?.picture !== newPost?.picture) {
|
||||
pictureFile.value = await buildFileFromIMedia(post.value?.picture);
|
||||
}
|
||||
if (newPost) {
|
||||
editablePost.value = { ...newPost };
|
||||
}
|
||||
});
|
||||
|
||||
const router = useRouter();
|
||||
|
||||
const { mutate: updatePost, onDone: onUpdateDone } = useMutation<{
|
||||
updatePost: IPost;
|
||||
}>(UPDATE_POST);
|
||||
const {
|
||||
mutate: createPost,
|
||||
onDone: onCreateDone,
|
||||
onError: onCreateError,
|
||||
} = useMutation<{
|
||||
createPost: IPost;
|
||||
}>(CREATE_POST);
|
||||
|
||||
onUpdateDone(({ data }) => {
|
||||
if (data && data.updatePost) {
|
||||
router.push({
|
||||
name: RouteName.POST,
|
||||
params: { slug: data.updatePost.slug },
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
onCreateDone(({ data }) => {
|
||||
if (data && data.createPost) {
|
||||
router.push({
|
||||
name: RouteName.POST,
|
||||
params: { slug: data.createPost.slug },
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
onCreateError((error) => {
|
||||
console.error(error);
|
||||
errors.value = error.graphQLErrors.reduce(
|
||||
(acc: { [key: string]: any }, localError: any) => {
|
||||
acc[localError.field] = transformMessage(localError.message);
|
||||
return acc;
|
||||
},
|
||||
{}
|
||||
);
|
||||
});
|
||||
|
||||
const publish = async (draft: boolean): Promise<void> => {
|
||||
errors.value = {};
|
||||
|
||||
if (props.isUpdate) {
|
||||
updatePost({
|
||||
id: editablePost.value?.id,
|
||||
title: editablePost.value?.title,
|
||||
body: editablePost.value?.body,
|
||||
tags: (editablePost.value?.tags || []).map(({ title }) => title),
|
||||
visibility: editablePost.value?.visibility,
|
||||
draft,
|
||||
...(await buildPicture()),
|
||||
});
|
||||
} else {
|
||||
createPost({
|
||||
...editablePost.value,
|
||||
...(await buildPicture()),
|
||||
tags: (editablePost.value?.tags ?? []).map(({ title }) => title),
|
||||
attributedToId: actualGroup.value.id,
|
||||
draft,
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
const transformMessage = (message: string[] | string): string | undefined => {
|
||||
if (Array.isArray(message) && message.length > 0) {
|
||||
return message[0];
|
||||
}
|
||||
if (typeof message === "string") {
|
||||
return message;
|
||||
}
|
||||
return undefined;
|
||||
};
|
||||
|
||||
const buildPicture = async (): Promise<Record<string, unknown>> => {
|
||||
let obj: { picture?: any } = {};
|
||||
if (pictureFile.value) {
|
||||
const pictureObj = buildFileVariable(pictureFile.value, "picture");
|
||||
obj = { ...obj, ...pictureObj };
|
||||
}
|
||||
try {
|
||||
if (editablePost.value?.picture && pictureFile.value) {
|
||||
const oldPictureFile = (await buildFileFromIMedia(
|
||||
editablePost.value.picture
|
||||
)) as File;
|
||||
const oldPictureFileContent = await readFileAsync(oldPictureFile);
|
||||
const newPictureFileContent = await readFileAsync(
|
||||
pictureFile.value as File
|
||||
);
|
||||
if (oldPictureFileContent === newPictureFileContent) {
|
||||
obj.picture = { mediaId: editablePost.value.picture.id };
|
||||
}
|
||||
}
|
||||
} catch (e: any) {
|
||||
console.error(e);
|
||||
}
|
||||
return obj;
|
||||
};
|
||||
|
||||
const actualGroup = computed((): IActor => {
|
||||
if (!group.value?.id) {
|
||||
return post.value?.attributedTo as IActor;
|
||||
}
|
||||
return group.value;
|
||||
});
|
||||
|
||||
const actualPreferredUsername = computed(() =>
|
||||
usernameWithDomain(actualGroup.value)
|
||||
);
|
||||
|
||||
const { t } = useI18n({ useScope: "global" });
|
||||
|
||||
const breadcrumbLinks = computed(() => {
|
||||
const links = [
|
||||
{
|
||||
name: RouteName.GROUP,
|
||||
params: {
|
||||
preferredUsername: usernameWithDomain(actualGroup.value),
|
||||
},
|
||||
text: displayName(actualGroup.value),
|
||||
},
|
||||
{
|
||||
name: RouteName.POSTS,
|
||||
params: {
|
||||
preferredUsername: usernameWithDomain(actualGroup.value),
|
||||
},
|
||||
text: t("Posts"),
|
||||
},
|
||||
];
|
||||
if (props.preferredUsername) {
|
||||
links.push({
|
||||
text: t("New post") as string,
|
||||
name: RouteName.POST_EDIT,
|
||||
params: { preferredUsername: usernameWithDomain(actualGroup.value) },
|
||||
});
|
||||
} else {
|
||||
links.push({
|
||||
text: t("Edit post") as string,
|
||||
name: RouteName.POST_EDIT,
|
||||
params: { preferredUsername: usernameWithDomain(actualGroup.value) },
|
||||
});
|
||||
}
|
||||
return links;
|
||||
});
|
||||
|
||||
const isCurrentActorAGroupModerator = computed((): boolean => {
|
||||
return hasCurrentActorThisRole([
|
||||
MemberRole.MODERATOR,
|
||||
MemberRole.ADMINISTRATOR,
|
||||
]);
|
||||
});
|
||||
|
||||
const hasCurrentActorThisRole = (givenRole: string | string[]): boolean => {
|
||||
const roles = Array.isArray(givenRole) ? givenRole : [givenRole];
|
||||
return (
|
||||
personMemberships.value?.total > 0 &&
|
||||
roles.includes(personMemberships.value?.elements[0].role)
|
||||
);
|
||||
};
|
||||
|
||||
const { person } = usePersonStatusGroup(actualPreferredUsername);
|
||||
|
||||
const personMemberships = computed(
|
||||
() => person.value?.memberships ?? { total: 0, elements: [] }
|
||||
);
|
||||
|
||||
const dialog = inject<Dialog>("dialog");
|
||||
|
||||
const openDeletePostModal = async (): Promise<void> => {
|
||||
dialog?.confirm({
|
||||
variant: "danger",
|
||||
title: t("Delete post"),
|
||||
message: t(
|
||||
"Are you sure you want to delete this post? This action cannot be reverted."
|
||||
),
|
||||
onConfirm: () =>
|
||||
deletePost({
|
||||
id: post.value?.id,
|
||||
}),
|
||||
});
|
||||
};
|
||||
|
||||
const { mutate: deletePost, onDone: onDeletePostDone } =
|
||||
useMutation(DELETE_POST);
|
||||
|
||||
onDeletePostDone(({ data }) => {
|
||||
if (data && post.value?.attributedTo) {
|
||||
router.push({
|
||||
name: RouteName.POSTS,
|
||||
params: {
|
||||
preferredUsername: usernameWithDomain(post.value?.attributedTo),
|
||||
},
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
useHead({
|
||||
title: computed(() =>
|
||||
props.isUpdate ? t("Edit post") : t("Add a new post")
|
||||
),
|
||||
});
|
||||
</script>
|
||||
155
src/views/Posts/ListView.vue
Normal file
155
src/views/Posts/ListView.vue
Normal file
@@ -0,0 +1,155 @@
|
||||
<template>
|
||||
<div class="container mx-auto section" v-if="group">
|
||||
<breadcrumbs-nav
|
||||
:links="[
|
||||
{
|
||||
name: RouteName.GROUP,
|
||||
params: { preferredUsername: usernameWithDomain(group) },
|
||||
text: displayName(group),
|
||||
},
|
||||
{
|
||||
name: RouteName.POSTS,
|
||||
params: { preferredUsername: usernameWithDomain(group) },
|
||||
text: $t('Posts'),
|
||||
},
|
||||
]"
|
||||
/>
|
||||
<section>
|
||||
<div class="intro">
|
||||
<p v-if="isCurrentActorMember">
|
||||
{{
|
||||
$t(
|
||||
"A place to publish something to the whole world, your community or just your group members."
|
||||
)
|
||||
}}
|
||||
</p>
|
||||
<p v-if="isCurrentActorMember">
|
||||
{{ $t("Only group moderators can create, edit and delete posts.") }}
|
||||
</p>
|
||||
<o-button
|
||||
tag="router-link"
|
||||
v-if="isCurrentActorAGroupModerator"
|
||||
:to="{
|
||||
name: RouteName.POST_CREATE,
|
||||
params: { preferredUsername: usernameWithDomain(group) },
|
||||
}"
|
||||
variant="primary"
|
||||
class="my-2"
|
||||
>{{ $t("+ Create a post") }}</o-button
|
||||
>
|
||||
</div>
|
||||
<div class="post-list">
|
||||
<multi-post-list-item
|
||||
:posts="group.posts.elements"
|
||||
:isCurrentActorMember="isCurrentActorMember"
|
||||
/>
|
||||
</div>
|
||||
<o-loading v-model:active="loading"></o-loading>
|
||||
<o-notification
|
||||
v-if="
|
||||
group.posts.elements.length === 0 &&
|
||||
membershipsLoading === false &&
|
||||
groupLoading === false
|
||||
"
|
||||
variant="danger"
|
||||
>
|
||||
{{ $t("No posts found") }}
|
||||
</o-notification>
|
||||
<o-pagination
|
||||
:total="group.posts.total"
|
||||
v-model:current="postsPage"
|
||||
:per-page="POSTS_PAGE_LIMIT"
|
||||
:aria-next-label="$t('Next page')"
|
||||
:aria-previous-label="$t('Previous page')"
|
||||
:aria-page-label="$t('Page')"
|
||||
:aria-current-label="$t('Current page')"
|
||||
>
|
||||
</o-pagination>
|
||||
</section>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script lang="ts" setup>
|
||||
import { PERSON_MEMBERSHIPS } from "@/graphql/actor";
|
||||
import { FETCH_GROUP_POSTS } from "../../graphql/post";
|
||||
import {
|
||||
usernameWithDomain,
|
||||
displayName,
|
||||
IPerson,
|
||||
IGroup,
|
||||
} from "../../types/actor";
|
||||
import RouteName from "../../router/name";
|
||||
import MultiPostListItem from "../../components/Post/MultiPostListItem.vue";
|
||||
import { useCurrentActorClient } from "@/composition/apollo/actor";
|
||||
import { useQuery } from "@vue/apollo-composable";
|
||||
import { computed } from "vue";
|
||||
import { useHead } from "@vueuse/head";
|
||||
import { integerTransformer, useRouteQuery } from "vue-use-route-query";
|
||||
import { useI18n } from "vue-i18n";
|
||||
import { MemberRole } from "@/types/enums";
|
||||
|
||||
const props = defineProps<{ preferredUsername: string }>();
|
||||
|
||||
const postsPage = useRouteQuery("page", 1, integerTransformer);
|
||||
const POSTS_PAGE_LIMIT = 10;
|
||||
|
||||
const { currentActor } = useCurrentActorClient();
|
||||
|
||||
const { result: membershipsResult, loading: membershipsLoading } = useQuery<{
|
||||
person: Pick<IPerson, "memberships">;
|
||||
}>(
|
||||
PERSON_MEMBERSHIPS,
|
||||
() => ({ id: currentActor.value?.id }),
|
||||
() => ({ enabled: currentActor.value?.id !== undefined })
|
||||
);
|
||||
const memberships = computed(() => membershipsResult.value?.person.memberships);
|
||||
|
||||
const { result: groupPostsResult, loading: groupLoading } = useQuery<{
|
||||
group: IGroup;
|
||||
}>(
|
||||
FETCH_GROUP_POSTS,
|
||||
() => ({
|
||||
preferredUsername: props.preferredUsername,
|
||||
page: postsPage.value,
|
||||
limit: POSTS_PAGE_LIMIT,
|
||||
}),
|
||||
() => ({ enabled: props.preferredUsername !== undefined })
|
||||
);
|
||||
|
||||
const group = computed(() => groupPostsResult.value?.group);
|
||||
|
||||
const { t } = useI18n({ useScope: "global" });
|
||||
|
||||
useHead({
|
||||
title: computed(() =>
|
||||
t("{group} posts", {
|
||||
group: displayName(group.value),
|
||||
})
|
||||
),
|
||||
});
|
||||
|
||||
const loading = computed(() => membershipsLoading.value || groupLoading.value);
|
||||
|
||||
const isCurrentActorMember = computed((): boolean => {
|
||||
if (!group.value || !memberships.value) return false;
|
||||
return memberships.value.elements
|
||||
.map(({ parent: { id } }) => id)
|
||||
.includes(group.value.id);
|
||||
});
|
||||
|
||||
const isCurrentActorAGroupModerator = computed((): boolean => {
|
||||
return hasCurrentActorThisRole([
|
||||
MemberRole.MODERATOR,
|
||||
MemberRole.ADMINISTRATOR,
|
||||
]);
|
||||
});
|
||||
|
||||
const hasCurrentActorThisRole = (givenRole: string | string[]): boolean => {
|
||||
const roles = Array.isArray(givenRole) ? givenRole : [givenRole];
|
||||
return (
|
||||
memberships.value !== undefined &&
|
||||
memberships.value?.total > 0 &&
|
||||
roles.includes(memberships.value?.elements[0].role)
|
||||
);
|
||||
};
|
||||
</script>
|
||||
547
src/views/Posts/PostView.vue
Normal file
547
src/views/Posts/PostView.vue
Normal file
@@ -0,0 +1,547 @@
|
||||
<template>
|
||||
<article class="container mx-auto post" v-if="post">
|
||||
<breadcrumbs-nav
|
||||
v-if="post.attributedTo"
|
||||
:links="[
|
||||
{ name: RouteName.MY_GROUPS, text: t('My groups') },
|
||||
{
|
||||
name: RouteName.GROUP,
|
||||
params: { preferredUsername: usernameWithDomain(post.attributedTo) },
|
||||
text: displayName(post.attributedTo),
|
||||
},
|
||||
{
|
||||
name: RouteName.POST,
|
||||
params: { slug: post.slug },
|
||||
text: post.title,
|
||||
},
|
||||
]"
|
||||
/>
|
||||
<header>
|
||||
<div class="flex justify-center">
|
||||
<lazy-image-wrapper :picture="post.picture" />
|
||||
</div>
|
||||
<div class="relative flex flex-col">
|
||||
<div
|
||||
class="px-2 py-3 flex flex-wrap gap-4 justify-center items-center"
|
||||
dir="auto"
|
||||
>
|
||||
<div class="flex-auto min-w-[300px] max-w-screen-lg">
|
||||
<div class="inline">
|
||||
<tag
|
||||
class="mr-2"
|
||||
variant="warning"
|
||||
size="medium"
|
||||
v-if="post.draft"
|
||||
>{{ t("Draft") }}</tag
|
||||
>
|
||||
<h1 class="inline" :lang="post.language">
|
||||
{{ post.title }}
|
||||
</h1>
|
||||
</div>
|
||||
<p class="mt-2 flex flex-col flex-wrap justify-start">
|
||||
<router-link
|
||||
:to="{
|
||||
name: RouteName.GROUP,
|
||||
params: {
|
||||
preferredUsername: usernameWithDomain(post.attributedTo),
|
||||
},
|
||||
}"
|
||||
>
|
||||
<actor-inline
|
||||
v-if="post.attributedTo"
|
||||
:actor="post.attributedTo"
|
||||
/>
|
||||
</router-link>
|
||||
<span
|
||||
class="inline-flex gap-2 items-center mt-2"
|
||||
v-if="!post.draft && post.publishAt"
|
||||
>
|
||||
<Clock :size="16" />
|
||||
{{ formatDateTimeString(post.publishAt) }}
|
||||
</span>
|
||||
<span
|
||||
class="inline-flex gap-2 items-center mt-2"
|
||||
:title="
|
||||
formatDateTimeString(post.updatedAt, undefined, true, 'short')
|
||||
"
|
||||
v-else-if="post.updatedAt"
|
||||
>
|
||||
<Clock :size="16" />
|
||||
{{
|
||||
t("Edited {relative_time} ago", {
|
||||
relative_time: formatDistanceToNowStrict(
|
||||
new Date(post.updatedAt),
|
||||
{
|
||||
locale: dateFnsLocale,
|
||||
}
|
||||
),
|
||||
})
|
||||
}}
|
||||
</span>
|
||||
<span
|
||||
v-if="post.visibility === PostVisibility.UNLISTED"
|
||||
class="flex gap-2 items-center"
|
||||
>
|
||||
<Link :size="16" />
|
||||
{{ t("Accessible only by link") }}
|
||||
</span>
|
||||
<span
|
||||
v-else-if="post.visibility === PostVisibility.PRIVATE"
|
||||
class="flex gap-2 items-center"
|
||||
>
|
||||
<Lock :size="16" />
|
||||
{{
|
||||
t("Accessible only to members", {
|
||||
group: post.attributedTo?.name,
|
||||
})
|
||||
}}
|
||||
</span>
|
||||
</p>
|
||||
</div>
|
||||
<o-dropdown position="bottom-left" aria-role="list">
|
||||
<template #trigger>
|
||||
<o-button role="button" icon-right="dots-horizontal">
|
||||
{{ t("Actions") }}
|
||||
</o-button>
|
||||
</template>
|
||||
<o-dropdown-item
|
||||
aria-role="listitem"
|
||||
has-link
|
||||
tabIndex="-1"
|
||||
v-if="
|
||||
currentActor?.id === post?.author?.id ||
|
||||
isCurrentActorAGroupModerator
|
||||
"
|
||||
>
|
||||
<router-link
|
||||
class="flex gap-1 whitespace-nowrap flex-1"
|
||||
:to="{
|
||||
name: RouteName.POST_EDIT,
|
||||
params: { slug: post.slug },
|
||||
}"
|
||||
>
|
||||
<Pencil />
|
||||
{{ t("Edit") }}
|
||||
</router-link>
|
||||
</o-dropdown-item>
|
||||
<o-dropdown-item
|
||||
aria-role="listitem"
|
||||
v-if="
|
||||
currentActor?.id === post?.author?.id ||
|
||||
isCurrentActorAGroupModerator
|
||||
"
|
||||
tabIndex="-1"
|
||||
>
|
||||
<button
|
||||
@click="openDeletePostModal"
|
||||
class="flex gap-1 whitespace-nowrap"
|
||||
>
|
||||
<Delete />
|
||||
{{ t("Delete") }}
|
||||
</button>
|
||||
</o-dropdown-item>
|
||||
|
||||
<hr
|
||||
role="presentation"
|
||||
class="dropdown-divider"
|
||||
aria-role="menuitem"
|
||||
v-if="
|
||||
currentActor?.id === post?.author?.id ||
|
||||
isCurrentActorAGroupModerator
|
||||
"
|
||||
/>
|
||||
<o-dropdown-item
|
||||
aria-role="listitem"
|
||||
v-if="!post.draft"
|
||||
tabIndex="-1"
|
||||
>
|
||||
<button
|
||||
@click="triggerShare()"
|
||||
class="flex gap-1 whitespace-nowrap"
|
||||
>
|
||||
<Share />
|
||||
{{ t("Share this event") }}
|
||||
</button>
|
||||
</o-dropdown-item>
|
||||
|
||||
<o-dropdown-item
|
||||
aria-role="listitem"
|
||||
v-if="ableToReport"
|
||||
tabIndex="-1"
|
||||
>
|
||||
<button
|
||||
@click="isReportModalActive = true"
|
||||
class="flex gap-1 whitespace-nowrap"
|
||||
>
|
||||
<Flag />
|
||||
{{ t("Report") }}
|
||||
</button>
|
||||
</o-dropdown-item>
|
||||
</o-dropdown>
|
||||
</div>
|
||||
</div>
|
||||
</header>
|
||||
<o-notification
|
||||
:title="t('Members-only post')"
|
||||
class="mx-4"
|
||||
variant="warning"
|
||||
:closable="false"
|
||||
v-if="
|
||||
!membershipsLoading &&
|
||||
!postLoading &&
|
||||
isInstanceModerator &&
|
||||
!isCurrentActorAGroupMember &&
|
||||
post.visibility === PostVisibility.PRIVATE
|
||||
"
|
||||
>
|
||||
{{
|
||||
t(
|
||||
"This post is accessible only for members. You have access to it for moderation purposes only because you are an instance moderator."
|
||||
)
|
||||
}}
|
||||
</o-notification>
|
||||
|
||||
<section
|
||||
v-html="post.body"
|
||||
dir="auto"
|
||||
class="px-2 md:px-4 py-4 prose lg:prose-xl prose-p:mt-6 dark:prose-invert bg-white dark:bg-zinc-700 mx-auto"
|
||||
:lang="post.language"
|
||||
/>
|
||||
<section class="flex gap-2 my-6 justify-center" dir="auto">
|
||||
<router-link
|
||||
v-for="tag in post.tags"
|
||||
:key="tag.title"
|
||||
:to="{ name: RouteName.TAG, params: { tag: tag.title } }"
|
||||
>
|
||||
<tag>{{ tag.title }}</tag>
|
||||
</router-link>
|
||||
</section>
|
||||
<o-modal
|
||||
:close-button-aria-label="t('Close')"
|
||||
v-model:active="isReportModalActive"
|
||||
has-modal-card
|
||||
ref="reportModal"
|
||||
:autoFocus="false"
|
||||
:trapFocus="false"
|
||||
>
|
||||
<ReportModal
|
||||
:on-confirm="reportPost"
|
||||
:title="t('Report this post')"
|
||||
:outside-domain="groupDomain"
|
||||
@close="isReportModalActive = false"
|
||||
/>
|
||||
</o-modal>
|
||||
<o-modal
|
||||
v-model:active="isShareModalActive"
|
||||
has-modal-card
|
||||
ref="shareModal"
|
||||
:close-button-aria-label="t('Close')"
|
||||
>
|
||||
<share-post-modal :post="post" />
|
||||
</o-modal>
|
||||
</article>
|
||||
</template>
|
||||
|
||||
<script lang="ts" setup>
|
||||
import { ICurrentUserRole, MemberRole, PostVisibility } from "@/types/enums";
|
||||
import { PERSON_MEMBERSHIPS } from "@/graphql/actor";
|
||||
import {
|
||||
IGroup,
|
||||
IPerson,
|
||||
usernameWithDomain,
|
||||
displayName,
|
||||
} from "@/types/actor";
|
||||
import RouteName from "@/router/name";
|
||||
import Tag from "@/components/TagElement.vue";
|
||||
import LazyImageWrapper from "@/components/Image/LazyImageWrapper.vue";
|
||||
import ActorInline from "@/components/Account/ActorInline.vue";
|
||||
import { formatDistanceToNowStrict, Locale } from "date-fns";
|
||||
import SharePostModal from "@/components/Post/SharePostModal.vue";
|
||||
import ReportModal from "@/components/Report/ReportModal.vue";
|
||||
import { useAnonymousReportsConfig } from "@/composition/apollo/config";
|
||||
import {
|
||||
useCurrentActorClient,
|
||||
usePersonStatusGroup,
|
||||
} from "@/composition/apollo/actor";
|
||||
import { useCurrentUserClient } from "@/composition/apollo/user";
|
||||
import { useMutation, useQuery } from "@vue/apollo-composable";
|
||||
import { computed, inject, ref } from "vue";
|
||||
import { IPost } from "@/types/post.model";
|
||||
import { DELETE_POST, FETCH_POST } from "@/graphql/post";
|
||||
import { useHead } from "@vueuse/head";
|
||||
import { formatDateTimeString } from "@/filters/datetime";
|
||||
import { useRouter } from "vue-router";
|
||||
import { useCreateReport } from "@/composition/apollo/report";
|
||||
import Clock from "vue-material-design-icons/Clock.vue";
|
||||
import Lock from "vue-material-design-icons/Lock.vue";
|
||||
import Pencil from "vue-material-design-icons/Pencil.vue";
|
||||
import Delete from "vue-material-design-icons/Delete.vue";
|
||||
import Share from "vue-material-design-icons/Share.vue";
|
||||
import Flag from "vue-material-design-icons/Flag.vue";
|
||||
import Link from "vue-material-design-icons/Link.vue";
|
||||
import { Dialog } from "@/plugins/dialog";
|
||||
import { useI18n } from "vue-i18n";
|
||||
import { Notifier } from "@/plugins/notifier";
|
||||
import { AbsintheGraphQLErrors } from "@/types/errors.model";
|
||||
|
||||
const props = defineProps<{
|
||||
slug: string;
|
||||
}>();
|
||||
|
||||
const { anonymousReportsConfig } = useAnonymousReportsConfig();
|
||||
const { currentUser } = useCurrentUserClient();
|
||||
const { currentActor } = useCurrentActorClient();
|
||||
|
||||
const { result: membershipsResult, loading: membershipsLoading } = useQuery<{
|
||||
person: Pick<IPerson, "memberships">;
|
||||
}>(
|
||||
PERSON_MEMBERSHIPS,
|
||||
() => ({ id: currentActor.value?.id }),
|
||||
() => ({
|
||||
enabled:
|
||||
currentActor.value?.id !== undefined && currentActor.value?.id !== null,
|
||||
})
|
||||
);
|
||||
const memberships = computed(() => membershipsResult.value?.person.memberships);
|
||||
|
||||
const {
|
||||
result: postResult,
|
||||
loading: postLoading,
|
||||
onError: onFetchPostError,
|
||||
} = useQuery<{
|
||||
post: IPost;
|
||||
}>(FETCH_POST, () => ({ slug: props.slug }));
|
||||
|
||||
const handleErrors = (errors: AbsintheGraphQLErrors): void => {
|
||||
if (
|
||||
errors.some((error) => error.status_code === 404) ||
|
||||
errors.some(({ message }) => message.includes("has invalid value $uuid"))
|
||||
) {
|
||||
router.replace({ name: RouteName.PAGE_NOT_FOUND });
|
||||
}
|
||||
};
|
||||
|
||||
onFetchPostError(({ graphQLErrors }) =>
|
||||
handleErrors(graphQLErrors as AbsintheGraphQLErrors)
|
||||
);
|
||||
|
||||
const post = computed(() => postResult.value?.post);
|
||||
|
||||
usePersonStatusGroup(usernameWithDomain(post.value?.attributedTo as IGroup));
|
||||
|
||||
useHead({
|
||||
title: computed(
|
||||
() => `${post.value?.title} - ${displayName(post.value?.attributedTo)}`
|
||||
),
|
||||
});
|
||||
|
||||
const notifier = inject<Notifier>("notifier");
|
||||
|
||||
const isShareModalActive = ref(false);
|
||||
const isReportModalActive = ref(false);
|
||||
const reportModal = ref();
|
||||
|
||||
const isInstanceModerator = computed((): boolean => {
|
||||
return (
|
||||
currentUser.value?.role !== undefined &&
|
||||
[ICurrentUserRole.ADMINISTRATOR, ICurrentUserRole.MODERATOR].includes(
|
||||
currentUser.value?.role
|
||||
)
|
||||
);
|
||||
});
|
||||
|
||||
const ableToReport = computed((): boolean => {
|
||||
return (
|
||||
currentActor.value?.id != undefined ||
|
||||
anonymousReportsConfig.value?.allowed === true
|
||||
);
|
||||
});
|
||||
|
||||
const triggerShare = (): void => {
|
||||
if (navigator.share) {
|
||||
navigator
|
||||
.share({
|
||||
title: post.value?.title,
|
||||
url: post.value?.url,
|
||||
})
|
||||
.then(() => console.debug("Successful share"))
|
||||
.catch((error: any) => console.debug("Error sharing", error));
|
||||
} else {
|
||||
isShareModalActive.value = true;
|
||||
// send popup
|
||||
}
|
||||
};
|
||||
|
||||
const {
|
||||
mutate: createReportMutation,
|
||||
onDone: onCreateReportDone,
|
||||
onError: onCreateReportError,
|
||||
} = useCreateReport();
|
||||
|
||||
onCreateReportDone(() => {
|
||||
isReportModalActive.value = false;
|
||||
reportModal.value.close();
|
||||
const postTitle = post.value?.title;
|
||||
notifier?.success(t("Post {eventTitle} reported", { postTitle }));
|
||||
});
|
||||
|
||||
onCreateReportError((error) => {
|
||||
console.error(error);
|
||||
});
|
||||
|
||||
const reportPost = async (content: string, forward: boolean): Promise<void> => {
|
||||
createReportMutation({
|
||||
// postId: post.value?.id,
|
||||
reportedId: post.value?.attributedTo?.id as string,
|
||||
content,
|
||||
forward,
|
||||
});
|
||||
};
|
||||
const groupDomain = computed((): string | undefined | null => {
|
||||
return post.value?.attributedTo?.domain;
|
||||
});
|
||||
|
||||
const dateFnsLocale = inject<Locale>("dateFnsLocale");
|
||||
|
||||
const isCurrentActorAGroupModerator = computed((): boolean => {
|
||||
return hasCurrentActorThisRole([
|
||||
MemberRole.MODERATOR,
|
||||
MemberRole.ADMINISTRATOR,
|
||||
]);
|
||||
});
|
||||
|
||||
const hasCurrentActorThisRole = (givenRole: string | string[]): boolean => {
|
||||
const roles = Array.isArray(givenRole)
|
||||
? givenRole
|
||||
: ([givenRole] as MemberRole[]);
|
||||
return (
|
||||
(memberships.value?.total ?? 0) > 0 &&
|
||||
roles.includes(memberships.value?.elements[0].role as MemberRole)
|
||||
);
|
||||
};
|
||||
|
||||
const isCurrentActorAGroupMember = computed((): boolean => {
|
||||
return hasCurrentActorThisRole([
|
||||
MemberRole.MODERATOR,
|
||||
MemberRole.ADMINISTRATOR,
|
||||
MemberRole.MEMBER,
|
||||
]);
|
||||
});
|
||||
|
||||
const { t } = useI18n({ useScope: "global" });
|
||||
const dialog = inject<Dialog>("dialog");
|
||||
|
||||
const openDeletePostModal = async (): Promise<void> => {
|
||||
dialog?.confirm({
|
||||
variant: "danger",
|
||||
title: t("Delete post"),
|
||||
message: t(
|
||||
"Are you sure you want to delete this post? This action cannot be reverted."
|
||||
),
|
||||
onConfirm: () =>
|
||||
deletePost({
|
||||
id: post.value?.id,
|
||||
}),
|
||||
});
|
||||
};
|
||||
|
||||
const router = useRouter();
|
||||
|
||||
const { mutate: deletePost, onDone: onDeletePostDone } =
|
||||
useMutation(DELETE_POST);
|
||||
|
||||
onDeletePostDone(({ data }) => {
|
||||
if (data && post.value?.attributedTo) {
|
||||
router.push({
|
||||
name: RouteName.POSTS,
|
||||
params: {
|
||||
preferredUsername: usernameWithDomain(post.value?.attributedTo),
|
||||
},
|
||||
});
|
||||
}
|
||||
});
|
||||
</script>
|
||||
<style lang="scss" scoped>
|
||||
@use "@/styles/_mixins" as *;
|
||||
article.post {
|
||||
header {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
.banner-container {
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
height: 30vh;
|
||||
}
|
||||
|
||||
.heading-section {
|
||||
position: relative;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
margin-bottom: 2rem;
|
||||
|
||||
.heading-wrapper {
|
||||
padding: 15px 10px;
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
|
||||
.title-metadata {
|
||||
min-width: 300px;
|
||||
flex: 20;
|
||||
|
||||
.title-wrapper {
|
||||
display: inline;
|
||||
|
||||
.tag {
|
||||
height: 38px;
|
||||
vertical-align: text-bottom;
|
||||
}
|
||||
|
||||
& > h1 {
|
||||
display: inline;
|
||||
}
|
||||
}
|
||||
|
||||
p.metadata {
|
||||
margin-top: 10px;
|
||||
display: flex;
|
||||
justify-content: flex-start;
|
||||
flex-wrap: wrap;
|
||||
flex-direction: column;
|
||||
|
||||
*:not(:first-child) {
|
||||
@include padding-left(5px);
|
||||
}
|
||||
}
|
||||
}
|
||||
p.buttons {
|
||||
flex: 1;
|
||||
}
|
||||
}
|
||||
|
||||
h1.title {
|
||||
margin: 0;
|
||||
font-weight: 500;
|
||||
font-family: "Roboto", "Helvetica", "Arial", serif;
|
||||
}
|
||||
|
||||
.authors {
|
||||
display: inline-block;
|
||||
}
|
||||
|
||||
&::after {
|
||||
height: 0.2rem;
|
||||
content: " ";
|
||||
display: block;
|
||||
}
|
||||
|
||||
.buttons {
|
||||
justify-content: center;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
margin: 0 auto;
|
||||
}
|
||||
</style>
|
||||
Reference in New Issue
Block a user