import { useSortable } from "@dnd-kit/sortable"; import { CSS } from "@dnd-kit/utilities"; import { subDays } from "date-fns"; import { m } from "framer-motion"; import { observer } from "mobx-react"; import { CloseIcon, DocumentIcon, ClockIcon } from "outline-icons"; import { useRef, useCallback, Suspense } from "react"; import { useTranslation } from "react-i18next"; import { Link } from "react-router-dom"; import styled, { useTheme } from "styled-components"; import Icon from "@shared/components/Icon"; import Squircle from "@shared/components/Squircle"; import { s, hover, ellipsis } from "@shared/styles"; import { IconType } from "@shared/types"; import { determineIconType } from "@shared/utils/icon"; import type Document from "~/models/Document"; import type Pin from "~/models/Pin"; import Flex from "~/components/Flex"; import NudeButton from "~/components/NudeButton"; import Time from "~/components/Time"; import useStores from "~/hooks/useStores"; import CollectionIcon from "./Icons/CollectionIcon"; import Text from "./Text"; import Tooltip from "./Tooltip"; import lazyWithRetry from "~/utils/lazyWithRetry"; const ReadingTime = lazyWithRetry(() => import("./ReadingTime")); type Props = { /** The pin record */ pin: Pin | undefined; /** The document related to the pin */ document: Document; /** Whether the user has permission to delete or reorder the pin */ canUpdatePin?: boolean; /** Whether this pin can be reordered by dragging */ isDraggable?: boolean; }; function DocumentCard(props: Props) { const { t } = useTranslation(); const { collections } = useStores(); const theme = useTheme(); const { document, pin, canUpdatePin, isDraggable } = props; const pinnedToHome = useRef(!pin?.collectionId).current; const collection = document.collectionId ? collections.get(document.collectionId) : undefined; const { attributes, listeners, setNodeRef, transform, transition, isDragging, } = useSortable({ id: props.document.id, disabled: !isDraggable || !canUpdatePin, }); const hasEmojiInTitle = determineIconType(document.icon) === IconType.Emoji; const style = { transform: CSS.Transform.toString(transform), transition, }; const handleUnpin = useCallback( async (ev) => { ev.preventDefault(); ev.stopPropagation(); await pin?.delete(); }, [pin] ); // If the document was updated within the last 7 days, show a timestamp instead of reading time const isRecentlyUpdated = new Date(document.updatedAt) > subDays(new Date(), 7); const updatedAt = ( <>