By now it should be clear that all functionality in BlueBase is added via plugins. So in order to add views to our To-Do app, we need to create our own plugin.
Step 1: Install components library
Start by adding the following dependency:
yarnadd@bluebase/components
This library provides typescript typings of components imported from the BlueBase context.
Step 2: Create a plugin icon
The first thing that we will do is to create a plugin icon component. Create the following files:
Time to create the plugin itself. Create the following file:
src/index.ts
import { createPlugin } from'@bluebase/core';import { ToDoAppIcon } from'./components/ToDoAppIcon';exportdefaultcreatePlugin({ key:'tasks', name:'Tasks', description:'A todo app made with BlueBase framework.', components: { ToDoAppIcon, }, icon: { component:'ToDoAppIcon', type:'component', }, indexRoute:'HomeScreen',});
In the above code, we use the createPlugin function from the the @bluebase/core library. This function takes attributes as input, and returns a BlueBase Plugin.
The key property servers as the plugin ID, as well as the slug in the plugin URL path. So in this case the path to access this plugin would be: http://localhost:19006/p/tasks.
The name and description properties are pretty self explanatory. The name property is rendered below the icon on the home screen.
The components property is a Map of key, value pair. Where key is a string, and value is a React component. This map is used by BlueBase to store these components in its context. These can be fetched dynamically at a later stage, and can be overwritten by plugins to change the plugin implementation. More on this here.
We save the ToDoAppIcon component in the example above.
The icon property defines the plugin icon that is rendered on the home page. In the icon.component sub-property tells which component to render.
We use 'ToDoAppIcon' value, which is the same as the key on the component object in Line 10. So, by doing this we are telling BlueBase to render a component by the key ToDoAppIcon .
Lastly, the indexRoute key tells BlueBase which screen to navigate to when the icon is pressed. We tell it to go to HomeScreen here. Since we would already be on the HomeScreen so pressing this button will not do anything.
Step 4: Use the plugin
Now we're all set to use our shiny new plugin Edit our plugin files to add our own plugin to the list.