Fix create_prompt is_public bug, conditional version bump, and add Jotai prompts atoms

- Pass is_public from request body in create_prompt route
- Only bump version on content field changes (name, prompt, mode),
  not on is_public toggle
- Add prompts query and mutation atoms (atomWithQuery/atomWithMutation)
  with TanStack Query caching, replacing manual useEffect fetches
- Update PromptPicker, PromptsContent, and CommunityPromptsContent
  to consume shared atoms instead of local state
This commit is contained in:
CREDO23 2026-03-31 18:34:10 +02:00
parent 95620a4331
commit 5f4f7780d1
7 changed files with 184 additions and 88 deletions

View file

@ -41,6 +41,7 @@ async def create_prompt(
name=body.name,
prompt=body.prompt,
mode=body.mode,
is_public=body.is_public,
)
session.add(prompt)
await session.commit()
@ -65,10 +66,15 @@ async def update_prompt(
if not prompt:
raise HTTPException(status_code=404, detail="Prompt not found")
for field, value in body.model_dump(exclude_unset=True).items():
updates = body.model_dump(exclude_unset=True)
content_fields = {"name", "prompt", "mode"}
has_content_change = bool(updates.keys() & content_fields)
for field, value in updates.items():
setattr(prompt, field, value)
prompt.version = (prompt.version or 0) + 1
if has_content_change:
prompt.version = (prompt.version or 0) + 1
session.add(prompt)
await session.commit()