mirror of
https://github.com/docmost/docmost.git
synced 2026-05-07 22:53:08 +08:00
78b1c1a453
* add cursor pagination function * support custom order modifier * refactor returned object * feat(db): migrate paginated endpoints to cursor-based pagination * sync * support hasPrevPage boolean * feat(client): migrate pagination from offset to cursor-based * support beforeCursor/prevCursor * wrap search results in items array for API consistency
93 lines
3.2 KiB
TypeScript
93 lines
3.2 KiB
TypeScript
import { Group, Table, Text } from "@mantine/core";
|
|
import React, { useState } from "react";
|
|
import { useCursorPaginate } from "@/hooks/use-cursor-paginate";
|
|
import { useGetSpacesQuery } from "@/features/space/queries/space-query.ts";
|
|
import SpaceSettingsModal from "@/features/space/components/settings-modal.tsx";
|
|
import { useDisclosure } from "@mantine/hooks";
|
|
import { formatMemberCount } from "@/lib";
|
|
import { useTranslation } from "react-i18next";
|
|
import Paginate from "@/components/common/paginate.tsx";
|
|
import { CustomAvatar } from "@/components/ui/custom-avatar.tsx";
|
|
import { AvatarIconType } from "@/features/attachments/types/attachment.types.ts";
|
|
import { AutoTooltipText } from "@/components/ui/auto-tooltip-text.tsx";
|
|
|
|
export default function SpaceList() {
|
|
const { t } = useTranslation();
|
|
const { cursor, goNext, goPrev } = useCursorPaginate();
|
|
const { data, isLoading } = useGetSpacesQuery({ cursor });
|
|
const [opened, { open, close }] = useDisclosure(false);
|
|
const [selectedSpaceId, setSelectedSpaceId] = useState<string>(null);
|
|
|
|
const handleClick = (spaceId: string) => {
|
|
setSelectedSpaceId(spaceId);
|
|
open();
|
|
};
|
|
|
|
return (
|
|
<>
|
|
<Table.ScrollContainer minWidth={500}>
|
|
<Table highlightOnHover verticalSpacing="sm" layout="fixed">
|
|
<Table.Thead>
|
|
<Table.Tr>
|
|
<Table.Th>{t("Space")}</Table.Th>
|
|
<Table.Th>{t("Members")}</Table.Th>
|
|
</Table.Tr>
|
|
</Table.Thead>
|
|
|
|
<Table.Tbody>
|
|
{data?.items.map((space, index) => (
|
|
<Table.Tr
|
|
key={index}
|
|
style={{ cursor: "pointer" }}
|
|
onClick={() => handleClick(space.id)}
|
|
>
|
|
<Table.Td>
|
|
<Group gap="sm" wrap="nowrap">
|
|
<CustomAvatar
|
|
color="initials"
|
|
avatarUrl={space.logo}
|
|
type={AvatarIconType.SPACE_ICON}
|
|
variant="filled"
|
|
name={space.name}
|
|
/>
|
|
<div style={{ minWidth: 0, overflow: "hidden" }}>
|
|
<AutoTooltipText fz="sm" fw={500} lineClamp={1}>
|
|
{space.name}
|
|
</AutoTooltipText>
|
|
<Text fz="xs" c="dimmed" lineClamp={2}>
|
|
{space.description}
|
|
</Text>
|
|
</div>
|
|
</Group>
|
|
</Table.Td>
|
|
<Table.Td>
|
|
<Text size="sm" style={{ whiteSpace: "nowrap" }}>
|
|
{formatMemberCount(space.memberCount, t)}
|
|
</Text>
|
|
</Table.Td>
|
|
</Table.Tr>
|
|
))}
|
|
</Table.Tbody>
|
|
</Table>
|
|
</Table.ScrollContainer>
|
|
|
|
{data?.items.length > 0 && (
|
|
<Paginate
|
|
hasPrevPage={data?.meta?.hasPrevPage}
|
|
hasNextPage={data?.meta?.hasNextPage}
|
|
onNext={() => goNext(data?.meta?.nextCursor)}
|
|
onPrev={goPrev}
|
|
/>
|
|
)}
|
|
|
|
{selectedSpaceId && (
|
|
<SpaceSettingsModal
|
|
opened={opened}
|
|
onClose={close}
|
|
spaceId={selectedSpaceId}
|
|
/>
|
|
)}
|
|
</>
|
|
);
|
|
}
|