Adding support for notebook icons

Hello,

I’m working on adding notebook icons to the Desktop version of Joplin.

I’m around 90% done and have two problems.

I’m trying to add a new column to the folders table in the database. I’ve seen the guide written in the comments in joplin-database.js

  1. Add the new version number to the existingDatabaseVersions array
  2. Add the upgrade logic to the “switch (targetVersion)” statement below

I added the 29 to the existingDatabaseVersions array and I added the following switch code

if (targetVersion == 29) {
			queries.push('ALTER TABLE folders ADD COLUMN `icon` TEXT NOT NULL DEFAULT ""');
}

Then I remove the current database and open ran the electron client.
However, when I do this, it resets the lib/joplin-database file. I’m guessing this has something to do with the build script.

The next problem I’m facing is Saving the icon.

I can successfully load the icon from the database. I added an icon column table manually to the folder table for testing purposes.

My code saves the title perfectly, but the icon isn’t getting saved. I tried to force an error by making the database busy, and I saw that the icon attribute isn’t even being loaded into the query (The title works fine).

This is the query that is logged when I force the Database is busy error.

UPDATE `folders` SET `title`=? WHERE `id`=?

I added functionality to add ‘fa-icon’ when a notebook is created.

folder = await Folder.save({ title: answer, icon: 'fa-book' }, { userSideValidation: true });

When I log the folder, I get

{title: "Maths", icon: "fa-book", id: "60be2a2a0cd44623a83821b36ffea247", updated_time: 1582915986458, created_time: 1582915986458, …}

But what happens is it instantly switches back to its previous state. Same with saving the icon. The icon gets shows for a moment, and then it disappears. I’m guessing this is because the item isn’t getting saved in the database. (Even though I get the response correctly)

Here is a screen capture of what happens.

Problem

The full code can be found here. https://github.com/rabeehrz/joplin/tree/issue-2268

If you could tell me how to do this properly, it would be great. Thank You.

Did you add 29 to the targetVersion array towards the top?

Yep.

The array is called existingDatabaseVersion. There is a comment there on how to add new databases. The problem is, whatever changes I make to the joplin-database file, it gets reset on build. I guess this has something to do with the build file.

I’ve updated the issue with one more problem. The icon doesn’t get saved in the database, but the loading works just file. Notebooks having icons are loaded from the database.

Issue Solved.

I had to upgrade the database in the ReactNative client rather than the Electron Client. Didn’t know it was synced. Went through the build script that gave me a clue. This also fixed the icon not save as well.

The problem with changing the code in ReactNative is that, depending on where it is in the code, it could alter how all platforms work if you decide to send a PR using your findings. Either way, glad you figured it out. :relaxed:

1 Like

Is it possible to use this? I started using Joplin right now and that was actually a thing i wanted to use, symbols on titles.

For now i’m having to use emojis, pasting it on the title.

Hi, is this coming to Android at some point? thanks