-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(#212): implemented user profile with grid
- Loading branch information
1 parent
530744a
commit b27dfe5
Showing
8 changed files
with
265 additions
and
0 deletions.
There are no files selected for viewing
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,77 @@ | ||
// "use client"; | ||
|
||
import prisma from "@/services/prisma"; | ||
import { Platform, PlatformCode, PlatformQuery } from "@prisma/client"; | ||
import { templates, samples } from "@/platforms"; | ||
import { RocksGridBuilder } from "@/components/widget/builder"; | ||
|
||
type IPlatformQueries = { | ||
platform: Platform & { queries: Array<PlatformQuery> }; | ||
}; | ||
|
||
const PlatformQueries = async ({ platform }: IPlatformQueries, key: string) => { | ||
const template = templates[platform.code]; | ||
const sample = samples[platform.code]; | ||
|
||
return Promise.all( | ||
platform.queries.map((query) => | ||
PlatformQueryView( | ||
{ | ||
query, | ||
template: template as any, | ||
sample: sample as any, | ||
}, | ||
query.id | ||
) | ||
) | ||
); | ||
}; | ||
|
||
type IPlatformQueryView = { | ||
query: PlatformQuery; | ||
template: { | ||
[key in keyof typeof PlatformCode]: ( | ||
...params: any | ||
) => Promise<JSX.Element>; | ||
}; | ||
sample: { [key in keyof typeof PlatformCode]: any }; | ||
}; | ||
|
||
const PlatformQueryView = async ( | ||
{ query, template, sample }: IPlatformQueryView, | ||
key: string | ||
) => { | ||
const getView = template[query.name as keyof typeof template]; | ||
const sampleData = sample[query.name as keyof typeof samples]; | ||
if (!sampleData) return <>No data.</>; | ||
|
||
return getView(sampleData.result, sampleData.config); | ||
}; | ||
|
||
type UserOwnProfileProps = { params: { uid: string } }; | ||
export default async function UserOwnProfile({ params }: UserOwnProfileProps) { | ||
const platforms = await prisma.platform.findMany({ | ||
include: { | ||
queries: { | ||
where: { publicQueryId: { isSet: false } }, | ||
}, | ||
}, | ||
}); | ||
|
||
const rocksWithView = ( | ||
await Promise.all( | ||
platforms.map((platform) => PlatformQueries({ platform }, platform.id)) | ||
) | ||
).flatMap((item) => item); | ||
|
||
return ( | ||
<div className="container mx-auto flex"> | ||
<div className="basis-1/4 w-16"> | ||
<p>User profile</p> | ||
</div> | ||
<div className="basis-3/4 w-32"> | ||
<RocksGridBuilder rocks={rocksWithView} /> | ||
</div> | ||
</div> | ||
); | ||
} |
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,29 @@ | ||
import { Profile } from "@/components/layout/profile"; | ||
import { RocksGridBuilder } from "@/components/widget/builder"; | ||
import prisma from "@/services/prisma"; | ||
|
||
type UserProfileProps = { | ||
params: { | ||
uid: string; | ||
}; | ||
}; | ||
|
||
export default async function UserProfile({ params }: UserProfileProps) { | ||
const userId = params.uid; | ||
|
||
const user = await prisma.user.findUnique({ | ||
where: { id: userId }, | ||
}); | ||
if (!user) return <p>User not found</p>; | ||
|
||
return ( | ||
<div className="container mx-auto py-24 flex divide-y-2"> | ||
<div className="w-1/6"> | ||
<Profile user={user} /> | ||
</div> | ||
<div className="w-5/2"> | ||
<RocksGridBuilder rocks={[]} /> | ||
</div> | ||
</div> | ||
); | ||
} |
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,23 @@ | ||
import { User } from "@prisma/client"; | ||
import NextImage from "next/image"; | ||
|
||
type ProfileType = { | ||
user: User; | ||
}; | ||
|
||
export const Profile = ({ user }: ProfileType) => { | ||
return ( | ||
<div className="flex flex-col justify-center items-center py-3"> | ||
{user.image && ( | ||
<NextImage | ||
className="rounded-full border-gray-300 border" | ||
alt={user.name || ""} | ||
src={user.image} | ||
width={200} | ||
height={200} | ||
/> | ||
)} | ||
<p className="text-3xl py-4">{user.name}</p> | ||
</div> | ||
); | ||
}; |
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,71 @@ | ||
"use client"; | ||
|
||
import { Responsive, WidthProvider } from "react-grid-layout"; | ||
import "react-grid-layout/css/styles.css"; | ||
import "react-resizable/css/styles.css"; | ||
import { useMemo } from "react"; | ||
import { FaPlus } from "react-icons/fa"; | ||
|
||
const ResponsiveGridLayout = WidthProvider(Responsive); | ||
|
||
type RocksGridBuilderProps = { | ||
rocks: Array<JSX.Element>; | ||
}; | ||
|
||
export function RocksGridBuilder({ rocks }: RocksGridBuilderProps) { | ||
// const layout: Array<Layout> = []; | ||
|
||
function onBreakpointChange(newBreakpoint: string, newCols: number) { | ||
console.log({ newBreakpoint, newCols }); | ||
} | ||
|
||
const addPlaceholder = useMemo( | ||
() => ( | ||
<div | ||
key={"grid_0"} | ||
data-grid={{ | ||
x: 0, | ||
y: 0, | ||
w: 1, | ||
h: 1, | ||
isResizable: false, | ||
}} | ||
> | ||
<div className="flex flex-col justify-center items-center text-center border-gray-300 border"> | ||
<FaPlus className="text-2xl" color="#555555" fontWeight="300" /> | ||
<p>Add a widget</p> | ||
</div> | ||
</div> | ||
), | ||
[] | ||
); | ||
|
||
return ( | ||
<ResponsiveGridLayout | ||
className="layout" | ||
breakpoints={{ lg: 1200, md: 996, sm: 768, xs: 480, xxs: 0 }} | ||
cols={{ lg: 12, md: 10, sm: 6, xs: 4, xxs: 2 }} | ||
onBreakpointChange={onBreakpointChange} | ||
rowHeight={30} | ||
autoSize={true} | ||
> | ||
{addPlaceholder} | ||
{rocks.map((rock, index) => { | ||
return ( | ||
<div | ||
key={index} | ||
data-grid={{ | ||
x: 0, | ||
y: 0, | ||
w: rock.props.width / 30 / 4, | ||
h: rock.props.height / 30, | ||
isResizable: false, | ||
}} | ||
> | ||
{rock} | ||
</div> | ||
); | ||
})} | ||
</ResponsiveGridLayout> | ||
); | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
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