import { useLocation, useNavigate } from 'react-router-dom'; import { subscribe, useSnapshot } from 'valtio'; import Accounts from '../pages/accounts'; import Settings from '../pages/settings'; import focusDeck from '../utils/focus-deck'; import showToast from '../utils/show-toast'; import states from '../utils/states'; import AccountSheet from './account-sheet'; import Compose from './compose'; import Drafts from './drafts'; import GenericAccounts from './generic-accounts'; import MediaAltModal from './media-alt-modal'; import MediaModal from './media-modal'; import Modal from './modal'; import ShortcutsSettings from './shortcuts-settings'; subscribe(states, (changes) => { for (const [action, path, value, prevValue] of changes) { // When closing modal, focus on deck if (/^show/i.test(path) && !value) { focusDeck(); } } }); export default function Modals() { const snapStates = useSnapshot(states); const navigate = useNavigate(); const location = useLocation(); return ( <> {!!snapStates.showCompose && ( { const { newStatus, instance, type } = results || {}; states.showCompose = false; window.__COMPOSE__ = null; if (newStatus) { states.reloadStatusPage++; showToast({ text: { post: 'Post published. Check it out.', reply: 'Reply posted. Check it out.', edit: 'Post updated. Check it out.', }[type || 'post'], delay: 1000, duration: 10_000, // 10 seconds onClick: (toast) => { toast.hideToast(); states.prevLocation = location; navigate( instance ? `/${instance}/s/${newStatus.id}` : `/s/${newStatus.id}`, ); }, }); } }} /> )} {!!snapStates.showSettings && ( { states.showSettings = false; }} > { states.showSettings = false; }} /> )} {!!snapStates.showAccounts && ( { states.showAccounts = false; }} > { states.showAccounts = false; }} /> )} {!!snapStates.showAccount && ( { states.showAccount = false; }} > { states.showAccount = false; // states.showGenericAccounts = false; // if (destination) { // states.showAccounts = false; // } }} /> )} {!!snapStates.showDrafts && ( { states.showDrafts = false; }} > (states.showDrafts = false)} /> )} {!!snapStates.showMediaModal && ( { if ( e.target === e.currentTarget || e.target.classList.contains('media') ) { states.showMediaModal = false; } }} > { states.showMediaModal = false; }} /> )} {!!snapStates.showShortcutsSettings && ( { states.showShortcutsSettings = false; }} > (states.showShortcutsSettings = false)} /> )} {!!snapStates.showGenericAccounts && ( { states.showGenericAccounts = false; }} > (states.showGenericAccounts = false)} /> )} {!!snapStates.showMediaAlt && ( { states.showMediaAlt = false; }} > { states.showMediaAlt = false; }} /> )} ); }