Skip to content
This repository has been archived by the owner on Nov 28, 2023. It is now read-only.

Commit

Permalink
Merge pull request #39 from gudfhr95/develop
Browse files Browse the repository at this point in the history
v0.3.0
  • Loading branch information
gudfhr95 authored Nov 29, 2022
2 parents 745fde1 + c783883 commit ed307fb
Show file tree
Hide file tree
Showing 21 changed files with 101 additions and 84 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ dist
# misc
.DS_Store
*.pem
data

# debug
logs
Expand Down
1 change: 0 additions & 1 deletion apps/schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,6 @@ type Post implements BaseEntity {
text: String
linkUrl: String
linkMetadata: LinkMetadata
linkMetadatas: [LinkMetadata!]!
images: [PostImage!]!
thumbnailUrl: String
author: User
Expand Down
9 changes: 0 additions & 9 deletions apps/server/migrations/.snapshot-stelllar.json
Original file line number Diff line number Diff line change
Expand Up @@ -518,15 +518,6 @@
"nullable": true,
"mappedType": "json"
},
"link_metadatas": {
"name": "link_metadatas",
"type": "jsonb",
"unsigned": false,
"autoincrement": false,
"primary": false,
"nullable": false,
"mappedType": "json"
},
"images": {
"name": "images",
"type": "jsonb",
Expand Down
2 changes: 1 addition & 1 deletion apps/server/migrations/Migration20221124115718.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ export class Migration20221124115718 extends Migration {
'alter table "server" add column "post_count" int not null default 0;'
);
this.addSql(
"UPDATE server SET post_count = (select count(*) from post where server_id=server.id)"
"update server set post_count = (select count(*) from post where server_id=server.id and is_deleted=false)"
);
}

Expand Down
13 changes: 13 additions & 0 deletions apps/server/migrations/Migration20221129080217.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { Migration } from '@mikro-orm/migrations';

export class Migration20221129080217 extends Migration {

async up(): Promise<void> {
this.addSql('alter table "post" drop column "link_metadatas";');
}

async down(): Promise<void> {
this.addSql('alter table "post" add column "link_metadatas" jsonb not null;');
}

}
4 changes: 0 additions & 4 deletions apps/server/src/post/entity/post.entity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,6 @@ export class Post extends BaseEntity {
@Embedded({ entity: () => LinkMetadata, nullable: true, object: true })
linkMetadata?: LinkMetadata;

@Field(() => [LinkMetadata])
@Embedded(() => LinkMetadata, { object: true, array: true })
linkMetadatas: LinkMetadata[] = [];

@Field(() => [PostImage])
@Embedded(() => PostImage, { object: true, array: true })
images: PostImage[] = [];
Expand Down
26 changes: 25 additions & 1 deletion apps/server/src/post/post.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ export class PostService {

async getPostById(postId: string) {
return await this.postRepository.findOneOrFail(
{ id: postId },
{ id: postId, isDeleted: false },
{ populate: ["author", "server"] }
);
}
Expand Down Expand Up @@ -254,6 +254,30 @@ export class PostService {

await this.postRepository.persistAndFlush(post);

if (post.linkMetadata) {
const { image } = post.linkMetadata;

await this.fileService.deleteFileInS3ByUrl(image.originalUrl);
await this.fileService.deleteFileInS3ByUrl(image.smallUrl);
await this.fileService.deleteFileInS3ByUrl(image.popupUrl);
}

if (post.images) {
await Promise.all(
post.images.map(async (postImage) => {
const { image } = postImage;

await this.fileService.deleteFileInS3ByUrl(image.originalUrl);
await this.fileService.deleteFileInS3ByUrl(image.smallUrl);
await this.fileService.deleteFileInS3ByUrl(image.popupUrl);
})
);
}

post.server.postCount -= 1;

await this.serverRepository.persistAndFlush(post.server);

return post;
}

Expand Down
20 changes: 4 additions & 16 deletions apps/server/src/server/server.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,7 @@ export class ServerService {
if (avatarFile) {
avatarUrl = await this.fileService.uploadSingleFile(
avatarFile,
{
width: 256,
height: 256,
},
{ width: 256, height: 256 },
true
);
}
Expand All @@ -55,10 +52,7 @@ export class ServerService {
if (bannerFile) {
bannerUrl = await this.fileService.uploadSingleFile(
bannerFile,
{
width: 256,
height: 256,
},
{ width: 1920, height: 1080 },
true
);
}
Expand Down Expand Up @@ -113,10 +107,7 @@ export class ServerService {

avatarUrl = await this.fileService.uploadSingleFile(
avatarFile,
{
width: 256,
height: 256,
},
{ width: 256, height: 256 },
true
);
}
Expand All @@ -132,10 +123,7 @@ export class ServerService {

bannerUrl = await this.fileService.uploadSingleFile(
bannerFile,
{
width: 256,
height: 256,
},
{ width: 1920, height: 1080 },
true
);
}
Expand Down
2 changes: 1 addition & 1 deletion apps/web/pages/404.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export default function NotFoundPage() {
<Head>
<title>404 - Stelllar</title>
</Head>
<div className="w-full flex flex-col items-center justify-center text-primary">
<div className="w-full h-full flex flex-col items-center justify-center text-primary bg-gray-750">
<img
alt="astronaut"
src={astronaut.src}
Expand Down
2 changes: 1 addition & 1 deletion apps/web/pages/500.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export default function InternalServerErrorPage() {
<Head>
<title>500 - Stelllar</title>
</Head>
<div className="w-full flex flex-col items-center justify-center text-primary">
<div className="w-full h-full flex flex-col items-center justify-center text-primary bg-gray-750">
<img
alt="astronaut"
src={astronaut.src}
Expand Down
5 changes: 4 additions & 1 deletion apps/web/public/locales/en/post.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,10 @@
"ago": "ago",
"endReached": "No more posts",
"menu": {
"copyLink": "Copy to Clipboard",
"copyLink": {
"label": "Copy Link to Clipboard",
"success": "Successfully copied link to clipboard"
},
"edit": "Edit",
"delete": "Delete"
}
Expand Down
5 changes: 4 additions & 1 deletion apps/web/public/locales/ko/post.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,10 @@
"ago": "",
"endReached": "게시글이 없습니다.",
"menu": {
"copyLink": "링크 복사",
"copyLink": {
"label": "링크 복사",
"success": "링크가 클립보드에 복사되었습니다."
},
"edit": "수정",
"delete": "삭제"
}
Expand Down
7 changes: 4 additions & 3 deletions apps/web/src/components/comment/Comment.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ import * as Locales from "date-fns/locale";
import { useTranslation } from "next-i18next";
import { useRouter } from "next/router";
import { useState } from "react";
import toast from "react-hot-toast";
import { Post, useCommentVoteMutation, VoteType } from "../../graphql/hooks";
import useAuth from "../../hooks/useAuth";
import { useEditComment } from "../../hooks/useEditComment";
import { useLoginDialog } from "../../hooks/useLoginDialog";
import { useReplyComment } from "../../hooks/useReplyComment";
import ContextMenuTrigger from "../ui/context/ContextMenuTrigger";
import { ContextMenuType } from "../ui/context/ContextMenuType";
Expand Down Expand Up @@ -50,14 +50,15 @@ export default function Comment({

const [commentVote] = useCommentVoteMutation();

const { setLoginDialog } = useLoginDialog();
const { replyingCommentId, setReplyingCommentId } = useReplyComment();
const { editingCommentId, setEditingCommentId } = useEditComment();

const [collapse, setCollapse] = useState(false);

const onClickUpVote = (e: any) => {
if (!user) {
toast.error("Login to vote");
setLoginDialog(true);
return;
}

Expand All @@ -73,7 +74,7 @@ export default function Comment({

const onClickDownVote = (e: any) => {
if (!user) {
toast.error("Login to vote");
setLoginDialog(true);
return;
}

Expand Down
2 changes: 1 addition & 1 deletion apps/web/src/components/post/EditPostDialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,7 @@ export default function EditPostDialog({ post }: EditPostDialog) {
onSubmit={handleSubmit(onSubmit)}
className="max-w-screen-md w-full dark:bg-gray-800 bg-white text-left rounded-xl"
>
<div className="grid grid-cols-4">
<div className="grid grid-cols-3">
<ServerSelect
servers={user ? user.servers : []}
server={server}
Expand Down
10 changes: 6 additions & 4 deletions apps/web/src/components/post/Post.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@ import { useTranslation } from "next-i18next";
import Link from "next/link";
import { useRouter } from "next/router";
import { useMemo, useState } from "react";
import toast from "react-hot-toast";
import {
Post as PostType,
usePostVoteMutation,
VoteType,
} from "../../graphql/hooks";
import useAuth from "../../hooks/useAuth";
import { useLoginDialog } from "../../hooks/useLoginDialog";
import { createCommentTree } from "../../utils/commentUtils";
import Comment from "../comment/Comment";
import CreateCommentCard from "../comment/CreateCommentCard";
Expand Down Expand Up @@ -41,6 +41,8 @@ export default function Post({ post, comments, className = "" }: IPost) {

const [postVote] = usePostVoteMutation();

const { setLoginDialog } = useLoginDialog();

const [currentImage, setCurrentImage] = useState(0);

const commentsTree = useMemo(
Expand All @@ -50,7 +52,7 @@ export default function Post({ post, comments, className = "" }: IPost) {

const onClickUpVote = (e: any) => {
if (!user) {
toast.error("Login to vote");
setLoginDialog(true);
return;
}

Expand All @@ -66,7 +68,7 @@ export default function Post({ post, comments, className = "" }: IPost) {

const onClickDownVote = (e: any) => {
if (!user) {
toast.error("Login to vote");
setLoginDialog(true);
return;
}

Expand All @@ -84,7 +86,7 @@ export default function Post({ post, comments, className = "" }: IPost) {
<>
<div className="md:pt-4 md:px-4 px-0 pt-0">
<div
className={`${className} cursor-pointer relative group hover:shadow dark:bg-gray-800 dark:hover:bg-gray-825 bg-gray-200 px-2 py-3 md:rounded flex hover:bg-gray-300`}
className={`${className} relative group dark:bg-gray-800 bg-gray-200 px-2 py-3 md:rounded flex`}
>
<div className="flex flex-col items-center pr-2">
<button
Expand Down
20 changes: 15 additions & 5 deletions apps/web/src/components/post/PostContextMenu.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
import { useTranslation } from "next-i18next";
import { useRouter } from "next/router";
import toast from "react-hot-toast";
import { useCopyToClipboard } from "react-use";
import { useDeletePostMutation } from "../../graphql/hooks";
import useAuth from "../../hooks/useAuth";
import { useEditPostDialog } from "../../hooks/useEditPostDialog";
import ContextMenuSection from "../ui/context/ContextMenuSection";
import EditPostDialog from "./EditPostDialog";

export default function PostContextMenu({ post, ContextMenuItem }: any) {
const { t } = useTranslation("post");
Expand All @@ -17,6 +19,13 @@ export default function PostContextMenu({ post, ContextMenuItem }: any) {

const { setEditPostDialog } = useEditPostDialog();

const onClickCopyLink = () => {
copyToClipboard(
`${location.origin}/planets/${post.server.name}/posts/${post.id}`
);
toast.success(t("menu.copyLink.success"));
};

const onClickEdit = () => {
setEditPostDialog(true);
};
Expand All @@ -30,13 +39,14 @@ export default function PostContextMenu({ post, ContextMenuItem }: any) {
const canManagePost = user?.isAdmin || post.author.id === user?.id;
return (
<>
<EditPostDialog post={post} />

<ContextMenuSection>
<ContextMenuItem
onClick={() => {
copyToClipboard(`${location.origin}${router.asPath}`);
}}
label={t("menu.copyLink")}
/>{" "}
onClick={onClickCopyLink}
label={t("menu.copyLink.label")}
/>

{canManagePost && (
<>
<ContextMenuItem label={t("menu.edit")} onClick={onClickEdit} />
Expand Down
23 changes: 16 additions & 7 deletions apps/web/src/components/post/PostListItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,11 @@ import { useTranslation } from "next-i18next";
import Link from "next/link";
import { useRouter } from "next/router";
import { memo } from "react";
import toast from "react-hot-toast";
import { Post, usePostVoteMutation, User, VoteType } from "../../graphql/hooks";
import { useLoginDialog } from "../../hooks/useLoginDialog";
import ServerAvatar from "../server/ServerAvatar";
import ContextMenuTrigger from "../ui/context/ContextMenuTrigger";
import { ContextMenuType } from "../ui/context/ContextMenuType";
import {
IconChat,
IconChevronDown,
Expand All @@ -31,11 +33,13 @@ export default memo(function PostItem({

const [postVote] = usePostVoteMutation();

const { setLoginDialog } = useLoginDialog();

const onClickUpVote = (e: any) => {
e.stopPropagation();

if (!user) {
toast.error("Login to vote");
setLoginDialog(true);
return;
}

Expand All @@ -53,7 +57,7 @@ export default memo(function PostItem({
e.stopPropagation();

if (!user) {
toast.error("Login to vote");
setLoginDialog(true);
return;
}

Expand Down Expand Up @@ -165,11 +169,16 @@ export default memo(function PostItem({
<div className="ml-2 text-xs font-medium">{post.commentCount}</div>
</div>

<div
className={`ml-2 text-gray-500 hover:text-gray-700 dark:hover:text-gray-300 flex items-center cursor-pointer`}
<ContextMenuTrigger
data={{ type: ContextMenuType.Post, post }}
leftClick
>
<IconDotsVertical className="text-disabled w-4 h-4" />
</div>
<div
className={`ml-2 text-gray-500 hover:text-gray-700 dark:hover:text-gray-300 flex items-center cursor-pointer`}
>
<IconDotsVertical className="w-4 h-4" />
</div>
</ContextMenuTrigger>
</div>
</div>
</div>
Expand Down
Loading

0 comments on commit ed307fb

Please sign in to comment.