Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AI生成のボタンを実装 #83

Merged
merged 1 commit into from
Oct 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions task_yell/src/app/home/actions.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
"use server";

import { splitWantToDo } from "@/lib/ai";

export async function generateStickyNoteServer(note: string) {
return await splitWantToDo({ title: note, id: "" });
}
24 changes: 24 additions & 0 deletions task_yell/src/app/home/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import { Switch } from "@/components/ui/switch";
import { Textarea } from "@/components/ui/textarea";
import { signOut } from "@/firebase/auth";
import { auth, db } from "@/firebase/client-app";
import { splitWantToDo } from "@/lib/ai";
import { createEvent, readEvents } from "@/lib/events";
import { createNotification } from "@/lib/notifications";
import { subscribeNotification } from "@/lib/push-notification";
Expand Down Expand Up @@ -80,10 +81,12 @@ import {
Users,
Download,
LogOut,
Brain,
PhoneCall,
} from "lucide-react";
import { useRouter } from "next/navigation";
import { useEffect, useMemo, useRef, useState } from "react";
import { generateStickyNoteServer } from "./actions";

type Todo = {
id: string;
Expand Down Expand Up @@ -524,6 +527,20 @@ export default function Home() {
setEditingStickyNote(note);
};

const generateStickyNote = async (note: StickyNote) => {
if (auth.currentUser) {
const uid = auth.currentUser.uid;
const generated = await generateStickyNoteServer(note.title);
// Firestoreに追加
if (generated) {
const items = await Promise.all(
generated.map(async (item) => ({ id: await createWantTodo(uid, item), title: item.title })),
);
setStickyNotes([...stickyNotes, ...items]);
}
}
};

const updateStickyNote = async (updatedNote: StickyNote) => {
const updatedNotes = stickyNotes.map((note) =>
note.id === updatedNote.id ? updatedNote : note,
Expand Down Expand Up @@ -742,6 +759,13 @@ export default function Home() {
>
<h3 className="font-semibold mb-2">{note.title}</h3>
<div className="flex justify-end space-x-2">
<Button
variant="ghost"
size="icon"
onClick={() => generateStickyNote(note)}
>
<Brain className="h-4 w-4" />
</Button>
<Button
variant="ghost"
size="icon"
Expand Down
4 changes: 2 additions & 2 deletions task_yell/src/lib/want-todo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ const COLLECTION_NAME = "want-todos";
export async function createWantTodo(
userId: string,
wantTodo: WantTodo,
): Promise<void> {
await createData<WantTodo>(`users/${userId}/${COLLECTION_NAME}`, wantTodo);
): Promise<string> {
return await createData<WantTodo>(`users/${userId}/${COLLECTION_NAME}`, wantTodo);
}

/**
Expand Down
Loading