Merge pull request #55 from docmost/fix/bug-fixes

Fix: missing tree, editor font and responsive recent pages
This commit is contained in:
Philip Okugbe
2024-07-05 00:45:32 +01:00
committed by GitHub
6 changed files with 53 additions and 48 deletions
@@ -1,4 +1,11 @@
import { Text, Group, UnstyledButton, Badge, Table } from "@mantine/core"; import {
Text,
Group,
UnstyledButton,
Badge,
Table,
ScrollArea,
} from "@mantine/core";
import { Link } from "react-router-dom"; import { Link } from "react-router-dom";
import PageListSkeleton from "@/components/ui/page-list-skeleton.tsx"; import PageListSkeleton from "@/components/ui/page-list-skeleton.tsx";
import { buildPageUrl } from "@/features/page/page.utils.ts"; import { buildPageUrl } from "@/features/page/page.utils.ts";
@@ -22,46 +29,48 @@ export default function RecentChanges({ spaceId }: Props) {
} }
return pages && pages.items.length > 0 ? ( return pages && pages.items.length > 0 ? (
<Table highlightOnHover verticalSpacing="sm"> <ScrollArea>
<Table.Tbody> <Table highlightOnHover verticalSpacing="sm">
{pages.items.map((page) => ( <Table.Tbody>
<Table.Tr key={page.id}> {pages.items.map((page) => (
<Table.Td> <Table.Tr key={page.id}>
<UnstyledButton
component={Link}
to={buildPageUrl(page?.space.slug, page.slugId, page.title)}
>
<Group wrap="nowrap">
{page.icon || <IconFileDescription size={18} />}
<Text fw={500} size="md" lineClamp={1}>
{page.title || "Untitled"}
</Text>
</Group>
</UnstyledButton>
</Table.Td>
{!spaceId && (
<Table.Td> <Table.Td>
<Badge <UnstyledButton
color="blue"
variant="light"
component={Link} component={Link}
to={getSpaceUrl(page?.space.slug)} to={buildPageUrl(page?.space.slug, page.slugId, page.title)}
style={{ cursor: "pointer" }}
> >
{page?.space.name} <Group wrap="nowrap">
</Badge> {page.icon || <IconFileDescription size={18} />}
<Text fw={500} size="md" lineClamp={1}>
{page.title || "Untitled"}
</Text>
</Group>
</UnstyledButton>
</Table.Td> </Table.Td>
)} {!spaceId && (
<Table.Td> <Table.Td>
<Text c="dimmed" size="xs" fw={500}> <Badge
{formattedDate(page.updatedAt)} color="blue"
</Text> variant="light"
</Table.Td> component={Link}
</Table.Tr> to={getSpaceUrl(page?.space.slug)}
))} style={{ cursor: "pointer" }}
</Table.Tbody> >
</Table> {page?.space.name}
</Badge>
</Table.Td>
)}
<Table.Td>
<Text c="dimmed" size="xs" fw={500}>
{formattedDate(page.updatedAt)}
</Text>
</Table.Td>
</Table.Tr>
))}
</Table.Tbody>
</Table>
</ScrollArea>
) : ( ) : (
<Text size="md" ta="center"> <Text size="md" ta="center">
No pages yet No pages yet
@@ -9,7 +9,7 @@
); );
font-size: var(--mantine-font-size-md); font-size: var(--mantine-font-size-md);
line-height: var(--mantine-line-height-xl); line-height: var(--mantine-line-height-xl);
font-weight: 415; font-weight: 400;
width: 100%; width: 100%;
> * + * { > * + * {
@@ -4,7 +4,7 @@
iframe { iframe {
display: block; display: block;
outline: 0px solid transparent; outline: 0 solid transparent;
border-radius: var(--mantine-radius-md); border-radius: var(--mantine-radius-md);
width: 100%; width: 100%;
} }
@@ -88,6 +88,7 @@ export default function SpaceTree({ spaceId, readOnly }: SpaceTreeProps) {
if (pagesData?.pages && !hasNextPage) { if (pagesData?.pages && !hasNextPage) {
const allItems = pagesData.pages.flatMap((page) => page.items); const allItems = pagesData.pages.flatMap((page) => page.items);
const treeData = buildTree(allItems); const treeData = buildTree(allItems);
if (data.length < 1 || data?.[0].spaceId !== spaceId) { if (data.length < 1 || data?.[0].spaceId !== spaceId) {
//Thoughts //Thoughts
// don't reset if there is data in state // don't reset if there is data in state
@@ -106,7 +107,7 @@ export default function SpaceTree({ spaceId, readOnly }: SpaceTreeProps) {
const fetchData = async () => { const fetchData = async () => {
if (isDataLoaded.current && currentPage) { if (isDataLoaded.current && currentPage) {
// check if pageId node is present in the tree // check if pageId node is present in the tree
const node = dfs(treeApiRef.current.root, currentPage.id); const node = dfs(treeApiRef.current?.root, currentPage.id);
if (node) { if (node) {
// if node is found, no need to traverse its ancestors // if node is found, no need to traverse its ancestors
return; return;
@@ -52,6 +52,8 @@ export function useTreeMutation<T>(spaceId: string) {
slugId: createdPage.slugId, slugId: createdPage.slugId,
name: "", name: "",
position: createdPage.position, position: createdPage.position,
spaceId: createdPage.spaceId,
parentPageId: createdPage.parentPageId,
children: [], children: [],
} as any; } as any;
@@ -1,17 +1,10 @@
import { Group, Center, Text } from "@mantine/core"; import { Group, Center, Text } from "@mantine/core";
import { Spotlight } from "@mantine/spotlight"; import { Spotlight } from "@mantine/spotlight";
import { import { IconFileDescription, IconSearch } from "@tabler/icons-react";
IconFileDescription,
IconHome,
IconSearch,
IconSettings,
} from "@tabler/icons-react";
import React, { useState } from "react"; import React, { useState } from "react";
import { useNavigate, useParams } from "react-router-dom"; import { useNavigate, useParams } from "react-router-dom";
import { useDebouncedValue } from "@mantine/hooks"; import { useDebouncedValue } from "@mantine/hooks";
import { usePageSearchQuery } from "@/features/search/queries/search-query"; import { usePageSearchQuery } from "@/features/search/queries/search-query";
import { useGetSpaceBySlugQuery } from "@/features/space/queries/space-query.ts";
import { useRecentChangesQuery } from "@/features/page/queries/page-query.ts";
import { buildPageUrl } from "@/features/page/page.utils.ts"; import { buildPageUrl } from "@/features/page/page.utils.ts";
interface SearchSpotlightProps { interface SearchSpotlightProps {