import { Divider } from "@mui/joy"; import classNames from "classnames"; import { useEffect, useState } from "react"; import toast from "react-hot-toast"; import { useParams } from "react-router-dom"; import Icon from "@/components/Icon"; import ShortcutFrame from "@/components/ShortcutFrame"; import ShortcutView from "@/components/ShortcutView"; import useResponsiveWidth from "@/hooks/useResponsiveWidth"; import useCollectionStore from "@/stores/v1/collection"; import useShortcutStore from "@/stores/v1/shortcut"; import useUserStore from "@/stores/v1/user"; import { Collection } from "@/types/proto/api/v2/collection_service"; import { Shortcut } from "@/types/proto/api/v2/shortcut_service"; import { convertShortcutFromPb } from "@/utils/shortcut"; const CollectionSpace = () => { const { collectionName } = useParams(); const { sm } = useResponsiveWidth(); const userStore = useUserStore(); const collectionStore = useCollectionStore(); const shortcutStore = useShortcutStore(); const [collection, setCollection] = useState(); const [shortcuts, setShortcuts] = useState([]); const [selectedShortcut, setSelectedShortcut] = useState(); if (!collectionName) { return null; } useEffect(() => { (async () => { try { const collection = await collectionStore.fetchCollectionByName(collectionName); await userStore.getOrFetchUserById(collection.creatorId); setCollection(collection); setShortcuts([]); for (const shortcutId of collection.shortcutIds) { try { const shortcut = await shortcutStore.getOrFetchShortcutById(shortcutId); setShortcuts((shortcuts) => { return [...shortcuts, shortcut]; }); } catch (error) { // Do nothing. } } document.title = `${collection.title} - Slash`; } catch (error: any) { console.error(error); toast.error(error.details); } })(); }, [collectionName]); if (!collection) { return null; } const creator = userStore.getUserById(collection.creatorId); const handleShortcutClick = (shortcut: Shortcut) => { if (sm) { setSelectedShortcut(shortcut); } else { window.open(`/s/${shortcut.name}`); } }; return (
{collection.title}

{collection.description}

{shortcuts.map((shortcut) => { return ( handleShortcutClick(shortcut)} /> ); })}
{sm && (
{selectedShortcut ? ( ) : (

Click on a tab in the Sidebar to get started.

Shared by {creator.nickname}

)}
)}
); }; export default CollectionSpace;