2023-09-13 11:38:55 +03:00
|
|
|
import { useLocation, useNavigate } from 'react-router-dom';
|
2023-09-12 06:27:54 +03:00
|
|
|
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 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);
|
2023-09-13 11:38:55 +03:00
|
|
|
const navigate = useNavigate();
|
|
|
|
const location = useLocation();
|
|
|
|
|
2023-09-12 06:27:54 +03:00
|
|
|
return (
|
|
|
|
<>
|
|
|
|
{!!snapStates.showCompose && (
|
|
|
|
<Modal>
|
|
|
|
<Compose
|
|
|
|
replyToStatus={
|
|
|
|
typeof snapStates.showCompose !== 'boolean'
|
|
|
|
? snapStates.showCompose.replyToStatus
|
|
|
|
: window.__COMPOSE__?.replyToStatus || null
|
|
|
|
}
|
|
|
|
editStatus={
|
|
|
|
states.showCompose?.editStatus ||
|
|
|
|
window.__COMPOSE__?.editStatus ||
|
|
|
|
null
|
|
|
|
}
|
|
|
|
draftStatus={
|
|
|
|
states.showCompose?.draftStatus ||
|
|
|
|
window.__COMPOSE__?.draftStatus ||
|
|
|
|
null
|
|
|
|
}
|
|
|
|
onClose={(results) => {
|
|
|
|
const { newStatus, instance } = results || {};
|
|
|
|
states.showCompose = false;
|
|
|
|
window.__COMPOSE__ = null;
|
|
|
|
if (newStatus) {
|
|
|
|
states.reloadStatusPage++;
|
|
|
|
showToast({
|
|
|
|
text: 'Post published. Check it out.',
|
|
|
|
delay: 1000,
|
|
|
|
duration: 10_000, // 10 seconds
|
|
|
|
onClick: (toast) => {
|
|
|
|
toast.hideToast();
|
|
|
|
states.prevLocation = location;
|
2023-09-13 11:38:55 +03:00
|
|
|
navigate(
|
|
|
|
instance
|
|
|
|
? `/${instance}/s/${newStatus.id}`
|
|
|
|
: `/s/${newStatus.id}`,
|
|
|
|
);
|
2023-09-12 06:27:54 +03:00
|
|
|
},
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}}
|
|
|
|
/>
|
|
|
|
</Modal>
|
|
|
|
)}
|
|
|
|
{!!snapStates.showSettings && (
|
|
|
|
<Modal
|
2023-09-14 15:39:23 +03:00
|
|
|
onClose={() => {
|
|
|
|
states.showSettings = false;
|
2023-09-12 06:27:54 +03:00
|
|
|
}}
|
|
|
|
>
|
|
|
|
<Settings
|
|
|
|
onClose={() => {
|
|
|
|
states.showSettings = false;
|
|
|
|
}}
|
|
|
|
/>
|
|
|
|
</Modal>
|
|
|
|
)}
|
|
|
|
{!!snapStates.showAccounts && (
|
|
|
|
<Modal
|
2023-09-14 15:39:23 +03:00
|
|
|
onClose={() => {
|
|
|
|
states.showAccounts = false;
|
2023-09-12 06:27:54 +03:00
|
|
|
}}
|
|
|
|
>
|
|
|
|
<Accounts
|
|
|
|
onClose={() => {
|
|
|
|
states.showAccounts = false;
|
|
|
|
}}
|
|
|
|
/>
|
|
|
|
</Modal>
|
|
|
|
)}
|
|
|
|
{!!snapStates.showAccount && (
|
|
|
|
<Modal
|
|
|
|
class="light"
|
2023-09-14 15:39:23 +03:00
|
|
|
onClose={() => {
|
|
|
|
states.showAccount = false;
|
2023-09-12 06:27:54 +03:00
|
|
|
}}
|
|
|
|
>
|
|
|
|
<AccountSheet
|
|
|
|
account={snapStates.showAccount?.account || snapStates.showAccount}
|
|
|
|
instance={snapStates.showAccount?.instance}
|
|
|
|
onClose={({ destination } = {}) => {
|
|
|
|
states.showAccount = false;
|
|
|
|
if (destination) {
|
|
|
|
states.showAccounts = false;
|
|
|
|
}
|
|
|
|
}}
|
|
|
|
/>
|
|
|
|
</Modal>
|
|
|
|
)}
|
|
|
|
{!!snapStates.showDrafts && (
|
|
|
|
<Modal
|
2023-09-14 15:39:23 +03:00
|
|
|
onClose={() => {
|
|
|
|
states.showDrafts = false;
|
2023-09-12 06:27:54 +03:00
|
|
|
}}
|
|
|
|
>
|
|
|
|
<Drafts onClose={() => (states.showDrafts = false)} />
|
|
|
|
</Modal>
|
|
|
|
)}
|
|
|
|
{!!snapStates.showMediaModal && (
|
|
|
|
<Modal
|
|
|
|
onClick={(e) => {
|
|
|
|
if (
|
|
|
|
e.target === e.currentTarget ||
|
|
|
|
e.target.classList.contains('media')
|
|
|
|
) {
|
|
|
|
states.showMediaModal = false;
|
|
|
|
}
|
|
|
|
}}
|
|
|
|
>
|
|
|
|
<MediaModal
|
|
|
|
mediaAttachments={snapStates.showMediaModal.mediaAttachments}
|
|
|
|
instance={snapStates.showMediaModal.instance}
|
|
|
|
index={snapStates.showMediaModal.index}
|
|
|
|
statusID={snapStates.showMediaModal.statusID}
|
|
|
|
onClose={() => {
|
|
|
|
states.showMediaModal = false;
|
|
|
|
}}
|
|
|
|
/>
|
|
|
|
</Modal>
|
|
|
|
)}
|
|
|
|
{!!snapStates.showShortcutsSettings && (
|
|
|
|
<Modal
|
|
|
|
class="light"
|
2023-09-14 15:39:23 +03:00
|
|
|
onClose={() => {
|
|
|
|
states.showShortcutsSettings = false;
|
2023-09-12 06:27:54 +03:00
|
|
|
}}
|
|
|
|
>
|
|
|
|
<ShortcutsSettings
|
|
|
|
onClose={() => (states.showShortcutsSettings = false)}
|
|
|
|
/>
|
|
|
|
</Modal>
|
|
|
|
)}
|
|
|
|
{!!snapStates.showGenericAccounts && (
|
|
|
|
<Modal
|
|
|
|
class="light"
|
2023-09-14 15:39:23 +03:00
|
|
|
onClose={() => {
|
|
|
|
states.showGenericAccounts = false;
|
2023-09-12 06:27:54 +03:00
|
|
|
}}
|
|
|
|
>
|
|
|
|
<GenericAccounts
|
|
|
|
onClose={() => (states.showGenericAccounts = false)}
|
|
|
|
/>
|
|
|
|
</Modal>
|
|
|
|
)}
|
|
|
|
</>
|
|
|
|
);
|
|
|
|
}
|