fixed bad commit and reverted prior to create note. Also added note id linking for iframe

This commit is contained in:
2026-02-27 13:53:08 -06:00
parent ef935ac37b
commit b59e2c2187
4 changed files with 272 additions and 109 deletions
+3 -1
View File
@@ -101,7 +101,9 @@ const App: Component = () => {
<Suspense fallback={<div class="flex items-center justify-center h-full"><div class="animate-spin rounded-full h-8 w-8 border-b-2 border-primary"></div></div>}>
<Show when={getEmbedView() === 'embed_notes'}>
{(() => {
const [selectedNoteId, setSelectedNoteId] = createSignal<string | null>(null);
const searchParams = new URLSearchParams(window.location.search);
const noteIdFromUrl = searchParams.get('noteId');
const [selectedNoteId, setSelectedNoteId] = createSignal<string | null>(noteIdFromUrl);
return <NotepadView selectedNoteId={selectedNoteId()} setSelectedNoteId={setSelectedNoteId} />;
})()}
</Show>
+2 -36
View File
@@ -5,52 +5,18 @@ interface EmbedAuthWrapperProps {
children: JSX.Element;
}
import { NOTES_COLLECTION } from "@/lib/constants";
export const EmbedAuthWrapper: Component<EmbedAuthWrapperProps> = (props) => {
const [isHydrated, setIsHydrated] = createSignal(pb.authStore.isValid);
const handleMessage = async (event: MessageEvent) => {
const handleMessage = (event: MessageEvent) => {
const { data } = event;
console.log('[DEBUG] EmbedAuthWrapper received message:', data?.type);
if (data?.type === "TASGRID_AUTH" && data.token) {
console.log("[DEBUG] Received TasGrid auth payload, hydrating...");
// Save triggers pb.authStore.onChange, which App.tsx is already listening to and calling initStore()
pb.authStore.save(data.token, data.user || null);
setIsHydrated(true);
}
if (data?.type === "TASGRID_CREATE_NOTE") {
const currentUserId = pb.authStore.model?.id;
if (!currentUserId) {
console.warn("[DEBUG] Rejecting note creation: Not authenticated");
return;
}
try {
const noteData = data.note || {};
const result = await pb.collection(NOTES_COLLECTION).create({
title: noteData.title || "New Note",
content: noteData.content || "",
tags: noteData.tags || [],
isPrivate: noteData.isPrivate === true,
user: currentUserId,
});
console.log("[DEBUG] Note created via API:", result.id);
// Respond back to parent
if (window.parent !== window) {
window.parent.postMessage({
type: "TASGRID_NOTE_CREATED",
noteId: result.id,
title: result.title
}, "*");
}
} catch (e) {
console.error("Failed to create note via API", e);
}
}
};
onMount(() => {