generated from haydenull/logseq-plugin-react-boilerplate
-
-
Notifications
You must be signed in to change notification settings - Fork 44
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(agenda3): ✨ custom project color
- Loading branch information
Showing
17 changed files
with
187 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,17 @@ | ||
const getTextColor = (bgColor: number[]) => { | ||
// 当color值大于128时,color值偏向255,即#ffffff,此时字体颜色应为#333333 | ||
// 当color值小于128时,color值偏向0,即#000000,此时字体颜色应为#ffffff | ||
const isWhiteBg = 0.213 * bgColor[0] + 0.715 * bgColor[1] + 0.072 * bgColor[2] > 255 / 2; | ||
return isWhiteBg ? '#333333': '#ffffff' | ||
const isWhiteBg = 0.299 * bgColor[0] + 0.587 * bgColor[1] + 0.114 * bgColor[2] > 128 | ||
return isWhiteBg ? '#333333' : '#ffffff' | ||
} | ||
|
||
/** | ||
* get text color base on background color | ||
* @param rbgColor rgba(11, 22, 33, 1) | ||
*/ | ||
export const autoTextColor = (rbgColor: string) => { | ||
const [red, green, blue, alpha] = rbgColor.replace(/(?:\(|\)|rgba)*/g, "").split(",") | ||
const [red, green, blue, alpha] = rbgColor.replace(/[rgba()]/g, '').split(',') | ||
if (rbgColor === 'rgb(149, 239, 181)') console.log('xxxxx', getTextColor([Number(red), Number(green), Number(blue)])) | ||
if (rbgColor === 'rgb(149, 239, 181)') console.log('yyyyy', [red, Number(green), Number(blue)]) | ||
return getTextColor([Number(red), Number(green), Number(blue)]) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import { useAtom } from 'jotai' | ||
|
||
import { getAllProjects } from '@/newHelper/project' | ||
import { allProjectsAtom } from '@/newModel/projects' | ||
|
||
const useNewProjects = () => { | ||
const [, setProjects] = useAtom(allProjectsAtom) | ||
const refreshProjects = () => { | ||
getAllProjects().then((projects) => setProjects(projects)) | ||
} | ||
|
||
return { | ||
refreshProjects, | ||
} | ||
} | ||
|
||
export default useNewProjects |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import tinycolor from 'tinycolor2' | ||
|
||
import { BACKGROUND_COLOR, DEFAULT_BG_COLOR_NAME } from '@/constants/agenda' | ||
import { autoTextColor } from '@/helper/autoTextColor' | ||
import type { AgendaProject } from '@/types/project' | ||
import type { AgendaTaskPage } from '@/types/task' | ||
|
||
export const getAllProjects = async () => { | ||
const pages = (await logseq.Editor.getAllPages()) || [] | ||
return pages?.map((page) => { | ||
return transformPageToProject({ | ||
...page, | ||
isJournal: page['journal?'], | ||
}) | ||
}) | ||
} | ||
|
||
export const transformPageToProject = (page: AgendaTaskPage): AgendaProject => { | ||
const colorName = page.properties?.['agenda-color'] || DEFAULT_BG_COLOR_NAME | ||
const bgColor = BACKGROUND_COLOR[colorName] || BACKGROUND_COLOR[DEFAULT_BG_COLOR_NAME] | ||
return { | ||
...page, | ||
id: page.uuid, | ||
isJournal: page['journal?'], | ||
isFavorite: page.properties?.['agenda-favorite'] === 'yes', | ||
bgColor, | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import { atom } from 'jotai' | ||
|
||
import type { AgendaProject } from '@/types/project' | ||
|
||
export const allProjectsAtom = atom<AgendaProject[]>([]) | ||
|
||
export const favoriteProjectsAtom = atom<AgendaProject[]>((get) => { | ||
const allProjects = get(allProjectsAtom) | ||
return allProjects.filter((project) => project.isFavorite) | ||
}) | ||
|
||
export const journalProjectsAtom = atom<AgendaProject[]>((get) => { | ||
const allProjects = get(allProjectsAtom) | ||
return allProjects.filter((project) => project.isJournal && !project.isFavorite) | ||
}) | ||
|
||
export const normalProjectsAtom = atom<AgendaProject[]>((get) => { | ||
const allProjects = get(allProjectsAtom) | ||
return allProjects.filter((project) => !project.isJournal && !project.isFavorite) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.