How to use actionsack - 10 common examples

To help you get started, we’ve selected a few actionsack examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github carbon-app / carbon / components / EditorContainer.js View on Github external
function EditorContainer(props) {
  const [themes, updateThemes] = React.useState(THEMES)
  const api = useAPI()
  const user = useAuth()
  const [update, { loading }] = useAsyncCallback(api.snippet.update)

  React.useEffect(() => {
    const storedThemes = getThemes(localStorage) || []
    if (storedThemes) {
      updateThemes(currentThemes => [...storedThemes, ...currentThemes])
    }
  }, [])

  React.useEffect(() => {
    saveThemes(themes.filter(({ custom }) => custom))
  }, [themes])

  // XXX use context
  const [snippet, setSnippet] = React.useState(props.snippet || null)
  const [toasts, setToasts] = React.useReducer(toastsReducer, [])
github carbon-app / carbon / components / RandomImage.js View on Github external
function RandomImage(props) {
  const cacheRef = React.useRef([])
  const [cacheIndex, updateIndex] = React.useState(0)
  const api = useAPI()

  const [selectImage, { loading: selecting }] = useAsyncCallback(() => {
    const image = cacheRef.current[cacheIndex]

    return api.unsplash.download(image.id).then(data => props.onChange({ ...image, ...data }))
  })

  const [updateCache, { loading: updating, error, data: imgs }] = useAsyncCallback(
    api.unsplash.random
  )

  const needsFetch = !error && !updating && (!imgs || cacheIndex > cacheRef.current.length - 2)

  React.useEffect(() => {
    if (needsFetch) {
      updateCache()
    }
  }, [needsFetch, updateCache])

  React.useEffect(() => {
    if (imgs) {
      cacheRef.current.push(...imgs)
    }
  }, [imgs])
github carbon-app / carbon / components / Billing.js View on Github external
function Billing(props) {
  const user = useAuth()

  const [submit, { error, loading, data: success }] = useAsyncCallback(async e => {
    e.preventDefault()

    const name = e.target.name.value.trim()

    const res = await props.stripe.createToken({ name })

    if (res.error) {
      throw res.error.message
    }

    return {}
  })

  if (!user) {
    return (
      <div></div>
github carbon-app / carbon / components / SnippetToolbar.js View on Github external
function DeleteButton(props) {
  const [onClick, { loading }] = useAsyncCallback(props.onClick)

  return (
    
      {loading ? 'Deleting...' : 'Delete'}
    
  )
github carbon-app / carbon / components / ExportMenu.js View on Github external
function ExportMenu({
  backgroundImage,
  onChange,
  exportSize,
  isVisible,
  toggleVisibility,
  exportImage: exp
}) {
  const tooLarge = React.useMemo(() =&gt; !verifyPayloadSize(backgroundImage), [backgroundImage])
  const online = useOnline()
  const isSafari = useSafari()

  const [exportImage, { loading }] = useAsyncCallback(exp)
  useKeyboardListener('⌘-⇧-e', () =&gt; exportImage())

  const disablePNG = isSafari &amp;&amp; (tooLarge || !online)

  const input = React.useRef()

  const handleExportSizeChange = selectedSize =&gt; () =&gt; onChange('exportSize', selectedSize)

  const handleExport = format =&gt; () =&gt;
    exportImage(format, {
      filename: input.current.value
    })

  return (
    <div id="export-menu">
      <div></div></div>
github carbon-app / carbon / components / RandomImage.js View on Github external
function RandomImage(props) {
  const cacheRef = React.useRef([])
  const [cacheIndex, updateIndex] = React.useState(0)
  const api = useAPI()

  const [selectImage, { loading: selecting }] = useAsyncCallback(() => {
    const image = cacheRef.current[cacheIndex]

    return api.unsplash.download(image.id).then(data => props.onChange({ ...image, ...data }))
  })

  const [updateCache, { loading: updating, error, data: imgs }] = useAsyncCallback(
    api.unsplash.random
  )

  const needsFetch = !error && !updating && (!imgs || cacheIndex > cacheRef.current.length - 2)

  React.useEffect(() => {
    if (needsFetch) {
      updateCache()
    }
  }, [needsFetch, updateCache])
github carbon-app / carbon / pages / snippets.js View on Github external
function SnippetsPage() {
  const user = useAuth()
  const api = useAPI()

  const [snippets, setSnippets] = React.useState([])
  const [page, setPage] = React.useState(0)

  const mounted = useOnMount()

  const [loadMore, { loading, data: previousRes }] = useAsyncCallback(api.snippet.list)

  React.useEffect(() =&gt; {
    if (user) {
      loadMore(page).then(newSnippets =&gt; setSnippets(curr =&gt; curr.concat(newSnippets)))
    }
  }, [loadMore, page, user])

  function deleteSnippet(id) {
    return api.snippet.delete(id).then(() =&gt; setSnippets(curr =&gt; curr.filter(s =&gt; s.id !== id)))
  }

  if (!user) {
    return 
  }

  return (
github carbon-app / carbon / components / TweetButton.js View on Github external
function TweetButton(props) {
  const api = useAPI()
  const online = useOnlineListener()
  const [onClick, { loading }] = useAsyncCallback(props.onClick)

  if (!api || !api.tweet) {
    return null
  }

  if (!online) {
    return null
  }

  return (
github carbon-app / carbon / components / SnippetToolbar.js View on Github external
function DuplicateButton(props) {
  const [onClick, { loading }] = useAsyncCallback(props.onClick)

  return (
    <button color="#37b589" border="" display="block">
      {loading ? 'Duplicating...' : 'Duplicate'}
    </button>
  )
github carbon-app / carbon / components / Settings.js View on Github external
function KeyboardShortcut({ trigger, handle }) {
  useKeyboardListener(trigger, handle)
  return null
}

actionsack

React UX components for handling common interactions

MIT
Latest version published 3 years ago

Package Health Score

42 / 100
Full package analysis