Skip to content

Commit e108791

Browse files
committed
jason boi and save
1 parent 8abd248 commit e108791

2 files changed

Lines changed: 51 additions & 2 deletions

File tree

app/routes/home.tsx

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -329,8 +329,25 @@ export default function TimelineEditor() {
329329
// }, [getMediaBinItems, getTimelineState, projectId]);
330330

331331
const handleSaveTimeline = useCallback(async () => {
332-
alert("save timeline");
333-
}, []);
332+
try {
333+
toast.info("Saving state of the project...");
334+
const id = projectId;
335+
if (!id) {
336+
toast.error("No project ID");
337+
return;
338+
}
339+
340+
const timelineState = getTimelineState();
341+
await axios.put(`/ai/api/api/projects/${encodeURIComponent(id)}`, timelineState, {
342+
withCredentials: true,
343+
});
344+
345+
toast.success("Timeline saved");
346+
} catch (error) {
347+
console.error(error);
348+
toast.error("Failed to save");
349+
}
350+
}, [getTimelineState, projectId]);
334351

335352
// Global Ctrl/Cmd+S to save timeline (registered after handler is defined)
336353
useEffect(() => {

backend/api/routes.py

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import json
2+
13
from fastapi import APIRouter, Depends, HTTPException, status
24

35
from api.schema import CreateProjectRequest
@@ -70,3 +72,33 @@ async def create_project(
7072
"created_at": row["created_at"].isoformat(),
7173
}
7274
}
75+
76+
77+
@router.put("/projects/{project_id}")
78+
async def save_project(
79+
project_id: str, timeline: dict, user: KimuJWT = Depends(get_current_user)
80+
) -> dict:
81+
"""
82+
Save the project timeline to the database.
83+
"""
84+
pool = await get_db_pool()
85+
async with pool.acquire() as conn:
86+
row = await conn.fetchrow(
87+
"""
88+
UPDATE projects
89+
SET timeline_state = $1::jsonb
90+
WHERE id = $2 AND user_id = $3
91+
RETURNING id
92+
""",
93+
json.dumps(timeline),
94+
project_id,
95+
user.user_id,
96+
)
97+
98+
if row is None:
99+
raise HTTPException(
100+
status_code=status.HTTP_404_NOT_FOUND,
101+
detail="Project not found",
102+
)
103+
104+
return {"ok": True, "project_id": str(row["id"])}

0 commit comments

Comments
 (0)