import React from 'react' import { useAsyncCallback, useOnline } from 'actionsack' import Button from './Button' import Toolbar from './Toolbar' import Input from './Input' import ConfirmButton from './ConfirmButton' import Popout, { managePopout } from './Popout' import { Down as ArrowDown } from './svg/Arrows' import { useAPI } from './ApiContext' import { useAuth } from './AuthContext' import { COLORS } from '../lib/constants' const popoutStyle = { width: '144px', right: 15, top: 40 } function DeleteButton(props) { const [onClick, { loading }] = useAsyncCallback(props.onClick) return ( {loading ? 'Deleting…' : 'Delete'} ) } function DuplicateButton(props) { const [onClick, { loading }] = useAsyncCallback(props.onClick) return ( ) } function SnippetToolbar({ toggleVisibility, isVisible, snippet, setSnippet, setToasts, state, ...props }) { const user = useAuth() const online = useOnline() const api = useAPI() const [update, { loading }] = useAsyncCallback(api.snippet.update) if (!online) return null if (!user) return null const sameUser = snippet && user.uid === snippet.userId // TODO move this to Editor function saveSnippet() { if (loading || !user) { return } if (!snippet) { update(undefined, state).then(newSnippet => { if (newSnippet && newSnippet.id) { setSnippet(newSnippet) setToasts({ type: 'ADD', toast: { children: 'Snippet saved!', closable: true }, }) } }) } else if (sameUser) { update(snippet.id, state).then(() => { setToasts({ type: 'ADD', toast: { children: 'Snippet saved!', closable: true }, }) }) } } return (
props.onChange('name', e.target.value)} />
) } export default managePopout(SnippetToolbar)