Skip to content

Commit

Permalink
予定の作成など
Browse files Browse the repository at this point in the history
  • Loading branch information
yuto-trd committed Oct 27, 2024
1 parent 9a6b757 commit f7b781e
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 9 deletions.
56 changes: 48 additions & 8 deletions task_yell/src/app/home/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,11 @@ import {
} from "@/components/ui/sheet";
import { Switch } from "@/components/ui/switch";
import { Textarea } from "@/components/ui/textarea";
import { signOut } from "@/firebase/auth";
import { auth } from "@/firebase/client-app";
import { readEvents } from "@/lib/events";
import { createEvent, readEvents } from "@/lib/events";
import { Category, Priority } from "@/lib/types";
import { createWantTodo, deleteWantTodo, readWantTodos, updateWantTodo } from "@/lib/want-todo";
import {
AngleIcon,
ListBulletIcon,
Expand Down Expand Up @@ -389,6 +391,15 @@ export default function Home() {
};
}));
});

readWantTodos(auth.currentUser.uid).then((todos) => {
setStickyNotes(todos.map((todo) => {
return {
id: todo.id,
title: todo.title,
};
}));
});
}
});
}, [router]);
Expand All @@ -408,42 +419,59 @@ export default function Home() {
{
icon: Bell,
label: "通知",
onClick: () => setIsNotificationsOpen(!isNotificationsOpen),
onClick: () => {
return setIsNotificationsOpen(!isNotificationsOpen);
},
},
{ icon: Users, label: "友達", onClick: () => console.log("友達") },
{
icon: Download,
label: "インポート",
onClick: () => console.log("インポート"),
onClick: () => {
if (auth.currentUser) {
router.push(`/api/auth/google-cal?userId=${encodeURIComponent(auth.currentUser.uid)}`)
}
},
},
{
icon: LogOut,
label: "ログアウト",
onClick: () => console.log("ログアウト"),
onClick: async () => {
await signOut();
router.refresh();
},
},
];

const addStickyNote = () => {
const addStickyNote = async () => {
if (newStickyNote.trim()) {
const newNote: StickyNote = { id: "", title: newStickyNote };
setStickyNotes([...stickyNotes, newNote]);
setNewStickyNote("");
if (auth.currentUser) {
await createWantTodo(auth.currentUser.uid, newNote);
}
}
};

const editStickyNote = (note: StickyNote) => {
setEditingStickyNote(note);
};

const updateStickyNote = (updatedNote: StickyNote) => {
const updateStickyNote = async (updatedNote: StickyNote) => {
const updatedNotes = stickyNotes.map((note) =>
note.id === updatedNote.id ? updatedNote : note,
);
setStickyNotes(updatedNotes);
setEditingStickyNote(null);
if (auth.currentUser) {
await updateWantTodo(auth.currentUser.uid, updatedNote.id, {
title: updatedNote.title,
})
}
};

const deleteStickyNote = (id: string) => {
const deleteStickyNote = async (id: string) => {
const noteToRemove = stickyNotes.find((note) => note.id === id);
if (noteToRemove) {
setRemovedStickyNote(noteToRemove);
Expand All @@ -452,12 +480,24 @@ export default function Home() {
if (draggedStickyNote && draggedStickyNote.id === id) {
setDraggedStickyNote(null);
}
if (auth.currentUser) {
await deleteWantTodo(auth.currentUser.uid, id);
}
};

const addEvent = (newEvent: Event) => {
const addEvent = async (newEvent: Event) => {
setEvents([...events, newEvent]);
setIsEventModalOpen(false);
setRemovedStickyNote(null);
if (auth.currentUser) {
await createEvent(auth.currentUser.uid, {
...newEvent,
attendees: newEvent.invitees.split(",").map((invitee) => invitee.trim()),
category: newEvent.category,
priority: newEvent.priority,
reccurence: []
});
}
};

const getDaysInMonth = (date: Date) => {
Expand Down
2 changes: 1 addition & 1 deletion task_yell/src/firebase/firestore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ export async function readSingleData<T>(
): Promise<T | null> {
const docRef = doc(db, collectionName, id);
const snapshot = await getDoc(docRef);
return snapshot.exists() ? (snapshot.data() as T) : null;
return snapshot.exists() ? { ...(snapshot.data() as T), id: id } : null;
}

export async function updateData<T>(
Expand Down

0 comments on commit f7b781e

Please sign in to comment.