Develop with Writer

How to use Writer functionality in your plugin

Getting started

Writer plugin gives you methods to use in your plugin to open articles in Writer application if it's mounted in the same workspace with your plugin, or open an article with the Naviga writer in a new tab.

Writer register it's own methods with Dashboard Actions

You can use any of these actions in your plugin.

Available actions

ID

Descriptions

com.naviga.writer:openArticle

An action to handle open an article in Writer application with article uuid

com.naviga.writer:get:article

An action type promise, it will resolve with opened article {url, uuid}, and rejects if Writer application is not mounted

openArticle action

If your plugin is running beside Writer plugin in the same workspace openArticle action will open the requested article within Writer plugin by calling openArticle action with passing the article {uuid, url}

get:article action

If your plugin is running beside Writer plugin in the same workspace get:article action will return the opened article {uuid, url} by resolving a promise.

An example to how to open an article with Writer

In your plugin you can import useAction from Dashboard, so you can "import" Writer actions to your plugin.

import { useAction } from 'Dashboard'
import { useRef, useEffect } from 'react'

const MyAwesomeComponent = props => {
    const openArticle = useRef()
    
    useEffect(() => {
        const openArticleAction = useAction('com.naviga.writer:openArticle')
        openArticle.current = openArticleAction
    }, [])
    
    /**
        Now you can use openArticle all around your plugin.
        In order to open an article in Writer you can call
        openArticle.current() with the article uuid, url
        
        const article = {
            uuid: '838d42cf-507a-c701-f46d-6cd0a738cca4',
            url: 'https://writer.tryout.infomaker.io/838d42cf-507a-c701-f46d-6cd0a738cca4'
        }
        
        openArticle.current(article)
    */
}

Here we used com.naviga.writer:openArticle action to open the article with given uuid === '838d42cf-507a-c701-f46d-6cd0a738cca4'

If you called openArticle action while Writer plugin is not mounted, The requested article will open in a new tab with the Naviga Writer.

An example to how to get article from Writer

const getArticleAction = useAction('com.naviga.writer:get:article')
const getArticle = getArticleAction

const article = await getArticle()

console.log(article)
/**
    {
        uuid: '838d42cf-507a-c701-f46d-6cd0a738cca4',
        url: 'https://writer.tryout.infomaker.io/838d42cf-507a-c701-f46d-6cd0a738cca4'
    }
*/

If you called get:article action while Writer plugin is not mounted, get:article action will reject the promise

Last updated