mirror of
https://github.com/docmost/docmost.git
synced 2026-05-07 06:23:06 +08:00
1280f96f37
* feat: implement space and workspace icons - Create reusable AvatarUploader component supporting avatars, space icons, and workspace icons - Add Sharp package for server-side image resizing and optimization - Create reusable AvatarUploader component supporting avatars, space icons, and workspace icons - Support removing icons * add workspace logo support - add upload loader - add white background to transparent image - other fixes and enhancements * dark mode * fixes * cleanup
78 lines
2.2 KiB
TypeScript
78 lines
2.2 KiB
TypeScript
import { Text, SimpleGrid, Card, rem, Group, Button } from "@mantine/core";
|
|
import React from "react";
|
|
import {
|
|
prefetchSpace,
|
|
useGetSpacesQuery,
|
|
} from "@/features/space/queries/space-query.ts";
|
|
import { getSpaceUrl } from "@/lib/config.ts";
|
|
import { Link } from "react-router-dom";
|
|
import classes from "./space-grid.module.css";
|
|
import { formatMemberCount } from "@/lib";
|
|
import { useTranslation } from "react-i18next";
|
|
import { IconArrowRight } from "@tabler/icons-react";
|
|
import { CustomAvatar } from "@/components/ui/custom-avatar.tsx";
|
|
import { AvatarIconType } from "@/features/attachments/types/attachment.types.ts";
|
|
|
|
export default function SpaceGrid() {
|
|
const { t } = useTranslation();
|
|
const { data, isLoading } = useGetSpacesQuery({ page: 1, limit: 10 });
|
|
|
|
const cards = data?.items.slice(0, 9).map((space, index) => (
|
|
<Card
|
|
key={space.id}
|
|
p="xs"
|
|
radius="md"
|
|
component={Link}
|
|
to={getSpaceUrl(space.slug)}
|
|
onMouseEnter={() => prefetchSpace(space.slug, space.id)}
|
|
className={classes.card}
|
|
withBorder
|
|
>
|
|
<Card.Section className={classes.cardSection} h={40}></Card.Section>
|
|
<CustomAvatar
|
|
name={space.name}
|
|
avatarUrl={space.logo}
|
|
type={AvatarIconType.SPACE_ICON}
|
|
color="initials"
|
|
variant="filled"
|
|
size="md"
|
|
mt={rem(-20)}
|
|
/>
|
|
|
|
<Text fz="md" fw={500} mt="xs" className={classes.title}>
|
|
{space.name}
|
|
</Text>
|
|
|
|
<Text c="dimmed" size="xs" fw={700} mt="md">
|
|
{formatMemberCount(space.memberCount, t)}
|
|
</Text>
|
|
</Card>
|
|
));
|
|
|
|
return (
|
|
<>
|
|
<Group justify="space-between" align="center" mb="md">
|
|
<Text fz="sm" fw={500}>
|
|
{t("Spaces you belong to")}
|
|
</Text>
|
|
</Group>
|
|
|
|
<SimpleGrid cols={{ base: 1, xs: 2, sm: 3 }}>{cards}</SimpleGrid>
|
|
|
|
{data?.items && data.items.length > 9 && (
|
|
<Group justify="flex-end" mt="lg">
|
|
<Button
|
|
component={Link}
|
|
to="/spaces"
|
|
variant="subtle"
|
|
rightSection={<IconArrowRight size={16} />}
|
|
size="sm"
|
|
>
|
|
{t("View all spaces")}
|
|
</Button>
|
|
</Group>
|
|
)}
|
|
</>
|
|
);
|
|
}
|