session state simplification

This commit is contained in:
2026-01-12 09:24:58 -05:00
parent ed16b277f7
commit f68f1f462a
32 changed files with 132 additions and 381 deletions

View File

@@ -7,14 +7,14 @@ const DeletePostButton = lazy(() => import("./DeletePostButton"));
export interface CardProps {
post: PostCardData;
privilegeLevel: "anonymous" | "admin" | "user";
isAdmin: boolean;
index?: number;
}
export default function Card(props: CardProps) {
return (
<div class="bg-base border-text relative z-0 mx-auto h-96 w-full overflow-hidden rounded-lg border shadow-lg lg:w-5/6 xl:w-3/4">
<Show when={props.privilegeLevel === "admin"}>
<Show when={props.isAdmin}>
<div class="border-opacity-20 bg-opacity-40 border-text bg-text absolute top-0 w-full border-b px-2 py-4 backdrop-blur-md md:px-6">
<div class="flex justify-between">
<Show when={!props.post.published}>
@@ -60,7 +60,7 @@ export default function Card(props: CardProps) {
</div>
<CardLinks
postTitle={props.post.title}
privilegeLevel={props.privilegeLevel}
isAdmin={props.isAdmin}
postID={props.post.id}
/>
</div>

View File

@@ -5,7 +5,7 @@ import { Spinner } from "~/components/Spinner";
export interface CardLinksProps {
postTitle: string;
postID: number;
privilegeLevel: string;
isAdmin: boolean;
}
export default function CardLinks(props: CardLinksProps) {
@@ -25,7 +25,7 @@ export default function CardLinks(props: CardLinksProps) {
<Spinner size={24} />
</Show>
</A>
<Show when={props.privilegeLevel === "admin"}>
<Show when={props.isAdmin}>
<A
href={`/blog/edit/${props.postID}`}
onClick={() => setEditLoading(true)}

View File

@@ -122,13 +122,10 @@ export default function CommentBlock(props: CommentBlockProps) {
);
const canDelete = () =>
props.currentUserID === props.comment.commenter_id ||
props.privilegeLevel === "admin";
props.currentUserID === props.comment.commenter_id || props.isAdmin;
const canEdit = () => props.currentUserID === props.comment.commenter_id;
const isAnonymous = () => props.privilegeLevel === "anonymous";
const replyIconColor = () => "var(--color-peach)";
return (
@@ -163,12 +160,12 @@ export default function CommentBlock(props: CommentBlockProps) {
hasUpvoted()
? "fill-green"
: `fill-text hover:fill-green ${
isAnonymous() ? "tooltip z-50" : ""
!props.isAuthenticated ? "tooltip z-50" : ""
}`
}`}
>
<ThumbsUpEmoji />
<Show when={isAnonymous()}>
<Show when={!props.isAuthenticated}>
<div class="tooltip-text -ml-16 w-32 text-white">
You must be logged in
</div>
@@ -190,14 +187,14 @@ export default function CommentBlock(props: CommentBlockProps) {
hasDownvoted()
? "fill-red"
: `fill-text hover:fill-red ${
isAnonymous() ? "tooltip z-50" : ""
!props.isAuthenticated ? "tooltip z-50" : ""
}`
}`}
>
<div class="rotate-180">
<ThumbsUpEmoji />
</div>
<Show when={isAnonymous()}>
<Show when={!props.isAuthenticated}>
<div class="tooltip-text -ml-16 w-32">
You must be logged in
</div>
@@ -309,7 +306,7 @@ export default function CommentBlock(props: CommentBlockProps) {
currentUserID={props.currentUserID}
reactions={reactions()}
showingReactionOptions={showingReactionOptions()}
privilegeLevel={props.privilegeLevel}
isAuthenticated={props.isAuthenticated}
commentReaction={props.commentReaction}
/>
</div>
@@ -325,7 +322,7 @@ export default function CommentBlock(props: CommentBlockProps) {
>
<CommentInputBlock
isReply={true}
privilegeLevel={props.privilegeLevel}
isAuthenticated={props.isAuthenticated}
parent_id={props.comment.id}
post_id={props.projectID}
currentUserID={props.currentUserID}
@@ -348,7 +345,8 @@ export default function CommentBlock(props: CommentBlockProps) {
child_comments={props.allComments?.filter(
(comment) => comment.parent_comment_id === childComment.id
)}
privilegeLevel={props.privilegeLevel}
isAuthenticated={props.isAuthenticated}
isAdmin={props.isAdmin}
currentUserID={props.currentUserID}
reactionMap={props.reactionMap}
level={props.level + 1}

View File

@@ -84,13 +84,11 @@ export default function CommentDeletionPrompt(
onChange={handleNormalDeleteCheckbox}
/>
<div class="my-auto px-2 text-sm font-normal">
{props.privilegeLevel === "admin"
? "Confirm User Delete?"
: "Confirm Delete?"}
{props.isAdmin ? "Confirm User Delete?" : "Confirm Delete?"}
</div>
</div>
</div>
<Show when={props.privilegeLevel === "admin"}>
<Show when={props.isAdmin}>
<div class="flex w-full justify-center">
<div class="flex pt-4">
<input

View File

@@ -18,7 +18,7 @@ export default function CommentInputBlock(props: CommentInputBlockProps) {
}
};
if (props.privilegeLevel === "user" || props.privilegeLevel === "admin") {
if (props.isAuthenticated) {
return (
<div class="flex w-full justify-center select-none">
<div class="h-fit w-3/4">

View File

@@ -6,7 +6,6 @@ import type {
UserPublicData,
ReactionType,
ModificationType,
PrivilegeLevel,
SortingMode
} from "~/types/comment";
import CommentInputBlock from "./CommentInputBlock";
@@ -20,28 +19,6 @@ const COMMENT_SORTING_OPTIONS: { val: SortingMode }[] = [
{ val: "hot" }
];
interface CommentSectionProps {
privilegeLevel: PrivilegeLevel;
allComments: Comment[];
topLevelComments: Comment[];
postID: number;
reactionMap: Map<number, CommentReaction[]>;
currentUserID: string;
userCommentMap: Map<UserPublicData, number[]> | undefined;
newComment: (commentBody: string, parentCommentID?: number) => Promise<void>;
commentSubmitLoading: boolean;
toggleModification: (
commentID: number,
commenterID: string,
commentBody: string,
modificationType: ModificationType,
commenterImage?: string,
commenterEmail?: string,
commenterDisplayName?: string
) => void;
commentReaction: (reactionType: ReactionType, commentID: number) => void;
}
export default function CommentSection(props: CommentSectionProps) {
const [searchParams] = useSearchParams();
@@ -66,7 +43,7 @@ export default function CommentSection(props: CommentSectionProps) {
<div class="mb-1">
<CommentInputBlock
isReply={false}
privilegeLevel={props.privilegeLevel}
isAuthenticated={props.isAuthenticated}
post_id={props.postID}
socket={undefined}
currentUserID={props.currentUserID}
@@ -90,7 +67,8 @@ export default function CommentSection(props: CommentSectionProps) {
<div id="comments">
<CommentSorting
topLevelComments={props.topLevelComments}
privilegeLevel={props.privilegeLevel}
isAuthenticated={props.isAuthenticated}
isAdmin={props.isAdmin}
postID={props.postID}
allComments={props.allComments}
reactionMap={props.reactionMap}

View File

@@ -855,7 +855,8 @@ export default function CommentSectionWrapper(
</Show>
<CommentSection
privilegeLevel={props.privilegeLevel}
isAuthenticated={props.isAuthenticated}
isAdmin={props.isAdmin}
allComments={allComments()}
topLevelComments={topLevelComments()}
postID={props.id}
@@ -875,7 +876,7 @@ export default function CommentSectionWrapper(
commenterImage={commenterImageForModification()}
commenterEmail={commenterEmailForModification()}
commenterDisplayName={commenterDisplayNameForModification()}
privilegeLevel={props.privilegeLevel}
isAdmin={props.isAdmin}
commentDeletionLoading={commentDeletionLoading()}
deleteComment={deleteComment}
onClose={() => {

View File

@@ -51,7 +51,8 @@ export default function CommentSorting(props: CommentSortingProps) {
child_comments={props.allComments?.filter(
(comment) => comment.parent_comment_id === topLevelComment.id
)}
privilegeLevel={props.privilegeLevel}
isAuthenticated={props.isAuthenticated}
isAdmin={props.isAdmin}
currentUserID={props.currentUserID}
reactionMap={props.reactionMap}
level={0}

View File

@@ -10,7 +10,7 @@ export interface Tag {
export interface PostSortingProps {
posts: PostCardData[];
tags: Tag[];
privilegeLevel: "anonymous" | "admin" | "user";
isAdmin: boolean;
filters?: string;
sort?: string;
include?: string;
@@ -36,7 +36,7 @@ export default function PostSorting(props: PostSortingProps) {
const filteredPosts = createMemo(() => {
let filtered = props.posts;
if (props.privilegeLevel === "admin" && props.status) {
if (props.isAdmin && props.status) {
if (props.status === "published") {
filtered = filtered.filter((post) => post.published === 1);
} else if (props.status === "unpublished") {
@@ -141,11 +141,7 @@ export default function PostSorting(props: PostSortingProps) {
<For each={sortedPosts()}>
{(post, index) => (
<div class="my-4">
<Card
post={post}
privilegeLevel={props.privilegeLevel}
index={index()}
/>
<Card post={post} isAdmin={props.isAdmin} index={index()} />
</div>
)}
</For>

View File

@@ -10,7 +10,7 @@ export interface PostLike {
export interface SessionDependantLikeProps {
currentUserID: string | undefined | null;
privilegeLevel: "admin" | "user" | "anonymous";
isAuthenticated: boolean;
likes: PostLike[];
projectID: number;
}
@@ -61,7 +61,7 @@ export default function SessionDependantLike(props: SessionDependantLikeProps) {
return (
<Show
when={props.privilegeLevel !== "anonymous"}
when={props.isAuthenticated}
fallback={
<button class="tooltip flex flex-col">
<div class="mx-auto">