Skip to content

armgit / memos

Public Imported from GitHub
0

Memos is an open-source, self-hosted note-taking app that brings your everyday thoughts together in a personal timeline. Your data stays yours, and you choose what to keep private or share.

chore: fix hover heatmap

boojack0dc377550ff1
diff --git a/web/src/components/UsageHeatMap.tsx b/web/src/components/UsageHeatMap.tsx
index f9e85c2c9..fd52a534d 100644
--- a/web/src/components/UsageHeatMap.tsx
+++ b/web/src/components/UsageHeatMap.tsx
@@ -37,10 +37,8 @@ const UsageHeatMap: React.FC<Props> = () => {
const { memos } = useAppSelector((state) => state.memo);
const [allStat, setAllStat] = useState<DailyUsageStat[]>(getInitialUsageStat(usedDaysAmount, beginDayTimestemp));
- const [popupStat, setPopupStat] = useState<DailyUsageStat | null>(null);
const [currentStat, setCurrentStat] = useState<DailyUsageStat | null>(null);
const containerElRef = useRef<HTMLDivElement>(null);
- const popupRef = useRef<HTMLDivElement>(null);
useEffect(() => {
const newStat: DailyUsageStat[] = getInitialUsageStat(usedDaysAmount, beginDayTimestemp);
@@ -54,18 +52,17 @@ const UsageHeatMap: React.FC<Props> = () => {
}, [memos]);
const handleUsageStatItemMouseEnter = useCallback((event: React.MouseEvent, item: DailyUsageStat) => {
- setPopupStat(item);
- if (!popupRef.current) {
- return;
- }
-
+ const tempDiv = document.createElement("div");
+ tempDiv.className = "usage-detail-container pop-up";
const bounding = utils.getElementBounding(event.target as HTMLElement);
- popupRef.current.style.left = bounding.left + "px";
- popupRef.current.style.top = bounding.top - 4 + "px";
+ tempDiv.style.left = bounding.left + "px";
+ tempDiv.style.top = bounding.top - 2 + "px";
+ tempDiv.innerHTML = `${item.count} memos on <span className="date-text">${new Date(item.timestamp as number).toDateString()}</span>`;
+ document.body.appendChild(tempDiv);
}, []);
const handleUsageStatItemMouseLeave = useCallback(() => {
- setPopupStat(null);
+ document.body.querySelectorAll("div.usage-detail-container.pop-up").forEach((node) => node.remove());
}, []);
const handleUsageStatItemClick = useCallback((item: DailyUsageStat) => {
@@ -89,11 +86,6 @@ const UsageHeatMap: React.FC<Props> = () => {
<span className="tip-text"></span>
<span className="tip-text">Sat</span>
</div>
-
- <div ref={popupRef} className={"usage-detail-container pop-up " + (popupStat ? "" : "hidden")}>
- {popupStat?.count} memos on <span className="date-text">{new Date(popupStat?.timestamp as number).toDateString()}</span>
- </div>
-
<div className="usage-heat-map">
{allStat.map((v, i) => {
const count = v.count;
diff --git a/web/src/helpers/consts.ts b/web/src/helpers/consts.ts
index 01b4bcc0c..02ec445f0 100644
--- a/web/src/helpers/consts.ts
+++ b/web/src/helpers/consts.ts
@@ -11,7 +11,7 @@ export const TOAST_ANIMATION_DURATION = 400;
export const DAILY_TIMESTAMP = 3600 * 24 * 1000;
// tag regex
-export const TAG_REG = /#(.+?) /g;
+export const TAG_REG = /#(\S+?) /g;
// markdown image regex
export const IMAGE_URL_REG = /!\[.*?\]\((.+?)\)/g;
diff --git a/web/src/less/usage-heat-map.less b/web/src/less/usage-heat-map.less
index 75417ff73..b086810ac 100644
--- a/web/src/less/usage-heat-map.less
+++ b/web/src/less/usage-heat-map.less
@@ -55,23 +55,23 @@
}
}
}
+}
- > .usage-detail-container {
- @apply fixed left-0 top-0 ml-2 -mt-9 p-2 z-100 -translate-x-1/2 select-none text-white text-xs rounded whitespace-nowrap;
- background-color: rgba(0, 0, 0, 0.8);
+.usage-detail-container {
+ @apply fixed left-0 top-0 ml-2 -mt-9 p-2 z-100 -translate-x-1/2 select-none text-white text-xs rounded whitespace-nowrap;
+ background-color: rgba(0, 0, 0, 0.8);
- > .date-text {
- @apply text-gray-300;
- }
+ > .date-text {
+ @apply text-gray-300;
+ }
- &::before {
- content: "";
- position: absolute;
- bottom: -4px;
- left: calc(50% - 5px);
- border-left: 4px solid transparent;
- border-right: 4px solid transparent;
- border-top: 4px solid rgba(0, 0, 0, 0.8);
- }
+ &::before {
+ content: "";
+ position: absolute;
+ bottom: -4px;
+ left: calc(50% - 5px);
+ border-left: 4px solid transparent;
+ border-right: 4px solid transparent;
+ border-top: 4px solid rgba(0, 0, 0, 0.8);
}
}