Skip to content

How to use Bookmarks

o5faruk edited this page May 2, 2021 · 2 revisions

⚠️⚠️⚠️

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

⚠️⚠️⚠️

Bookmarks

The BookmarkAPI provides a simple way to allow users to save their favorite content for easy access. Saved bookmarks appear under the "bookmarks" section of the side munu.

Usage

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

  • buildfire.bookmarks.add
  • buildfire.bookmarks.delete
  • buildfire.bookmarks.getAll

Adding bookmarks

buildfire.bookmarks.add(options, callback)

Options

  • id {String|Number}: unique identifier
  • title {String}: title of the item being bookmarked, will be displayed on the bookmarks page
  • icon {String}: icon for the bookmarked item, will be displayed on the bookmarks page
  • payload {Object}: serializable object used to pass data back to the plugin consuming the bookmark
const options = {
 id: '1b64df4b-fed5-4af8-a7b2-84c57adf3a36',
 title: 'example bookmark',
 icon: 'https://example.com/image.jpg,
 payload: {
  data: { link: "https://yout.be/1fs9e50ds" }
 }
};

Consuming the payload and handling bookmark opens

The payload is a serializable object that can be used to pass data back to the plugin. The app will navigate to the plugin to which the bookmark belongs, and this data is passed along through deeplinking.

This can be useful in cases where the plugin has internal navigation, which must be triggered when the bookmark 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
 }
});

Deleting bookmarks

buildfire.bookmarks.delete(id, callback)

  • id {String|Number}: the unique identifier of the bookmark to delete
  • callback {Function}: called upon successful deletion
 buildfire.bookmarks.delete(item.guid, () => {
   // Update UI to indicate the item is no longer bookmarked
 });

Fetching bookmarks

buildfire.bookmarks.getAll(callback)

  • callback {Function}: returns an array of bookmarks from the plugin
buildfire.bookmarks.getAll(bookmarks => {
 console.log(bookmarks);
 /**
 * Returns an array of bookmark objects
 * [
 *   {
 *     pluginInstanceId: "9ab46295-b061-4fd1-b612-aca11b020b10-1573072609937"
 *     id: '1b64df4b-fed5-4af8-a7b2-84c57adf3a36',
 *     title: 'example bookmark',
 *     icon: 'https://example.com/image.jpg,
 *     payload: {
 *       data: { link: "https://yout.be/1fs9e50ds" }
 *     }
 *   }
 * ]
 */
});

Clone this wiki locally