Skip to content

Commit a3d8a37

Browse files
committed
feat: fetch character via id
1 parent bf1074f commit a3d8a37

File tree

5 files changed

+58
-14
lines changed

5 files changed

+58
-14
lines changed
Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
1-
import React from 'react'
1+
import { fetchCharacterById } from '@/utils/api'
22

3-
export default function Page() {
4-
return (
5-
<div>Page</div>
6-
)
3+
export default async function Page({ params }: { params: { id: string } }) {
4+
const character = await fetchCharacterById(params.id)
5+
return <div>character page</div>
76
}

apps/web/src/components/Modals/DropZone.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,17 +13,17 @@ const maxFileSize = 10 * 1024 * 1024 // 10 MB
1313
export default function DropZone({
1414
setData,
1515
className = "",
16-
value = "",
16+
value = null,
1717
aspectRatio = "1"
1818
}: {
1919
setData: (url: string) => void
2020
className?: string
21-
value?: string
21+
value?: string | null
2222
aspectRatio?: string
2323
}) {
2424
const [isDragging, setIsDragging] = useState(false)
2525
const [file, setFile] = useState<File | null>(null)
26-
const [imageUrl, setImageUrl] = useState<string | null>(null)
26+
const [imageUrl, setImageUrl] = useState<string | null>(value)
2727
const [uploading, setUploading] = useState(false)
2828
const [error, setError] = useState<string | null>(null)
2929
const [_success, setSuccess] = useState(false)
@@ -122,7 +122,7 @@ export default function DropZone({
122122
{imageUrl ? (
123123
<div className="flex flex-col items-center">
124124
<Image width={200} height={200} alt="Uploaded" src={imageUrl} />
125-
<span className="text-lg font-bold">Uploaded!</span>
125+
{/* <span className="text-lg font-bold">Uploaded!</span> */}
126126
</div>
127127
) : uploading ? (
128128
<span className="text-lg font-bold">Uploading...</span>

apps/web/src/components/layouts/StudioLayout/Sidebar.tsx

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,22 @@ import { motion } from "framer-motion"
55
import { LuSettings } from "react-icons/lu"
66
import { useSidebarOpenAtom } from "./Sidebar.atom"
77
import SidebarItem from "./SidebarItem"
8-
import { generateSidebarItems } from "./SidebarItems"
8+
import { generateEditSidebarItems, generateSidebarItems } from "./SidebarItems"
99
import { useAuth, User } from "@/app/context/AuthContext"
10+
import { useRouter, usePathname } from "next/navigation"
1011
import Image from "next/image"
1112
import Avatar from "@/components/Avatar"
1213
import clsx from 'clsx'
1314

1415
export default function Sidebar({ user }: { user: User }) {
1516
const { sidebarState: isSidebarExpanded } = useSidebarOpenAtom()
16-
const sidebarItems = generateSidebarItems()
17+
const pathname = usePathname();
18+
const isEditingCharacter = pathname.includes('/studio/characters/');
19+
const characterId = isEditingCharacter
20+
? pathname.split("/studio/characters/")[1]?.split("/")[0]
21+
: null;
22+
const sidebarItems = characterId ? generateEditSidebarItems(characterId) : generateSidebarItems();
23+
1724
return (
1825
<>
1926
<motion.aside
@@ -42,12 +49,12 @@ export default function Sidebar({ user }: { user: User }) {
4249
</div>
4350
<div className="flex flex-col flex-1">
4451
{Object.entries(sidebarItems)
45-
.filter(([sectionKey]) => sectionKey !== "settings")
52+
.filter(([key]) => key !== "settings")
4653
.map(([sectionKey, items]) => (
4754
<div key={sectionKey} className="flex flex-col">
4855
{isSidebarExpanded && items.length > 0 && (
4956
<span className="m-3 text-sm text-subtext capitalize">
50-
{sectionKey}
57+
{sectionKey === "character" ? "Character Editor" : sectionKey}
5158
</span>
5259
)}
5360
{items.map((item) => (

apps/web/src/components/layouts/StudioLayout/SidebarItems.tsx

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { ReactNode } from "react"
2-
import { LuCat, LuFileQuestion, LuImage, LuKanbanSquare, LuLineChart, LuMessageCircle, LuPaintbrush, LuSettings, LuShield, LuShieldQuestion, LuZap } from "react-icons/lu"
2+
import { LuCat, LuFileQuestion, LuImage, LuKanbanSquare, LuLayers, LuLineChart, LuList, LuMessageCircle, LuPaintbrush, LuPencil, LuPencilLine, LuSettings, LuShield, LuShieldQuestion, LuZap } from "react-icons/lu"
33

44
type SidebarItem = {
55
icon: ReactNode
@@ -69,6 +69,27 @@ const generateArtistSidebarItems = (): SidebarItem[] => {
6969
]
7070
}
7171

72+
const generateCharacterEditSidebarItems = (uuid: string): SidebarItem[] => {
73+
return [
74+
{
75+
icon: <LuPencilLine size={20} />,
76+
label: "Basic Info",
77+
href: `#`
78+
},
79+
{
80+
icon: <LuList size={20} />,
81+
label: "Properties",
82+
href: `#properties`
83+
},
84+
{
85+
icon: <LuLayers size={20} />,
86+
label: "Ref Sheets",
87+
href: `#references`
88+
}
89+
]
90+
}
91+
92+
7293
const generateStaffSidebarItems = (): SidebarItem[] => {
7394
// TODO: Call backend to see if user is staff
7495
return [
@@ -104,3 +125,11 @@ export const generateSidebarItems = (): SidebarItemsByCategory => {
104125
settings: generateSettingsSidebarItems()
105126
}
106127
}
128+
129+
export const generateEditSidebarItems = (characterId: string) => {
130+
return {
131+
character: generateCharacterEditSidebarItems(characterId),
132+
settings: generateSettingsSidebarItems()
133+
}
134+
}
135+

apps/web/src/utils/api.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,15 @@ export const fetchCharacter = async (handle: string, characterName: string) => {
179179
return character
180180
}
181181

182+
export const fetchCharacterById = async (id: string) => {
183+
const character = await apiWithoutAuth<Character>(
184+
"GET",
185+
`/v1/character/id/${id}`
186+
)
187+
188+
return character
189+
}
190+
182191
export const fetchArtistRequests = async () => {
183192
const requests = await apiWithAuth<UserType[]>(
184193
"GET",

0 commit comments

Comments
 (0)