post author link

This commit is contained in:
Stepan Usatiuk
2023-12-17 14:22:50 +01:00
parent 92f3bebede
commit f69c33358b
6 changed files with 27 additions and 5 deletions

View File

@@ -23,10 +23,24 @@
.info {
flex-grow: 1;
align-self: start;
> * {
margin-left: 0.5rem;
}
> *:first-child {
margin-left: 0;
}
a {
color: inherit;
}
}
.actions {
align-self: end;
button {
background: none;
border: none;

View File

@@ -1,14 +1,16 @@
import "./Post.scss";
import { Form } from "react-router-dom";
import { Form, Link } from "react-router-dom";
export function Post({
text,
createdDate,
actions,
authorUsername,
id,
}: {
text: string;
createdDate: string;
authorUsername: string;
actions: boolean;
id: number;
}) {
@@ -18,6 +20,12 @@ export function Post({
<div className={"footer"}>
<div className={"info"}>
<span className={"createdDate"}>{createdDate}</span>
<Link
className={"authorLink"}
to={"/home/profile/" + authorUsername}
>
by {authorUsername}
</Link>
</div>
{actions && (
<div className={"actions"}>

View File

@@ -20,6 +20,7 @@ export function PostList({
createdDate={`${date.toUTCString()}`}
key={p.id}
id={p.id}
authorUsername={p.authorUsername}
actions={selfUuid == p.authorUuid}
/>
);

View File

@@ -58,6 +58,7 @@ export const PostTo = z.object({
authorUuid: z.string(),
text: z.string(),
createdAt: z.number(),
authorUsername: z.string(),
});
export type TPostTo = z.infer<typeof PostTo>;

View File

@@ -1,6 +1,4 @@
package com.usatiuk.tjv.y.server.dto;
import com.usatiuk.tjv.y.server.entity.Post;
public record PostTo(Long id, String authorUuid, String text, Long createdAt) {
public record PostTo(Long id, String authorUuid, String authorUsername, String text, Long createdAt) {
}

View File

@@ -5,6 +5,6 @@ import com.usatiuk.tjv.y.server.entity.Post;
public class PostMapper {
public static PostTo makeDto(Post post) {
return new PostTo(post.getId(), post.getAuthor().getUuid(), post.getText(), post.getCreatedAt().getEpochSecond());
return new PostTo(post.getId(), post.getAuthor().getUuid(), post.getAuthor().getUsername(), post.getText(), post.getCreatedAt().getEpochSecond());
}
}