diff --git a/components/Button.js b/components/Button.js index 1a6fd19..c5c3cec 100644 --- a/components/Button.js +++ b/components/Button.js @@ -8,6 +8,7 @@ const Button = ({ onClick = () => {}, background = COLORS.BLACK, color = COLORS.SECONDARY, + textColor, hoverBackground = COLORS.HOVER, hoverColor, disabled, @@ -33,7 +34,7 @@ const Button = ({ display: ${display || 'flex'}; flex: ${flex}; background-color: ${background}; - color: ${color}; + color: ${textColor || color}; box-shadow: ${border ? `inset 0px 0px 0px ${selected ? 2 : 1}px ${color}` : 'initial'}; cursor: ${disabled ? 'not-allowed' : 'pointer'}; outline: none; diff --git a/components/ConfirmButton.js b/components/ConfirmButton.js new file mode 100644 index 0000000..778d93b --- /dev/null +++ b/components/ConfirmButton.js @@ -0,0 +1,22 @@ +import React from 'react' +import Button from './Button' + +export default function ConfirmButton(props) { + const [confirmed, setConfirmed] = React.useState(false) + return ( + + ) +} diff --git a/components/SnippetToolbar.js b/components/SnippetToolbar.js index b0ed0d8..e6a11b5 100644 --- a/components/SnippetToolbar.js +++ b/components/SnippetToolbar.js @@ -3,31 +3,11 @@ import { useAsyncCallback, useOnline } from '@dawnlabs/tacklebox' import Button from './Button' import Toolbar from './Toolbar' +import ConfirmButton from './ConfirmButton' import { useAuth } from './AuthContext' import { COLORS } from '../lib/constants' -function ConfirmButton(props) { - const [confirmed, setConfirmed] = React.useState(false) - - return ( - - ) -} - function DeleteButton(props) { const [onClick, { loading }] = useAsyncCallback(props.onClick) diff --git a/pages/snippets.js b/pages/snippets.js index 5e2e308..cc69edc 100644 --- a/pages/snippets.js +++ b/pages/snippets.js @@ -7,6 +7,7 @@ import { useAsyncCallback } from '@dawnlabs/tacklebox' import Button from '../components/Button' import LoginButton from '../components/LoginButton' +import ConfirmButton from '../components/ConfirmButton' import { useAuth } from '../components/AuthContext' import { useAPI } from '../components/ApiContext' @@ -29,95 +30,122 @@ function Snippet(props) { const config = { ...DEFAULT_SETTINGS, ...props, fontSize: '2px', windowControls: false } return ( - - -
-
-
- - {props.code} - -
-
{props.title || props.id}
-
- Edited {formatDistanceToNow(correctTimestamp(props.updatedAt), { addSuffix: true })} -
-
+
+
+
+ + {props.code} +
- -
- +
{props.title || props.id}
+
+ Edited {formatDistanceToNow(correctTimestamp(props.updatedAt), { addSuffix: true })} +
+
+
+ + + + + Delete + +
+ +
) } @@ -127,9 +155,9 @@ function ActionButton(props) { border center margin="0.5rem" - flex="0 0 266px" + flex="unset" color={COLORS.GRAY} - style={{ minHeight: 266 }} + style={{ width: 266, minHeight: 266 }} {...props} /> ) @@ -164,6 +192,10 @@ function SnippetsPage() { } }, [loadMore, page, user]) + function deleteSnippet(id) { + return api.snippet.delete(id).then(() => setSnippets(curr => curr.filter(s => s.id !== id))) + } + if (!user) { return } @@ -171,7 +203,12 @@ function SnippetsPage() { return (
{snippets.map(snippet => ( - + ))} {snippets.length && previousRes && previousRes.length < 10 ? null : (