mirror of
https://github.com/barthuijgen/factorio-sites.git
synced 2025-02-03 14:01:50 +02:00
Added my favorites page
This commit is contained in:
parent
4083e49f75
commit
b6829c2657
@ -56,6 +56,7 @@ export const Header: React.FC = (props) => {
|
||||
>
|
||||
{auth ? (
|
||||
<>
|
||||
<MenuItem href="/user/favorites">My Favorites</MenuItem>
|
||||
<MenuItem href="/user/blueprints">My blueprints</MenuItem>
|
||||
<MenuItem href="/user/edit">Account</MenuItem>
|
||||
<MenuItem href="/about">About</MenuItem>
|
||||
|
49
apps/blueprints/src/pages/user/favorites.tsx
Normal file
49
apps/blueprints/src/pages/user/favorites.tsx
Normal file
@ -0,0 +1,49 @@
|
||||
import React from "react";
|
||||
import { NextPage } from "next";
|
||||
import { SimpleGrid, Box, Text } from "@chakra-ui/react";
|
||||
import { getUserFavoriteBlueprintPages } from "@factorio-sites/database";
|
||||
import { BlueprintPage } from "@factorio-sites/types";
|
||||
import { pageHandler } from "../../utils/page-handler";
|
||||
import { BlueprintLink } from "../../components/BlueprintLink";
|
||||
import { Panel } from "../../components/Panel";
|
||||
|
||||
interface UserBlueprintsProps {
|
||||
blueprints: BlueprintPage[];
|
||||
}
|
||||
|
||||
export const UserBlueprints: NextPage<UserBlueprintsProps> = ({ blueprints }) => {
|
||||
if (!blueprints) return null;
|
||||
|
||||
return (
|
||||
<SimpleGrid columns={1} margin="0 auto" maxWidth="800px">
|
||||
<Panel title="Blueprints">
|
||||
<Box
|
||||
css={{
|
||||
display: "flex",
|
||||
borderBottom: "1px solid #b7b7b7",
|
||||
paddingBottom: "0.3rem",
|
||||
}}
|
||||
>
|
||||
<Text>Your favorites</Text>
|
||||
</Box>
|
||||
<Box>
|
||||
{blueprints.length !== 0 ? (
|
||||
blueprints.map((bp) => <BlueprintLink key={bp.id} blueprint={bp} editLink type="row" />)
|
||||
) : (
|
||||
<p css={{ marginTop: "10px" }}>You don't have any favorites yet</p>
|
||||
)}
|
||||
</Box>
|
||||
</Panel>
|
||||
</SimpleGrid>
|
||||
);
|
||||
};
|
||||
|
||||
export const getServerSideProps = pageHandler(async (_, { session, redirect }) => {
|
||||
if (!session) return redirect("/");
|
||||
|
||||
const blueprints = await getUserFavoriteBlueprintPages(session.user.id);
|
||||
|
||||
return { props: { blueprints } };
|
||||
});
|
||||
|
||||
export default UserBlueprints;
|
@ -11,7 +11,7 @@ services:
|
||||
ports:
|
||||
- 5432:5432
|
||||
adminer:
|
||||
image: dpage/pgadmin4:4
|
||||
image: dpage/pgadmin4:5
|
||||
container_name: factorio-blueprints-database-admin
|
||||
restart: always
|
||||
volumes:
|
||||
|
@ -54,6 +54,19 @@ export async function getBlueprintPageByFactorioprintsId(
|
||||
return result ? mapBlueprintPageEntityToObject(result) : null;
|
||||
}
|
||||
|
||||
export async function getUserFavoriteBlueprintPages(user_id: string) {
|
||||
const result = await prisma.blueprint_page.findMany({
|
||||
where: {
|
||||
user_favorites: {
|
||||
some: {
|
||||
user_id: user_id,
|
||||
},
|
||||
},
|
||||
},
|
||||
});
|
||||
return result ? result.map((row) => mapBlueprintPageEntityToObject(row)) : [];
|
||||
}
|
||||
|
||||
export async function searchBlueprintPages({
|
||||
page = 1,
|
||||
perPage = 10,
|
||||
|
Loading…
x
Reference in New Issue
Block a user