import React from 'react' import { useAsyncCallback, useOnline, useKeyboardListener } 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 { useAuth } from './AuthContext' import { COLORS } from '../lib/constants' const popoutStyle = { width: '120px', right: -8, 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 ( {loading ? 'Duplicating…' : 'Duplicate'} ) } function SaveButton({ loading, onClick, sameUser }) { useKeyboardListener('⌥-s', e => { if (loading) { return } e.preventDefault() onClick() }) return ( {loading ? 'Saving…' : 'Save'} ) } function SnippetToolbar({ toggleVisibility, isVisible, snippet, ...props }) { const user = useAuth() const online = useOnline() const [save, { loading }] = useAsyncCallback(() => { if (snippet) { return props.onUpdate() } else { return props.onCreate() } }) if (!online) return null if (!user) return null const sameUser = snippet && user.uid === snippet.userId return ( props.onChange('name', e.target.value)} /> {snippet && !sameUser ? ( ) : ( )} {sameUser && ( )} ) } export default managePopout(SnippetToolbar)