import React, { useState } from "react"; import Container from "../../ui/atoms/container"; import { Button } from "../../ui/atoms/button"; import NewEditCollectionModal from "./new-edit-collection-modal"; import { Route, Routes } from "react-router"; import { Collection, useCollectionDelete, useCollections } from "./api"; import { Link } from "react-router-dom"; import { CollectionComponent, FrequentlyViewedCollectionComponent, } from "./collection"; import { DropdownMenuWrapper, DropdownMenu } from "../../ui/molecules/dropdown"; import MDNModal from "../../ui/atoms/modal"; import { Loading } from "../../ui/atoms/loading"; import NoteCard from "../../ui/molecules/notecards"; import "./index.scss"; import dayjs from "dayjs"; import relativeTime from "dayjs/plugin/relativeTime"; import Mandala from "../../ui/molecules/mandala"; import { useGleanClick } from "../../telemetry/glean-context"; import { PLUS_COLLECTIONS } from "../../telemetry/constants"; import { camelWrap } from "../../utils"; import { useFrequentlyViewed } from "./frequently-viewed"; import { Icon } from "../../ui/atoms/icon"; import { MDN_PLUS_TITLE } from "../../constants"; import { SWRConfig } from "swr"; dayjs.extend(relativeTime); const swrConfig = { revalidateOnFocus: false, revalidateIfStale: false }; export default function Collections() { return ( } /> } /> } /> ); } function Overview() { document.title = `Collections | ${MDN_PLUS_TITLE}`; const { data, isLoading, error } = useCollections(); const [showCreate, setShowCreate] = useState(false); const gleanClick = useGleanClick(); let collectionCards = data?.map((collection) => ( )); const frequentlyViewedCard = ( ); if (collectionCards && frequentlyViewedCard) { collectionCards.splice(1, 0, frequentlyViewedCard); } return (

Collections

Save and group your favorite MDN articles to easily find them later on.
We'd love to hear your feedback!

{isLoading ? ( ) : data ? ( collectionCards ) : error ? (

Error

{error.message}

) : ( "Create a new collection..." )}
); } function CollectionCard({ collection }: { collection: Collection }) { const [showDropdown, setShowDropdown] = useState(false); const [showEdit, setShowEdit] = useState(false); const [showDelete, setShowDelete] = useState(false); const { mutator: deleter, error, resetError, isPending, } = useCollectionDelete(); const deleteHandler = async (e: React.MouseEvent) => { e.preventDefault(); if (isPending) return; await deleter(collection); setShowDelete(false); }; const deleteCancelHandler = async (e: React.MouseEvent) => { e.preventDefault(); if (isPending) return; resetError(); setShowDelete(false); }; return collection.name === "Default" ? ( ) : (

{camelWrap(collection.name)}

{collection.name !== "Default" ? (
  • ) : null}

    Delete collection

    {error && (

    Error: {error.message}

    )}

    Are you sure you want to delete your collection "{collection.name} "?

    {collection.description &&

    {camelWrap(collection.description)}

    }
    {collection.article_count}{" "} {collection.article_count === 1 ? "article" : "articles"}
    ); } function DefaultCollectionCard({ collection }: { collection: Collection }) { return (

    Saved Articles

    The default collection.

    {collection.article_count}{" "} {collection.article_count === 1 ? "article" : "articles"}
    ); } function FrequentlyViewedCollectionCard() { const collection = useFrequentlyViewed(); if (!collection.items.length) { return null; } return (

    {collection.name}

    {collection.description}

    ); }