Skip to content

Commit

Permalink
Desktop: Display default notebook icons when at least one notebook ha…
Browse files Browse the repository at this point in the history
…s an icon
  • Loading branch information
laurent22 committed Sep 5, 2022
1 parent e37d980 commit 7974df9
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 7 deletions.
8 changes: 6 additions & 2 deletions packages/app-desktop/gui/FolderIconBox.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,19 @@ import { FolderIcon, FolderIconType } from '@joplin/lib/services/database/types'

interface Props {
folderIcon: FolderIcon;
opacity?: number;
}

export default function(props: Props) {
const folderIcon = props.folderIcon;
const opacity = 'opacity' in props ? props.opacity : 1;

if (folderIcon.type === FolderIconType.Emoji) {
return <span style={{ fontSize: 20 }}>{folderIcon.emoji}</span>;
return <span style={{ fontSize: 20, opacity }}>{folderIcon.emoji}</span>;
} else if (folderIcon.type === FolderIconType.DataUrl) {
return <img style={{ width: 20, height: 20 }} src={folderIcon.dataUrl} />;
return <img style={{ width: 20, height: 20, opacity }} src={folderIcon.dataUrl} />;
} else if (folderIcon.type === FolderIconType.FontAwesome) {
return <i style={{ fontSize: 18, width: 20, opacity }} className={folderIcon.name}></i>;
} else {
throw new Error(`Unsupported folder icon type: ${folderIcon.type}`);
}
Expand Down
27 changes: 22 additions & 5 deletions packages/app-desktop/gui/Sidebar/Sidebar.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import * as React from 'react';
import { useEffect, useRef, useCallback } from 'react';
import { useEffect, useRef, useCallback, useMemo } from 'react';
import { StyledRoot, StyledAddButton, StyledShareIcon, StyledHeader, StyledHeaderIcon, StyledAllNotesIcon, StyledHeaderLabel, StyledListItem, StyledListItemAnchor, StyledExpandLink, StyledNoteCount, StyledSyncReportText, StyledSyncReport, StyledSynchronizeButton } from './styles';
import { ButtonLevel } from '../Button/Button';
import CommandService from '@joplin/lib/services/CommandService';
Expand All @@ -18,7 +18,7 @@ import Folder from '@joplin/lib/models/Folder';
import Note from '@joplin/lib/models/Note';
import Tag from '@joplin/lib/models/Tag';
import Logger from '@joplin/lib/Logger';
import { FolderEntity, FolderIcon } from '@joplin/lib/services/database/types';
import { FolderEntity, FolderIcon, FolderIconType } from '@joplin/lib/services/database/types';
import stateToWhenClauseContext from '../../services/commands/stateToWhenClauseContext';
import { store } from '@joplin/lib/reducer';
import PerFolderSortOrderService from '../../services/sortOrder/PerFolderSortOrderService';
Expand Down Expand Up @@ -79,13 +79,21 @@ function ExpandLink(props: any) {
}

const renderFolderIcon = (folderIcon: FolderIcon) => {
if (!folderIcon) return null;
if (!folderIcon) {
const defaultFolderIcon: FolderIcon = {
dataUrl: '',
emoji: '',
name: 'far fa-folder',
type: FolderIconType.FontAwesome,
};
return <div style={{ marginRight: 5, display: 'flex' }}><FolderIconBox opacity={0.7} folderIcon={defaultFolderIcon}/></div>;
}

return <div style={{ marginRight: 5, display: 'flex' }}><FolderIconBox folderIcon={folderIcon}/></div>;
};

function FolderItem(props: any) {
const { hasChildren, isExpanded, parentId, depth, selected, folderId, folderTitle, folderIcon, anchorRef, noteCount, onFolderDragStart_, onFolderDragOver_, onFolderDrop_, itemContextMenu, folderItem_click, onFolderToggleClick_, shareId } = props;
const { hasChildren, showFolderIcon, isExpanded, parentId, depth, selected, folderId, folderTitle, folderIcon, anchorRef, noteCount, onFolderDragStart_, onFolderDragOver_, onFolderDrop_, itemContextMenu, folderItem_click, onFolderToggleClick_, shareId } = props;

const noteCountComp = noteCount ? <StyledNoteCount className="note-count-label">{noteCount}</StyledNoteCount> : null;

Expand All @@ -110,7 +118,7 @@ function FolderItem(props: any) {
}}
onDoubleClick={onFolderToggleClick_}
>
{renderFolderIcon(folderIcon)}<span className="title" style={{ lineHeight: 0 }}>{folderTitle}</span>
{showFolderIcon ? renderFolderIcon(folderIcon) : null}<span className="title" style={{ lineHeight: 0 }}>{folderTitle}</span>
{shareIcon} {noteCountComp}
</StyledListItemAnchor>
</StyledListItem>
Expand Down Expand Up @@ -139,6 +147,14 @@ const SidebarComponent = (props: Props) => {
const pluginsRef = useRef<PluginStates>(null);
pluginsRef.current = props.plugins;

// If at least one of the folder has an icon, then we display icons for all
// folders (those without one will get the default icon). This is so that
// visual alignment is correct for all folders, otherwise the folder tree
// looks messy.
const showFolderIcons = useMemo(() => {
return !!props.folders.find((f: FolderEntity) => !!f.icon);
}, [props.folders]);

const getSelectedItem = useCallback(() => {
if (props.notesParentType === 'Folder' && props.selectedFolderId) {
return { type: 'folder', id: props.selectedFolderId };
Expand Down Expand Up @@ -506,6 +522,7 @@ const SidebarComponent = (props: Props) => {
onFolderToggleClick_={onFolderToggleClick_}
shareId={folder.share_id}
parentId={folder.parent_id}
showFolderIcon={showFolderIcons}
/>;
};

Expand Down
1 change: 1 addition & 0 deletions packages/lib/services/database/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ export interface BaseItemEntity {
export enum FolderIconType {
Emoji = 1,
DataUrl = 2,
FontAwesome = 3,
}

export interface FolderIcon {
Expand Down

3 comments on commit 7974df9

@antoniopaolini
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's a way to restore the previous behavior (no foder's icon) with CSS?
In my setup the effect of this change is very ugly.
2022-12-19 14_17_24-joplin-2 8 8-2 9 17

@laurent22
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You could set the emojis that you have there as actual notebook icons?

@antoniopaolini
Copy link

@antoniopaolini antoniopaolini commented on 7974df9 Dec 19, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe I didn't understand (sorry, my english is not very good).

At left you can see some "manually inserted" icons (copy and paste from emoji list), put there before the 2.6.2, that added support for notebook icons.
For example the notebooks in the yellow rectangle or the bulb at the end of the notebook "Progetti 💡" or the english flag (in windows there's no flags emoji support AFAIK).
Others, like "🔴 Coperchio Nuovo" or "🧧000_TECO" are more recent, and are created with the Joplin function.

What I want is to keep the current emoji but not see the folder icons. Maybe making them transparent (only those of the folders, is it possible?), to have a cleaner look in which only the notebooks to which I gave an icon stand out.

For example I use (not visible in the screenshot) some emoji in front of some notebook name to make it urgent (🔺 or ❗) or less important (⬇️) , or to mark some project as done ✅ or closed (❌ or ⛔) or problematic (⚠️ or 🆘) or great ⭐.

Yes, I know, I'm "colorful"... 😅

Please sign in to comment.