-
Notifications
You must be signed in to change notification settings - Fork 373
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add tag colors setup #704
Add tag colors setup #704
Conversation
a989841
to
fb181c1
Compare
const [colorPickerModal, showColorPickerModal] = useState(false) | ||
|
||
const openTagContextMenu: React.MouseEventHandler = useCallback( | ||
(_) => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you don't need to access the event parameter, you don't need to provide the handler type
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Removed!
title: 'Cannot update tag color.', | ||
description: 'Invalid note or tag.', | ||
}) | ||
console.log('Tag name or note was null', 'requested color:', color) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Delete this!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Removed!
src/components/pages/NotePage.tsx
Outdated
@@ -220,12 +220,18 @@ const NotePage = ({ storage }: NotePageProps) => { | |||
|
|||
const { showSearchModal } = useSearchModal() | |||
|
|||
const storageTags = useMemo(() => { | |||
if (storage == null) return [] | |||
return values(storage.tagMap).map((tag) => tag) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[...storage.tagMap.values()]
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is no values() on ObjectMap
So final should be:
return [...values(storage.tagMap)]
? copy of tags
or maybe even
return values(storage.tagMap)
? raw values
@@ -77,11 +78,17 @@ const WikiNotePage = ({ storage }: WikiNotePageProps) => { | |||
|
|||
const { showSearchModal } = useSearchModal() | |||
|
|||
const storageTags = useMemo(() => { | |||
if (storage == null) return [] | |||
return values(storage.tagMap).map((tag) => tag) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[...storage.tagMap.values()]
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is no values() on ObjectMap
So final should be:
return [...values(storage.tagMap)]
? copy of tags
or maybe even
return values(storage.tagMap)
? raw values
src/lib/colors.ts
Outdated
|
||
const brightnessDefaultThreshold = 110 | ||
|
||
export function getColorBrightness(color: RGBColor | string | null) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Don't accept null
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed!
src/lib/colors.ts
Outdated
} | ||
|
||
export function isColorBright( | ||
color: RGBColor | string | null, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Dont accept null
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed!
src/lib/db/createStore.ts
Outdated
@@ -922,6 +928,7 @@ export function createDbStoreCreator( | |||
return { | |||
...(await targetStorage.db.getTag(tagName))!, | |||
name: tagName, | |||
color: '', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If color is not set, I'd like to leave it as undefined
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Removed!
src/lib/db/createStore.ts
Outdated
map[name] = { | ||
...tagDoc, | ||
name, | ||
color: tagDoc.color || '', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Don't fill empty string.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed!
src/lib/db/types.ts
Outdated
@@ -70,6 +70,7 @@ export type TagDoc = { | |||
} & TagDocEditibleProps | |||
|
|||
export type TagDocEditibleProps = { | |||
color?: string | |||
data: JsonObject |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd like to put it in data
like bookmarked
prop of NoteDoc
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's a bit more work, because it is not a boolean.
But I think I managed to do it.
src/lib/styled/styleFunctions.ts
Outdated
@@ -199,3 +204,14 @@ export const flexCenter = () => `display: flex; | |||
align-items: center; | |||
justify-content: center; | |||
` | |||
|
|||
export const tagBgColor = ({ theme, color }: StyledProps & TagStyleProps) => ` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
tagBackgroundColor
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Renamed!
d48ce37
to
f8ac689
Compare
src/lib/db/createStore.ts
Outdated
map[name] = { | ||
...tagDoc, | ||
name, | ||
color: tagColor, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can access color directly from tagDoc.data.color
I don't see any benifits
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
True, a mistake! Fixed now!
src/lib/db/types.ts
Outdated
@@ -118,6 +118,7 @@ export type PopulatedFolderDoc = FolderDoc & { | |||
|
|||
export type PopulatedTagDoc = TagDoc & { | |||
name: string | |||
color?: string |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should be discarded
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, correct. Done!
@Rokt33r, @Komediruzecki: One concern I have with this is that the web browser users will not be able to right click on tags and open the context menu, as they can only perform left click. Instead, you can add a I've implemented this in #730. Feel free to copy over the code, or change the implementation. |
Hi, I agree that it will be a problem for users who don't have the typical right-click option (I suppose you mean mobile browser users or native android version in general?) I looked over the PR and I am missing some images how all of this looks like, can you share them? If the implementation wise makes sense, sure I will transfer the code or rebase it onto it if it merges to master sooner. |
I should've attached some pictures to make it clear, my bad. The web browser app (www.boostnote.io/app) will not allow users to right click. This is not the case only for mobile users, but for desktop browser users as well. This is what they'll see when they right click: By adding a control option (three vertical dots) to the list view, we can allow them to view the context menu by left clicking on this button: This control option may not be possible in the note view due to lack of space. But even then, I believe we should give the user the ability to use this feature through the list view |
Oh, I see, you are right. I'll rebase and integrate changes to make it easier for those users too. Thanks for the suggestion. |
4a3860f
to
65e6637
Compare
}, | ||
[tag, updateTagColorByName] | ||
) | ||
const tagColor = useCallback(() => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use useMemo
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Used!
colorBrightness: number | ||
} | ||
|
||
export default class DialogColorPicker extends React.Component< |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't see any benefits to make a class component. Please covert this into a function component!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
True, refactored
Add tag context menu (right click on tag) for chosing colors Add react color as color pickers library Add basic DB management for tags with color (FSNote, PouchDB, createStore API) Add basic UI component (react-color) for choosing the color Add basic handling of color brightness in tags and hover styles (black/white inversion, brigther, dimmer when bg is dark/light) Add colored tags inside note list note tag list
65e6637
to
d71ce2c
Compare
Add tag colors setup (#323):
Fix right click context menu in sidebar
How it works:
Users can right click on any tag in note tag list. The color picker comes up and on selection it changes colors (preview is below in color slider at right corner), below that are some predefined colors which can be clicked. Once user is satisfied with color, to close the dialog any click outside of the color picker will do. The color is then updated in UI acordingly.
For background colors which are too dark, hovering the tag will brighten it up, opposite works too.
For background colors which are too dark, text and remove tag button are light/white and vice versa.
The following image shows picking color:
Some colored tags preview:
v0.11.5 - new tag location examples:
Test:
IssueHunt Summary
Referenced issues
This pull request has been submitted to: