import React, {useState} from "react" import {useDispatch, useSelector} from "react-redux" import styles from "./FeedsList.pcss" import {selectFeeds} from "spotlight/admin-common/stores/feeds/selectors" import {deleteFeed, duplicateFeed} from "spotlight/admin-common/stores/feeds/thunks" import {Dashicon} from "spotlight/common/components/Dashicon" import {Link} from "spotlight/admin-common/components/Link" import {Button, ButtonSize, ButtonType} from "spotlight/admin-common/components/Button" import Table, {TableStyleMap} from "spotlight/admin-common/components/Table/Table" import {SCREENS} from "spotlight/admin-common/stores/ScreensStore" import {MenuContent, MenuItem, MenuSeparator, StatefulMenu} from "spotlight/admin-common/components/Containers/Menu" import {Ellipsis} from "spotlight/admin-common/components/Ellipsis" import {CopyShortcode} from "spotlight/admin-common/components/Feeds/CopyShortcode" import WalletInfoModal from "spotlight/admin-common/components/WalletInfoModal" import {Responsive} from "spotlight/utils/responsive" import {Feed} from "spotlight/admin-common/stores/feeds" import {removeToast, showToast, ToastType} from "spotlight/admin-common/stores/toasts" import {gotoRoute} from "spotlight/admin-common/stores/router" import CopyToClipboard from "react-copy-to-clipboard" import {getErrorResponseMessage} from "spotlight/common/modules/rest-api/client" import {RestApi} from "spotlight/common/modules/rest-api" import {AdminRestApi} from "spotlight/admin-common/modules/rest-api" import {triggerError} from "spotlight/common/modules/errors/handlers" import {selectWalletList} from "spotlight/admin-common/stores/wallets/selectors" import {Wallet} from "spotlight/common/modules/wallets" export function FeedsList() { const dispatch = useDispatch() const feeds = useSelector(selectFeeds) const handleDelete = (feed) => { if (confirm("Are you sure you want to delete this gallery? This cannot be undone.")) { dispatch(deleteFeed(feed)) } } const handleUpdatePosts = async (feed) => { const response = await RestApi.tokens.import(feed.options) if (!response?.data?.batching) { dispatch(showToast({ key: "admin/feeds/import/done", message: `Finished importing NFTs for "${feed.name}".`, })) } } const editFeed = (feed: Feed) => { dispatch(gotoRoute({ screen: SCREENS.EDIT_FEED, id: feed.id.toString(), })) } const handleDuplicateFeed = (feed: Feed) => { dispatch(duplicateFeed(feed)) } const handleClearCache = async (feed) => { dispatch(showToast({ key: "admin/feeds/clear_cache/wait", message: `Clearing the cache for "${feed.name}". This could take a while. Please wait ...`, type: ToastType.STICKY, })) try { await AdminRestApi.cache.clearForFeed(feed) dispatch(showToast({ key: "admin/feeds/clear_cache/done", message: `Finished clearing the cache for "${feed.name}."`, })) } catch (error) { triggerError({ type: "feeds/clear_cache/error", message: getErrorResponseMessage(error), }) } finally { dispatch(removeToast("admin/feeds/clear_cache/wait")) } } function onExport() { dispatch(showToast({ key: "admin/feeds/export", message: "Copied export code to clipboard!", })) } const styleMap: TableStyleMap = { cols: { name: styles.nameCol, sources: styles.sourcesCol, usages: styles.usagesCol, actions: styles.actionsCol, }, cells: { name: styles.nameCell, sources: styles.sourcesCell, usages: styles.usagesCell, actions: styles.actionsCell, }, } return (
{ const editLink = {screen: SCREENS.EDIT_FEED, id: feed.id.toString()} return (
{feed.name ? feed.name : "(no name)"} {/*
ID: {feed.id} {Responsive.extract(feed.options.layout)?.toUpperCase() ?? "GRID"}
*/}
) }, }, { id: "sources", label: "Shows NFTs from", render: (feed) => , }, { id: "usages", label: "Instances", render: (feed) => , }, { id: "actions", label: "Actions", render: (feed) => (
{({ref, openMenu}) => ( )} editFeed(feed)}> Edit gallery handleDuplicateFeed(feed)}> Duplicate gallery Copy shortcode Export gallery handleUpdatePosts(feed)}> Update NFTs handleClearCache(feed)}> Clear cache handleDelete(feed)} danger> Delete gallery
), }, ]} /> ) } function getExportCode(feed: Feed) { return JSON.stringify({name: feed.name, options: feed.options}) } interface SourcesProps { feed: Feed; } function FeedSources({feed}: SourcesProps) { const wallets = useSelector(selectWalletList(feed.options.wallets)) // The info to show in the bottom row let info = [] // Add selected accounts to info wallets.forEach(wallet => { if (wallet) { info.push() } }) // If no sources were added to info, add a message if (info.length === 0) { info.push((
Gallery shows no NFTs
)) } return (
{info.map((elem, idx) => elem && {elem})}
) } interface UsagesProps { feed: Feed; } const FeedUsages = ({feed}: UsagesProps) => { return (
{feed.usages.map((usage, idx) => (
{usage.name} ({usage.type})
))}
) } interface FeedAccountProps { wallet: Wallet; onClick?: () => void; } function FeedWallet({wallet, onClick}: FeedAccountProps) { return (
{wallet.name}
) } const Source = ({children}) => (
{children}
)