Dashboard Writer
4.1.0
4.1.0
  • About
  • Changelog
  • User
    • How to
  • Admin
    • Config
      • Writer 7 and later
      • Copy articles
    • Requirements
    • Migration v3 to v4
  • Developer
    • Develop with Writer
      • Create
      • Open
      • Copy
      • Get article
      • Get instance
Powered by GitBook
On this page

Was this helpful?

  1. Developer
  2. Develop with Writer

Get instance

id

com.naviga.writer:getWriterInstance

description

An action returns the instance of Writer plugin with Writer methods

The instance object contains all the actions that's specified since before with the intention to get a single access point rather than retrieving multiple actions.

{
    article: {
        create: () => void { /* creates a new article */ },
        open: (uuid) => void { /* open article with passed uuid */ },
        copy: (uuid) => void { /* opens a modal to make a copy of chosen article */ },
        preview: (uuid) => void { /* opens a preview of chosen article */ }
    },
    config: {
        get: () => Promise { /* get current writer configuration */ }
    }
}

Preview also has a second optional parameter. This is a function supposed to handle custom images in the case where current configured ICP does not match the one where the images of the preview are supposed to be fetched from.

import { Plugin, Utility } from '@root'

const MyComponent = async (props) => {
    const instance = Utility.useLazyRef(() => {
        return Plugin.getAction('my-bound-action-id')
    })
    
    const articleUuid = '07a99d1a-3387-4cd6-bc64-c07f0062bb78'
    
    // create
    instance.current().article.create()
    
    // open
    instance.current().article.open(artilceUuid)
    
    // copy
    instance.current().article.copy(articleUuid)
    
    // preview
    instance.current().article.preview(articleUuid)
    
    // preview with optional image generator
    instance.current().article.preview(articleUuid, data => {
         const {
            uuid,
            uri
        } = data
        
        return {
            url: functionToGenerateImageUrl(uuid, uri)
        }
    })
    
    // get writer config
    const config = await instances.current().config.get()
}

PreviousGet article

Last updated 4 years ago

Was this helpful?