Skip to content

Commit

Permalink
fix home layout
Browse files Browse the repository at this point in the history
  • Loading branch information
younes200 committed Oct 17, 2023
1 parent 7fed014 commit 908b98c
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 30 deletions.
48 changes: 19 additions & 29 deletions apps/frontend/src/components/home/ProjectGrid.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,22 +12,19 @@ import {
Typography,
} from "@mui/material";
import Grid from "@mui/material/Grid";
import { useQueryClient } from "@tanstack/react-query";
import { debounce } from "lodash";
import * as R from "ramda";
import * as React from "react";
import { useMemo, useRef, useState } from "react";
import { useTranslation } from "react-i18next";
import { TransitionGroup } from "react-transition-group";
import { useDidUpdate } from "rooks";

import { StyledTitle } from "~components/typography";
import { trpc } from "~utils/trpc";

import ProjectThumbnail from "./ProjectThumbnail";

export const ProjectGrid: React.FC = () => {
const queryClient = useQueryClient();
const searchInputRef = useRef<HTMLInputElement>(null);
const [searchTerm, setSearchTerm] = useState<string | undefined>(undefined);

Expand All @@ -41,16 +38,12 @@ export const ProjectGrid: React.FC = () => {
}, 1000);

const { data: user } = trpc.user.me.useQuery();
const [data] = trpc.project.list.useSuspenseQuery({
const [data, mutation] = trpc.project.list.useSuspenseQuery({
term: searchTerm,
});

const { t } = useTranslation();

useDidUpdate(() => {
queryClient.invalidateQueries(["projects"]);
}, [user]);

const userProjects = useMemo(
() => data.items.filter((project) => user && project.userId == user.id),
[user, data]
Expand Down Expand Up @@ -90,10 +83,13 @@ export const ProjectGrid: React.FC = () => {
height: 50,
}}
>
<IconButton sx={{ p: "10px", ml: 1 }} aria-label="menu">
<SearchIcon />
</IconButton>
{/* <CircularProgress sx={{ p: "10px", ml: 1 }} /> */}
{mutation.isFetching ? (
<CircularProgress sx={{ p: "10px", ml: 1 }} />
) : (
<IconButton sx={{ p: "10px", ml: 1 }} aria-label="menu">
<SearchIcon />
</IconButton>
)}
<Divider sx={{ height: 28, m: 0.5 }} orientation="vertical" />
<InputBase
sx={{ ml: 1, flex: 1 }}
Expand Down Expand Up @@ -122,17 +118,15 @@ export const ProjectGrid: React.FC = () => {
</Fade>
<Grid container={true} spacing={5} direction="row">
<TransitionGroup component={null} appear={true}>
{[...userProjects, ...userProjects, ...userProjects].map(
(project) => (
<Grid xs={12} sm={6} lg={4} xl={3} item>
<ProjectThumbnail
showPublic={true}
project={project}
key={project.id}
/>
</Grid>
)
)}
{userProjects.map((project) => (
<Grid xs={12} sm={6} lg={4} xl={3} item>
<ProjectThumbnail
showPublic={true}
project={project}
key={project.id}
/>
</Grid>
))}
</TransitionGroup>
</Grid>
</>
Expand All @@ -150,11 +144,7 @@ export const ProjectGrid: React.FC = () => {
</Fade>
<Grid container={true} spacing={5} direction="row">
<TransitionGroup component={null} appear={true}>
{[
...publicProjects,
...publicProjects,
...publicProjects,
].map((project) => (
{publicProjects.map((project) => (
<Grid xs={12} sm={6} lg={4} xl={3} item>
<ProjectThumbnail
showPublic={false}
Expand All @@ -171,7 +161,7 @@ export const ProjectGrid: React.FC = () => {
{noProjects && (
<Fade in={noProjects} appear={true}>
<Typography
variant="h3"
variant="h6"
align="center"
gutterBottom={true}
sx={{
Expand Down
2 changes: 1 addition & 1 deletion apps/frontend/src/pages/home.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ export const HomePage: React.FC = () => {
>
<Trans i18nKey="ERR_UNKOWN" />
<Button onClick={() => resetErrorBoundary()}>
Try again
<Trans i18nKey={"home.projects.retry"}>Réessayer</Trans>
</Button>
</Typography>
</Fade>
Expand Down

0 comments on commit 908b98c

Please sign in to comment.