This commit is contained in:
Philipinho
2024-05-19 09:06:06 +01:00
parent 9c7c2f1163
commit 6287f41ef6
6 changed files with 22 additions and 20 deletions

View File

@ -1,10 +1,10 @@
import { Text, Group, Stack, UnstyledButton, Divider } from "@mantine/core"; import { Text, Group, Stack, UnstyledButton, Divider } from "@mantine/core";
import { format } from "date-fns";
import classes from "./home.module.css"; import classes from "./home.module.css";
import { Link } from "react-router-dom"; import { Link } from "react-router-dom";
import PageListSkeleton from "@/features/home/components/page-list-skeleton"; import PageListSkeleton from "@/features/home/components/page-list-skeleton";
import { useRecentChangesQuery } from "@/features/page/queries/page-query"; import { useRecentChangesQuery } from "@/features/page/queries/page-query";
import { buildPageSlug } from "@/features/page/page.utils.ts"; import { buildPageSlug } from "@/features/page/page.utils.ts";
import { formattedDate } from "@/lib/time.ts";
function RecentChanges() { function RecentChanges() {
const { data, isLoading, isError } = useRecentChangesQuery(); const { data, isLoading, isError } = useRecentChangesQuery();
@ -35,7 +35,7 @@ function RecentChanges() {
</Stack> </Stack>
<Text c="dimmed" size="xs" fw={500}> <Text c="dimmed" size="xs" fw={500}>
{format(new Date(page.updatedAt), "PP")} {formattedDate(page.updatedAt)}
</Text> </Text>
</Group> </Group>
</UnstyledButton> </UnstyledButton>

View File

@ -1,6 +1,6 @@
import { Text, Group, UnstyledButton } from "@mantine/core"; import { Text, Group, UnstyledButton } from "@mantine/core";
import { UserAvatar } from "@/components/ui/user-avatar"; import { UserAvatar } from "@/components/ui/user-avatar";
import { formatDate } from "@/lib/time"; import { formattedDate } from "@/lib/time";
import classes from "./history.module.css"; import classes from "./history.module.css";
import clsx from "clsx"; import clsx from "clsx";
@ -19,7 +19,9 @@ function HistoryItem({ historyItem, onSelect, isActive }: HistoryItemProps) {
> >
<Group wrap="nowrap"> <Group wrap="nowrap">
<div> <div>
<Text size="sm">{formatDate(new Date(historyItem.createdAt))}</Text> <Text size="sm">
{formattedDate(new Date(historyItem.createdAt))}
</Text>
<div style={{ flex: 1 }}> <div style={{ flex: 1 }}>
<Group gap={4} wrap="nowrap"> <Group gap={4} wrap="nowrap">

View File

@ -1,16 +1,16 @@
import { formatDistanceStrict } from 'date-fns'; import { formatDistanceStrict } from "date-fns";
import { format, isToday, isYesterday } from 'date-fns'; import { format, isToday, isYesterday } from "date-fns";
export function timeAgo(date: Date) { export function timeAgo(date: Date) {
return formatDistanceStrict(new Date(date), new Date(), { addSuffix: true }); return formatDistanceStrict(new Date(date), new Date(), { addSuffix: true });
} }
export function formatDate(date: Date) { export function formattedDate(date: Date) {
if (isToday(date)) { if (isToday(date)) {
return `Today, ${format(date, 'h:mma')}`; return `Today, ${format(date, "h:mma")}`;
} else if (isYesterday(date)) { } else if (isYesterday(date)) {
return `Yesterday, ${format(date, 'h:mma')}`; return `Yesterday, ${format(date, "h:mma")}`;
} else { } else {
return format(date, 'MMM dd, yyyy, h:mma'); return format(date, "MMM dd, yyyy, h:mma");
} }
} }

View File

@ -10,7 +10,8 @@ export class CreateSpaceDto {
@IsString() @IsString()
description?: string; description?: string;
@IsOptional() @MinLength(4)
@MaxLength(64)
@IsString() @IsString()
slug?: string; slug: string;
} }

View File

@ -10,8 +10,6 @@ import { KyselyTransaction } from '@docmost/db/types/kysely.types';
import { Space } from '@docmost/db/types/entity.types'; import { Space } from '@docmost/db/types/entity.types';
import { PaginationResult } from '@docmost/db/pagination/pagination'; import { PaginationResult } from '@docmost/db/pagination/pagination';
import { UpdateSpaceDto } from '../dto/update-space.dto'; import { UpdateSpaceDto } from '../dto/update-space.dto';
// eslint-disable-next-line @typescript-eslint/no-var-requires
const { slugify } = require('fix-esm').require('@sindresorhus/slugify');
@Injectable() @Injectable()
export class SpaceService { export class SpaceService {
@ -23,14 +21,14 @@ export class SpaceService {
createSpaceDto: CreateSpaceDto, createSpaceDto: CreateSpaceDto,
trx?: KyselyTransaction, trx?: KyselyTransaction,
): Promise<Space> { ): Promise<Space> {
const slug = slugify( const slugExists = await this.spaceRepo.slugExists(
createSpaceDto?.slug?.toLowerCase() ?? createSpaceDto.name.toLowerCase(), createSpaceDto.slug,
workspaceId,
trx,
); );
const slugExists = await this.spaceRepo.slugExists(slug, workspaceId, trx);
if (slugExists) { if (slugExists) {
throw new BadRequestException( throw new BadRequestException(
'Slug exist. Please use a unique space slug', 'Slug exists. Please use a unique space slug',
); );
} }
@ -40,7 +38,7 @@ export class SpaceService {
description: createSpaceDto.description ?? '', description: createSpaceDto.description ?? '',
creatorId: userId, creatorId: userId,
workspaceId: workspaceId, workspaceId: workspaceId,
slug: slug, slug: createSpaceDto.slug,
}, },
trx, trx,
); );

View File

@ -104,6 +104,7 @@ export class WorkspaceService {
// create default space // create default space
const spaceInfo: CreateSpaceDto = { const spaceInfo: CreateSpaceDto = {
name: 'General', name: 'General',
slug: 'general',
}; };
const createdSpace = await this.spaceService.create( const createdSpace = await this.spaceService.create(