Skip to content

How to use Notes

o5faruk edited this page May 2, 2021 · 3 revisions

⚠️⚠️⚠️

This sdk documentation is deprecated and will not be updated. Check out our new docs at https://sdk.buildfire.com/docs/notes/

⚠️⚠️⚠️

Notes

The NotesAPI allows users to create and manage notes for app content. Saved notes appear under the "notes" section of the side munu.

Usage

The BuildFire SDK provides the ability to add, delete, and fetch notes.

  • buildfire.notes.openDialog Opens the notes dialog where user can add notes.
  • buildfire.notes.onSeekTo A function that is called when navigating from notes to media content
  • buildfire.notes.getByItemId Checks if there is at least one note associated with itemId without opening notes dialog. Also returns total number of notes.

buildfire.notes.openDialog(options, callback)

Used for opening up notes dialog. Once opened, user can add new note or edit / remove previous notes.

Options

  • itemId {String|Number}: unique identifier
  • title {String}: title of the item the note will belong to, will be displayed on the notes page
  • imageUrl {String}: icon for the item the note will belong to, will be displayed on the notes page
  • timeIndex {Number}: optional, if adding notes to a video this allows the video to skip to the time when the user added the note. Expressed in seconds.

Callback

Callback returns 2 items, error and data.

Error

Error will indicate if there was any error while notes dialog is opened, otherwise it will return null

Data

  • itemId {String|Number}: unique identifier passed in options
  • hasNotes {Boolean}: indicates whether there is at least 1 note associated with itemId
  • noteCount {Number}: total number of notes associated with itemId

Example adding note to a video

const options = {
 itemId: 'MY_VIDEO_ID',
 title: 'Crazy cat jumping over the fence!',
 imageUrl: 'https://example.com/image.jpg',
 timeIndex: 22
};

const callback = (err, data) => {
    if (err) return console.error(err);

    const { hasNotes, noteCount, itemId } = data;

    if (hasNotes) {
        console.log(`Video with id ${itemId} has ${noteCount} notes!`)
    } else {
        console.log(`No notes yet!`)
    }
}

buildfire.notes.openDialog(options, callback)

Handling note opens

The app will navigate to the plugin to which the note belongs, and will pass note data through deeplinking.

This can be useful in cases where the plugin has internal navigation, which must be triggered when the note is opened. The following example shows how a plugin may use the payload to navigate to a specific YouTube video.

buildfire.deeplink.getData(data => {
 if (data && data.link) {
  // use link to navigate to item
 }
});

Consuming the timeIndex

If you have a video associated with an item, pass its current time to openDialog as timeIndex. If the item is later on opened through the notes dialog, BuildFire will trigger an event used to seek to the specified time.

An example of using onSeekTo with the YouTube API

buildfire.notes.onSeekTo(function (data) {
    window.player.seekTo(data.time);
});

One more example using different video player

buildfire.notes.onSeekTo(function (data) {
    NowPlaying.changeTime(data.time);
});

buildfire.notes.getByItemId(options, callback)

Useful if you want to get total number of notes or simply check if any note exists on given itemId without pulling up the notes dialog.

options

  • itemId {String|Number}: unique identifier

callback

  • itemId {String|Number}: unique identifier passed in options
  • hasNotes {Boolean}: indicates whether there is at least 1 note associated with itemId
  • noteCount {Number}: number of notes associated with itemId
const options = {
  itemId: 'MY_VIDEO_ID',
};

const callback = (err, data) => {
    if(err) return console.error(err);

    console.log(data)

    const { hasNotes, noteCount, itemId } = data;

    if (hasNotes) {
        console.log(`Video with id ${itemId} has ${noteCount} notes!`)
    } else {
        console.log(`Video with id ${itemId} does not have a single note yet!`)
    }
}

buildfire.notes.getByItemId(options, callback)

Editing and Deleting notes

The user manages their notes for an item through the notes dialog that is accessed through menu or opened programatically using openDialog. Once there, they can add, edit or remove notes.

Clone this wiki locally