create note api added
This commit is contained in:
@@ -5,18 +5,52 @@ 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 = (event: MessageEvent) => {
|
||||
const handleMessage = async (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(() => {
|
||||
|
||||
Reference in New Issue
Block a user