-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* rearrange navigation * properly style * comm form * create community * load community * approve community * list members * post to community, load post * progress * looking good * validation * collate nocase
- Loading branch information
Showing
50 changed files
with
1,305 additions
and
285 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,109 @@ | ||
import { useFetcher, useLoaderData, useParams } from "@remix-run/react"; | ||
import dayjs from "dayjs"; | ||
import { useGlobalCtx } from "~/lib/global-ctx"; | ||
import { loader } from "~/routes/communities_.$slug"; | ||
import { Anchor } from "./anchor"; | ||
import { Avatar } from "./avatar"; | ||
import { Button } from "./button"; | ||
|
||
function CommunityInfo() { | ||
const { user } = useGlobalCtx(); | ||
const { community, membership, members } = useLoaderData<typeof loader>(); | ||
const { slug } = useParams(); | ||
const fetcher = useFetcher(); | ||
|
||
async function join() { | ||
fetcher.submit("", { | ||
action: `/communities/${slug}/members`, | ||
method: "POST", | ||
}); | ||
} | ||
|
||
return ( | ||
<> | ||
<h1 className="font-bold text-lg leading-none">{community.name}</h1> | ||
<div className="bg-rose-100 dark:bg-rose-900 dark:bg-opacity-20 rounded-lg inline-block text-rose-500 font-medium px-1 text-sm"> | ||
+{community.handle} | ||
</div> | ||
|
||
{/* <div className="rounded-lg aspect-[5/2] bg-zinc-100 dark:bg-neutral-800 mt-2" /> */} | ||
|
||
<p className="">{community.description}</p> | ||
|
||
{!membership && ( | ||
<div className="border dark:border-neutral-800 rounded-lg p-2 mt-2"> | ||
<header className="font-mono text-xs text-secondary"> | ||
Join to interact | ||
</header> | ||
<p className="text-sm"> | ||
To be able to start and participate in conversations in this | ||
community, you need to join first. | ||
</p> | ||
|
||
<div className="mt-2"> | ||
{!user ? ( | ||
<Anchor to="/login">Login & join</Anchor> | ||
) : ( | ||
<Button | ||
variant="secondary" | ||
disabled={fetcher.state === "submitting"} | ||
onClick={join} | ||
> | ||
{fetcher.state === "submitting" ? ( | ||
<>Joining</> | ||
) : ( | ||
<>Join community</> | ||
)} | ||
</Button> | ||
)} | ||
</div> | ||
</div> | ||
)} | ||
|
||
{user && membership && ( | ||
<div className="flex gap-2"> | ||
<div className="text-xs text-secondary"> | ||
Member since {dayjs(membership.createdAt).format("DD MMM YYYY")} | ||
</div> | ||
{/** [ ] Add "leave community" */} | ||
</div> | ||
)} | ||
|
||
{/* <div className="border rounded-lg p-2 mt-2"> | ||
<header className="font-mono text-xs text-secondary"> | ||
Upcoming event | ||
</header> | ||
<p className="text-sm">Lecture 7: Developing a pixel art editor</p> | ||
<p className="text-secondary text-sm font-medium">Sat, 17 Apr.</p> | ||
</div> */} | ||
|
||
<div className="max-lg:hidden"> | ||
<div className="flex gap-2 items-center mt-2 font-medium text-secondary text-sm"> | ||
<div className="i-lucide-users-2 inline-block" /> | ||
{community.members} members | ||
</div> | ||
|
||
<ul> | ||
{members.map((member) => ( | ||
<li key={member.userId}> | ||
<div className="flex gap-2 py-1 px-2 rounded-lg hover:bg-zinc-100 items-center hover-bg-light"> | ||
<Avatar size={22} name={member.user.username} /> | ||
|
||
<div> | ||
{member.user.username}{" "} | ||
{member.role === "moderator" && ( | ||
<span className="bg-zinc-200 dark:bg-neutral-800 rounded-full px-2 text-sm text-secondary font-medium"> | ||
MOD | ||
</span> | ||
)} | ||
</div> | ||
</div> | ||
</li> | ||
))} | ||
</ul> | ||
</div> | ||
</> | ||
); | ||
} | ||
|
||
export { CommunityInfo }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
import { Community } from "@prisma/client"; | ||
import { useFetcher } from "@remix-run/react"; | ||
import { Jsonify } from "type-fest"; | ||
import { useGlobalCtx } from "~/lib/global-ctx"; | ||
import { Button } from "./button"; | ||
|
||
interface Props { | ||
community: Community | Jsonify<Community>; | ||
} | ||
|
||
function CommunityMod({ community }: Props) { | ||
const { user } = useGlobalCtx(); | ||
const fetcher = useFetcher(); | ||
|
||
const actions: { title: string; id: string }[] = []; | ||
|
||
if (community.status === "pending-approval") { | ||
actions.push({ title: "Approve", id: "approve" }); | ||
} | ||
|
||
function handleAction(action: string) { | ||
switch (action) { | ||
case "approve": { | ||
fetcher.submit(JSON.stringify({ action }), { | ||
encType: "application/json", | ||
method: "POST", | ||
action: `/communities/${community.handle}/mod`, | ||
}); | ||
} | ||
} | ||
} | ||
|
||
if (actions.length === 0) { | ||
return null; | ||
} | ||
|
||
if (user?.role !== "moderator") return null; | ||
|
||
return ( | ||
<div className="mb-2 p-1 bg-red-50 border border-red-200 rounded-lg"> | ||
<header className="font-mono text-xs text-red-500">community mod</header> | ||
|
||
<div className="flex"> | ||
{actions.map((action) => ( | ||
<Button | ||
className="text-sm p-1" | ||
variant="neutral" | ||
key={action.id} | ||
onClick={() => handleAction(action.id)} | ||
disabled={fetcher.state === "submitting"} | ||
> | ||
{action.title} | ||
</Button> | ||
))} | ||
</div> | ||
</div> | ||
); | ||
} | ||
|
||
export { CommunityMod }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.