-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTaskContext.tsx
More file actions
63 lines (57 loc) · 1.78 KB
/
TaskContext.tsx
File metadata and controls
63 lines (57 loc) · 1.78 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
import React, { createContext, useContext } from "react";
import { Task, Category } from "@/types/task";
import { EditingField } from "@/components/task/types";
// タスク編集に関するアクション
export interface TaskEditActions {
editingField: EditingField | null;
editValue: string;
setEditingField: (field: EditingField | null) => void;
setEditValue: (value: string) => void;
handleEditStart: (
taskId: string,
field:
| "title"
| "estimated_minute"
| "start_time"
| "end_time"
| "category_id",
value: string,
) => void;
handleEditChange: (e: React.ChangeEvent<HTMLInputElement>) => void;
handleEditSave: (customValue?: string) => void;
handleKeyDown: (e: React.KeyboardEvent<HTMLInputElement>) => void;
}
// タスク操作に関するアクション
export interface TaskActions {
handleDelete: (taskId: string) => void;
handleTaskTimer: (
taskId: string,
action: "start" | "stop" | "complete",
) => void;
handleRepeatTask: (task: Task) => void;
handleMoveToToday: (taskId: string) => void;
handlePauseTask: (task: Task) => void;
}
// タスクコンテキストの型定義
export interface TaskContextType {
// 状態
tasks: Task[];
categories: Category[];
lastTaskEndTime: string | null;
currentRunningTask: Task | null;
// アクション
taskEdit: TaskEditActions;
taskActions: TaskActions;
}
// コンテキストの作成
export const TaskContext = createContext<TaskContextType | undefined>(
undefined,
);
// TaskContextを使用するためのカスタムフック
export const useTaskContext = (): TaskContextType => {
const context = useContext(TaskContext);
if (context === undefined) {
throw new Error("useTaskContext must be used within a TaskProvider");
}
return context;
};