Skip to content

Commit b83a7a1

Browse files
committed
🧑‍💻 open TIL items in notion with shortcut
1 parent 3e964f4 commit b83a7a1

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

apps/nye-julianjark.no/app/components/dette-kan-jeg.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { classNames, shuffled } from "~/utils/misc";
55
import { HoverCard, HoverCardContent, HoverCardTrigger } from "./hover-card";
66
import { RichTextListRender } from "@julianjark/notion-render";
77
import { Popover, PopoverContent, PopoverTrigger } from "~/components/popover";
8+
import { RegisterEditNotionPage } from "~/routes/($prefix).$notionPage/use-edit-notion-page";
89

910
export const getDetteKanJegData = async () => {
1011
const detteKanJeg = await getAllDetteKanJeg();
@@ -75,6 +76,7 @@ function KnowledgeList({ knowledge }: { knowledge: DetteKanJeg[] }) {
7576
sideOffset={14}
7677
className="p-6 w-96 flex space-x-6"
7778
>
79+
<RegisterEditNotionPage pageId={item.id} />
7880
{item.logo && (
7981
<span className="relative flex h-12 w-12 shrink-0 overflow-hidden">
8082
<img

apps/nye-julianjark.no/app/routes/($prefix).$notionPage/use-edit-notion-page.tsx

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import { useEffect } from "react";
22

33
// This lets the notion editing be triggered from anywhere in the app
4-
// Although not not ideal, it works
54
let currentNotionPageId: string | undefined;
65
export function openCurrentNotionPage() {
76
if (!currentNotionPageId) return;
@@ -19,6 +18,20 @@ export function openCurrentNotionPage() {
1918
*/
2019
export function useEditNotionPage({ pageId }: { pageId: string }) {
2120
useEffect(() => {
21+
const previousNotionPageId = currentNotionPageId;
2222
currentNotionPageId = pageId;
23+
24+
// Use the previous pageId when this unmounts
25+
// This allows us to use this in dialogs and other places temporary components
26+
return () => {
27+
if (currentNotionPageId === pageId) {
28+
currentNotionPageId = previousNotionPageId;
29+
}
30+
};
2331
}, [pageId]);
2432
}
33+
34+
export function RegisterEditNotionPage({ pageId }: { pageId: string }) {
35+
useEditNotionPage({ pageId });
36+
return null;
37+
}

0 commit comments

Comments
 (0)