Skip to content

Commit

Permalink
feat(icons): integrate with Logseq in built icon property
Browse files Browse the repository at this point in the history
fix #23
  • Loading branch information
sawhney17 authored Jul 5, 2022
2 parents 9032930 + 79bb78c commit 5cb01d6
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 6 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "logseq-banners-plugin",
"version": "1.5.1",
"version": "1.6.1",
"main": "dist/index.html",
"scripts": {
"dev": "vite",
Expand Down
19 changes: 14 additions & 5 deletions src/main.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,12 @@ const initStyles = () => {
body:is([data-page="page"],[data-page="home"]).is-banner-active.is-icon-active #journals .journal-item:first-of-type h1.title::before {
display: none;
}
.cp__right-sidebar-inner .resizer {z-index:9;}
.cp__right-sidebar-inner .resizer {
z-index:9;
}
.page-title .page-icon {
display: none;
}
`)
}

Expand Down Expand Up @@ -210,7 +215,7 @@ const hideProps = () => {
const propBlockKeys = top?.document.getElementsByClassName("page-property-key");
if (propBlockKeys?.length) {
for (let i = 0; i < propBlockKeys.length; i++) {
if (propBlockKeys[i].textContent === "banner" || propBlockKeys[i].textContent === "page-icon") {
if (propBlockKeys[i].textContent === "banner" || propBlockKeys[i].textContent === "page-icon" || propBlockKeys[i].textContent === "icon") {
propBlockKeys[i].parentElement!.style.display = hidePluginProps ? "none" : "block" ;
}
}
Expand All @@ -219,6 +224,7 @@ const hideProps = () => {

// Render
const render = async () => {
hideProps();
// "Delete" icon on ever render start if no default allowed
if (!useDefault.pageIcon) {
clearIcon();
Expand Down Expand Up @@ -322,6 +328,11 @@ const getPropsAsset = async (assetType: string) => {
propsAsset = encodeURI("assets://" + graphPath + propsAsset.replace("..", ""));
}
}
if (!propsAsset && assetType === "pageIcon") {
console.info(`#${pluginId}: Trying logseq icon props`);
//@ts-expect-error
propsAsset = currentPageProps?.icon;
}
return propsAsset;
}

Expand Down Expand Up @@ -444,7 +455,6 @@ const clearIcon = () => {
const routeChangedCallback = () => {
console.info(`#${pluginId}: page route changed`);
// Content reloaded, so need reconnect props listeners
hideProps();
propsChangedObserverStop();
setTimeout(() => {
propsChangedObserverRun();
Expand All @@ -469,8 +479,7 @@ const main = async () => {

readPluginSettings();
initStyles();
hideProps();
setTimeout(() => {
setTimeout(() => {
render();
}, timeout*2)

Expand Down

0 comments on commit 5cb01d6

Please sign in to comment.