Skip to content

feat(web-ui): add skeleton to photos page #913

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jul 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions services/web-ui/public/locales/en/blog-photos.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"error": "Unable to fetch photos",
"no-photos": "No photos has been uploaded yet. Create a blog post to make that happen!"
}
4 changes: 4 additions & 0 deletions services/web-ui/public/locales/sv/blog-photos.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"error": "Kunde inte hämta foton",
"no-photos": "Inga foton har laddats upp här än. Skapa en bloggpost för att ladda upp foton."
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { ReactElement } from "react";
import { useTranslation } from "react-i18next";

import { Typography } from "@mui/material";
import { Box, Typography } from "@mui/material";

import { blogsApi } from "src/apis";
import { InteractionObserver } from "src/core/infinite-scroll";
Expand All @@ -14,6 +15,8 @@ import { BlogPhotoListPageSkeleton } from "./BlogPhotoListPage.skeleton";
const ITEMS_PER_PAGE = 10;

export function BlogPhotoListPageContainer(): ReactElement {
const { t } = useTranslation("blog-photos");

const { error, data, isPending, fetchNextPage, hasNextPage } =
useInfiniteQuery({
queryKey: [CacheKeysConstants.BlogPhotoList],
Expand All @@ -35,7 +38,7 @@ export function BlogPhotoListPageContainer(): ReactElement {
if (error) {
return (
<BlogPhotoListPageNav>
<ErrorView message="Unable to fetch photos" />
<ErrorView message={t("error")} />
</BlogPhotoListPageNav>
);
}
Expand All @@ -51,7 +54,9 @@ export function BlogPhotoListPageContainer(): ReactElement {
if (!data || data.pages[0].length === 0) {
return (
<BlogPhotoListPageNav>
<Typography>No photos to display</Typography>
<Box sx={{ p: 2 }}>
<Typography>{t("no-photos")}</Typography>
</Box>
</BlogPhotoListPageNav>
);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,38 @@
import { ReactElement } from "react";

import { Skeleton } from "@mui/material";
import { Box, Skeleton } from "@mui/material";

const getNumElement = (num: number) => {
const arr: number[] = [];

for (let x = 0; x < num; x++) {
arr.push(x);
}

return arr;
};

export function BlogPhotoListPageSkeleton(): ReactElement {
const photos = [3, 1, 4, 2];

return (
<>
<Skeleton />
{photos.map((photo, index) => (
<Box key={index} sx={{ pt: 3, px: 1 }}>
<Skeleton />

<Box sx={{ display: "flex", gap: 1, pt: 1 }}>
{getNumElement(photo).map((v) => (
<Skeleton
key={index + "" + v}
sx={{ height: 100, width: 100 }}
variant="rectangular"
/>
))}
<Skeleton variant="rectangular" />
</Box>
</Box>
))}
</>
);
}
Original file line number Diff line number Diff line change
@@ -1,21 +1,30 @@
import { ReactElement } from "react";

import { List, ListItem, Skeleton } from "@mui/material";
import {
List,
ListItem,
ListItemAvatar,
ListItemText,
Skeleton,
} from "@mui/material";

export function ChatListPageSkeleton(): ReactElement {
const items = [150, 75, 180, 140, 80, 90, 130, 210, 70];

return (
<List>
<ListItem divider>
<Skeleton height={50} width="100%" />
</ListItem>

<ListItem divider>
<Skeleton height={50} width="100%" />
</ListItem>
{items.map((item) => (
<ListItem key={item} disablePadding>
<ListItemAvatar>
<Skeleton sx={{ height: 38, width: 38 }} variant="circular" />
</ListItemAvatar>

<ListItem divider>
<Skeleton height={50} width="100%" />
</ListItem>
<ListItemText
primary={<Skeleton height={30} width={60} />}
secondary={<Skeleton height={25} width={item} />}
/>
</ListItem>
))}
</List>
);
}
Loading