Refactoring of most components regarding props and, Lint corrections
This commit is contained in:
parent
2e23c7919f
commit
146518b94a
12 changed files with 59 additions and 88 deletions
|
@ -1,17 +1,14 @@
|
||||||
import { JSXElement } from "solid-js";
|
import { JSXElement } from "solid-js";
|
||||||
|
|
||||||
import { CommentsIcon } from "../../Util/Icons";
|
import { CommentsIcon } from "../../Util/Icons";
|
||||||
import { Post } from "../../Util/api";
|
|
||||||
|
|
||||||
export default function CommentsBUtton({ post }: { post: Post }): JSXElement {
|
export default function CommentsButton(): JSXElement {
|
||||||
return (
|
return (
|
||||||
<>
|
<div class="flex p-1">
|
||||||
<div class="flex p-1">
|
<CommentsIcon />
|
||||||
<CommentsIcon />
|
<span class="text-1xl countdown px-1.5 pt-1.5 text-center">
|
||||||
<span class="text-1xl countdown text-center pt-1.5 px-1.5">
|
<p style={{ "--value": 12 }}></p>
|
||||||
<p style={{ "--value": 11 }}>{post.comments}</p>
|
</span>
|
||||||
</span>
|
</div>
|
||||||
</div>
|
|
||||||
</>
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,20 +1,19 @@
|
||||||
import { JSXElement } from "solid-js";
|
import { JSXElement } from "solid-js";
|
||||||
|
|
||||||
import { EngagementIcon } from "../../Util/Icons";
|
import { EngagementIcon } from "../../Util/Icons";
|
||||||
import { Post } from "../../Util/api";
|
|
||||||
|
|
||||||
export default function EngagementButton({ post }: { post: Post }): JSXElement {
|
export default function EngagementButton(): JSXElement {
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<div class="flex p-1">
|
<div class="flex p-1">
|
||||||
<button
|
<button
|
||||||
class="btn btn-xs hover:border-primary rounded-base"
|
class="rounded-base btn btn-xs hover:border-primary"
|
||||||
aria-label="Show sign of engagement"
|
aria-label="Show sign of engagement"
|
||||||
>
|
>
|
||||||
<EngagementIcon />
|
<EngagementIcon />
|
||||||
</button>
|
</button>
|
||||||
<span class="text-1xl countdown text-center pt-1.5 px-1.5">
|
<span class="text-1xl countdown px-1.5 pt-1.5 text-center">
|
||||||
<p style={{ "--value": 46 }}>{post.votes}</p>
|
<p style={{ "--value": 46 }}></p>
|
||||||
</span>
|
</span>
|
||||||
</div>
|
</div>
|
||||||
</>
|
</>
|
||||||
|
|
|
@ -1,9 +1,8 @@
|
||||||
import { JSXElement } from "solid-js";
|
import { JSXElement } from "solid-js";
|
||||||
|
|
||||||
import { RemovePostIcon } from "../../Util/Icons";
|
import { RemovePostIcon } from "../../Util/Icons";
|
||||||
import { Post } from "../../Util/api";
|
|
||||||
|
|
||||||
export default function RemovePostButton({ post }: { post: Post }): JSXElement {
|
export default function RemovePostButton(): JSXElement {
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<div class="flex p-1">
|
<div class="flex p-1">
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
import { JSXElement, Show, useContext } from "solid-js";
|
import { JSXElement, Show, useContext } from "solid-js";
|
||||||
|
|
||||||
import { LoginContext } from "../../Context/GlobalState";
|
import { LoginContext } from "../../Context/GlobalState";
|
||||||
import { ReplyIcon, ReportIcon } from "../../Util/Icons";
|
import { ReplyIcon } from "../../Util/Icons";
|
||||||
|
|
||||||
export default function ReplyButton(): JSXElement {
|
export default function ReplyButton(): JSXElement {
|
||||||
const login_ctx = useContext(LoginContext)!;
|
const login_ctx = useContext(LoginContext)!;
|
||||||
|
|
|
@ -1,24 +1,21 @@
|
||||||
import { useNavigate } from "@solidjs/router";
|
import { useNavigate } from "@solidjs/router";
|
||||||
import { JSXElement } from "solid-js";
|
import { JSXElement } from "solid-js";
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
import { Arrow } from "../../Util/Icons";
|
import { Arrow } from "../../Util/Icons";
|
||||||
import { Post } from "../../Util/api";
|
import { Post } from "../../Util/api";
|
||||||
|
|
||||||
|
export default function ToPostButton(props: { post: Post }): JSXElement {
|
||||||
export default function ToPostButton({ post }: { post: Post }): JSXElement {
|
const nav = useNavigate();
|
||||||
const nav = useNavigate();
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div class="p-1">
|
<div class="p-1">
|
||||||
<button
|
<button
|
||||||
onClick={(): void => nav("/post/" + post.id)}
|
onClick={(): void => nav("/post/" + props.post.id)} // Accessing props.post directly
|
||||||
class="btn btn-xs hover:border-primary"
|
class="btn btn-xs hover:border-primary"
|
||||||
aria-label="View post"
|
aria-label="View post"
|
||||||
>
|
>
|
||||||
<Arrow />
|
<Arrow />
|
||||||
</button>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,27 +7,23 @@ interface CommentProps {
|
||||||
comment: PublicComment;
|
comment: PublicComment;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
export function Comment(props: CommentProps): JSXElement {
|
||||||
* Comment is a component that displays a single comment.
|
|
||||||
* @param {Object} props The properties for the Comment component.
|
|
||||||
* @param {string} props.postId The id of the post that the comment is a reply to.
|
|
||||||
* @returns {JSXElement} A JSXElement of a comment
|
|
||||||
*/
|
|
||||||
export function Comment({ comment }: CommentProps): JSXElement {
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<div class="chat chat-start py-5">
|
<div class="chat chat-start py-5">
|
||||||
<time class="text-xs opacity-50">{comment.created_at}</time>
|
<time class="text-xs opacity-50">{props.comment.created_at}</time>
|
||||||
</div>
|
</div>
|
||||||
<div class="chat-">{comment.content}</div>
|
<div class="chat-">{props.comment.content}</div>
|
||||||
<div class="divider"></div>
|
<div class="divider"></div>
|
||||||
<div class="chat chat-end">
|
<div class="chat chat-end">
|
||||||
<div class="flex-col">
|
<div class="flex-col">
|
||||||
<time class="text-xs opacity-50 time-end">Reply created_at</time>
|
<time class="time-end text-xs opacity-50">Reply created_at</time>
|
||||||
<div class="chat-end">Replies to parent comment if any</div>
|
<div class="chat-end">Replies to parent comment if any</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="divider divider-end"><ReplyButton/></div>
|
<div class="divider divider-end">
|
||||||
|
<ReplyButton />
|
||||||
|
</div>
|
||||||
</>
|
</>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,17 +3,13 @@ import { For, JSXElement, createResource } from "solid-js";
|
||||||
import { getComments } from "../Util/api";
|
import { getComments } from "../Util/api";
|
||||||
import { Comment } from "./Comment";
|
import { Comment } from "./Comment";
|
||||||
|
|
||||||
/**
|
export function CommentSection(props: { postId: string }): JSXElement {
|
||||||
* CommentSection is a component that displays a collection of comments.
|
const [comments] = createResource(props.postId, () =>
|
||||||
* @param {Object} props The properties for the CommentSection component.
|
getComments(props.postId, 10, 0)
|
||||||
* @param {string} props.postId The id of the post that the comments are a reply to.
|
);
|
||||||
* @returns {JSXElement} A JSXElement that contains a collection of comments.
|
|
||||||
*/
|
|
||||||
export function CommentSection({ postId }: { postId: string }): JSXElement {
|
|
||||||
const [comments] = createResource(postId, () => getComments(postId, 10, 0));
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<section class="p-5 my-5 bg-base-200 border-b-2 border-b-primary ">
|
<section class="my-5 border-b-2 border-b-primary bg-base-200 p-5 ">
|
||||||
<For each={comments()!}>{(comment) => <Comment comment={comment} />}</For>
|
<For each={comments()!}>{(comment) => <Comment comment={comment} />}</For>
|
||||||
</section>
|
</section>
|
||||||
);
|
);
|
||||||
|
|
|
@ -1,7 +1,6 @@
|
||||||
import { JSXElement, Show, createSignal, useContext } from "solid-js";
|
import { JSXElement, Show, createSignal, useContext } from "solid-js";
|
||||||
|
|
||||||
import { LoginContext, ModalContext } from "../Context/GlobalState";
|
import { LoginContext, ModalContext } from "../Context/GlobalState";
|
||||||
import { UserCircle } from "../Util/Icons";
|
|
||||||
|
|
||||||
export function LoginButton(): JSXElement {
|
export function LoginButton(): JSXElement {
|
||||||
const modal_ctx = useContext(ModalContext)!;
|
const modal_ctx = useContext(ModalContext)!;
|
||||||
|
@ -35,7 +34,7 @@ export function LoginButton(): JSXElement {
|
||||||
{showLogoutModal() && (
|
{showLogoutModal() && (
|
||||||
<div
|
<div
|
||||||
role="alert"
|
role="alert"
|
||||||
class="absolute top-10 z-10 flex rounded-md bg-base-200 border-2 border-info"
|
class="absolute top-10 z-10 flex rounded-md border-2 border-info bg-base-200"
|
||||||
>
|
>
|
||||||
<div class="relative p-5">
|
<div class="relative p-5">
|
||||||
<p>Do you wish to logout?</p>
|
<p>Do you wish to logout?</p>
|
||||||
|
|
|
@ -2,7 +2,7 @@ import { A } from "@solidjs/router";
|
||||||
import { JSXElement, Show, useContext } from "solid-js";
|
import { JSXElement, Show, useContext } from "solid-js";
|
||||||
|
|
||||||
import { LoginContext } from "../Context/GlobalState";
|
import { LoginContext } from "../Context/GlobalState";
|
||||||
import { Home, Plus } from "../Util/Icons";
|
import { Plus } from "../Util/Icons";
|
||||||
|
|
||||||
// Represents a single list item in the menu bar
|
// Represents a single list item in the menu bar
|
||||||
export function MenuItem(props: {
|
export function MenuItem(props: {
|
||||||
|
@ -23,7 +23,7 @@ export function Menu(): JSXElement {
|
||||||
const login_ctx = useContext(LoginContext)!;
|
const login_ctx = useContext(LoginContext)!;
|
||||||
return (
|
return (
|
||||||
<Show when={login_ctx.loggedIn()}>
|
<Show when={login_ctx.loggedIn()}>
|
||||||
<ul class="menu menu-horizontal space-y-0 space-x-2 rounded-box md:space-x-5 md:space-y-0">
|
<ul class="menu menu-horizontal space-x-2 space-y-0 rounded-box md:space-x-5 md:space-y-0">
|
||||||
<MenuItem href="/new">
|
<MenuItem href="/new">
|
||||||
<Plus />
|
<Plus />
|
||||||
</MenuItem>
|
</MenuItem>
|
||||||
|
|
|
@ -4,26 +4,23 @@ import { JSXElement, Show, createSignal, useContext } from "solid-js";
|
||||||
import { LoginContext } from "../Context/GlobalState";
|
import { LoginContext } from "../Context/GlobalState";
|
||||||
import { NewComment, createComment } from "../Util/api";
|
import { NewComment, createComment } from "../Util/api";
|
||||||
|
|
||||||
interface NewCommentInputAreaProps {
|
|
||||||
parentPostId: number;
|
|
||||||
parentCommentId: number | null;
|
|
||||||
}
|
|
||||||
|
|
||||||
/** NewCommentInputArea is a component that allows users to submit a comment on a **post or comment**.
|
/** NewCommentInputArea is a component that allows users to submit a comment on a **post or comment**.
|
||||||
* @param {Object} props The properties for the NewCommentInputArea component.
|
* @param {Object} props The properties for the NewCommentInputArea component.
|
||||||
* @param {number} props.parentPostId The id of the post that the comment is a reply to.
|
* @param {number} props.parentPostId The id of the post that the comment is a reply to.
|
||||||
* @returns {JSXElement} A JSXElement that contains a textarea and a submit button.
|
* @returns {JSXElement} A JSXElement that contains a textarea and a submit button.
|
||||||
*/
|
*/
|
||||||
export function NewCommentInputArea({
|
|
||||||
parentPostId,
|
interface NewCommentInputAreaProps {
|
||||||
parentCommentId,
|
parentPostId: number;
|
||||||
}: NewCommentInputAreaProps): JSXElement {
|
parentCommentId: number | null;
|
||||||
|
}
|
||||||
|
|
||||||
|
export function NewCommentInputArea(
|
||||||
|
props: NewCommentInputAreaProps
|
||||||
|
): JSXElement {
|
||||||
const [content, setContent] = createSignal("");
|
const [content, setContent] = createSignal("");
|
||||||
const [waiting, setWaiting] = createSignal(false);
|
const [waiting, setWaiting] = createSignal(false);
|
||||||
|
|
||||||
// We assumte this context is always available
|
|
||||||
const login_ctx = useContext(LoginContext)!;
|
const login_ctx = useContext(LoginContext)!;
|
||||||
|
|
||||||
const nav = useNavigate();
|
const nav = useNavigate();
|
||||||
|
|
||||||
const sendComment = (): void => {
|
const sendComment = (): void => {
|
||||||
|
@ -32,15 +29,15 @@ export function NewCommentInputArea({
|
||||||
const response = createComment({
|
const response = createComment({
|
||||||
content: content(),
|
content: content(),
|
||||||
user_token: login_ctx.token(),
|
user_token: login_ctx.token(),
|
||||||
parent_post_id: parentPostId,
|
parent_post_id: props.parentPostId,
|
||||||
parent_comment_id: parentCommentId,
|
parent_comment_id: props.parentCommentId,
|
||||||
} as NewComment);
|
} as NewComment);
|
||||||
|
|
||||||
if (response) {
|
if (response) {
|
||||||
response.then(() => {
|
response.then(() => {
|
||||||
setWaiting(false);
|
setWaiting(false);
|
||||||
setContent("");
|
setContent("");
|
||||||
nav("/post/" + parentPostId);
|
nav("/post/" + props.parentPostId);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
|
@ -1,22 +1,15 @@
|
||||||
import { JSXElement, Show } from "solid-js";
|
import { JSXElement, Show } from "solid-js";
|
||||||
|
|
||||||
import { Post } from "../Util/api";
|
import { Post } from "../Util/api";
|
||||||
import EngagementButton from "./Buttons/Engegament";
|
|
||||||
import CommentsBUtton from "./Buttons/CommentsButton";
|
import CommentsBUtton from "./Buttons/CommentsButton";
|
||||||
|
import EngagementButton from "./Buttons/Engegament";
|
||||||
|
import RemovePostButton from "./Buttons/RemovePostButton";
|
||||||
import ReportButton from "./Buttons/Report";
|
import ReportButton from "./Buttons/Report";
|
||||||
import ToPostButton from "./Buttons/ToPost";
|
import ToPostButton from "./Buttons/ToPost";
|
||||||
import RemovePostButton from "./Buttons/RemovePostButton";
|
|
||||||
|
|
||||||
/**
|
export function PostSegment(props: { post: Post }): JSXElement {
|
||||||
* PostSegment is used to display posts in both the main feed and the post view
|
const dateOfCreation = new Date(props.post.createdAt).toDateString();
|
||||||
*
|
const isEdited = !(props.post.createdAt == props.post.updatedAt);
|
||||||
* @param {Object} props The properties for the PostSegment component.
|
|
||||||
* @param {Post} props.post The post to display.
|
|
||||||
* @returns {JSXElement} A JSXElement of a post
|
|
||||||
*/
|
|
||||||
export function PostSegment({ post }: { post: Post }): JSXElement {
|
|
||||||
const dateOfCreation = new Date(post.createdAt).toDateString();
|
|
||||||
const isEdited = !(post.createdAt == post.updatedAt);
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div class="card compact w-full flex-grow border-b-2 border-b-primary bg-base-200 text-base-content transition-all hover:bg-base-300">
|
<div class="card compact w-full flex-grow border-b-2 border-b-primary bg-base-200 text-base-content transition-all hover:bg-base-300">
|
||||||
|
@ -25,12 +18,12 @@ export function PostSegment({ post }: { post: Post }): JSXElement {
|
||||||
<p class="text-xs">{dateOfCreation}</p>
|
<p class="text-xs">{dateOfCreation}</p>
|
||||||
<details class="dropdown">
|
<details class="dropdown">
|
||||||
<summary class="btn m-1">...</summary>
|
<summary class="btn m-1">...</summary>
|
||||||
<ul class="menu dropdown-content z-[1] w-26 rounded-box bg-base-100 p-2 shadow">
|
<ul class="w-26 menu dropdown-content z-[1] rounded-box bg-base-100 p-2 shadow">
|
||||||
<li>
|
<li>
|
||||||
<ReportButton />
|
<ReportButton />
|
||||||
</li>
|
</li>
|
||||||
<li>
|
<li>
|
||||||
<RemovePostButton post={post}/>
|
<RemovePostButton post={props.post} />
|
||||||
</li>
|
</li>
|
||||||
</ul>
|
</ul>
|
||||||
</details>
|
</details>
|
||||||
|
@ -38,13 +31,13 @@ export function PostSegment({ post }: { post: Post }): JSXElement {
|
||||||
<Show when={isEdited}>
|
<Show when={isEdited}>
|
||||||
<p>This post has been edited</p>
|
<p>This post has been edited</p>
|
||||||
</Show>
|
</Show>
|
||||||
<p class="my-5 text-base">{post.content}</p>
|
<p class="my-5 text-base">{props.post.content}</p>
|
||||||
<div class="card-actions justify-between">
|
<div class="card-actions justify-between">
|
||||||
<div class="flex">
|
<div class="flex">
|
||||||
<EngagementButton post={post} />
|
<EngagementButton post={props.post} />
|
||||||
<CommentsBUtton post={post} />
|
<CommentsBUtton post={props.post} />
|
||||||
</div>
|
</div>
|
||||||
<ToPostButton post={post} />
|
<ToPostButton post={props.post} />
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -91,9 +91,7 @@ export async function getComments(
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Incomplete */
|
/** Incomplete */
|
||||||
export async function engagePost(
|
export async function engagePost(postId: string): Promise<void> {
|
||||||
postId: string
|
|
||||||
): Promise<void> {
|
|
||||||
const res = await fetch(`/api/engage_post?post_id=${postId}`);
|
const res = await fetch(`/api/engage_post?post_id=${postId}`);
|
||||||
const data = await res.json();
|
const data = await res.json();
|
||||||
return data;
|
return data;
|
||||||
|
|
Loading…
Reference in a new issue