mirror of
https://github.com/TurTaskProject/TurTaskWeb.git
synced 2025-12-19 22:14:07 +01:00
Make Kanban More responsive, auto add task for new user
This commit is contained in:
parent
fc817d9677
commit
e83e58db07
@ -27,15 +27,63 @@ def update_priority(sender, instance, **kwargs):
|
|||||||
instance.priority = Todo.EisenhowerMatrix.NOT_IMPORTANT_NOT_URGENT
|
instance.priority = Todo.EisenhowerMatrix.NOT_IMPORTANT_NOT_URGENT
|
||||||
|
|
||||||
|
|
||||||
@receiver(post_save, sender=Todo)
|
# @receiver(post_save, sender=Todo)
|
||||||
def assign_todo_to_listboard(sender, instance, created, **kwargs):
|
# def assign_todo_to_listboard(sender, instance, created, **kwargs):
|
||||||
"""Signal handler to automatically assign a Todo to the first ListBoard in the user's Board upon creation."""
|
# """Signal handler to automatically assign a Todo to the first ListBoard in the user's Board upon creation."""
|
||||||
|
# if created:
|
||||||
|
# user_board = instance.user.board_set.first()
|
||||||
|
|
||||||
|
# if user_board:
|
||||||
|
# first_list_board = user_board.listboard_set.order_by('position').first()
|
||||||
|
|
||||||
|
# if first_list_board:
|
||||||
|
# instance.list_board = first_list_board
|
||||||
|
# instance.save()
|
||||||
|
|
||||||
|
|
||||||
|
@receiver(post_save, sender=ListBoard)
|
||||||
|
def create_placeholder_tasks(sender, instance, created, **kwargs):
|
||||||
|
"""
|
||||||
|
Signal handler to create placeholder tasks for each ListBoard.
|
||||||
|
"""
|
||||||
if created:
|
if created:
|
||||||
user_board = instance.user.board_set.first()
|
list_board_position = instance.position
|
||||||
|
|
||||||
if user_board:
|
if list_board_position == 1:
|
||||||
first_list_board = user_board.listboard_set.order_by('position').first()
|
placeholder_tasks = [
|
||||||
|
{"title": "Normal Task Example"},
|
||||||
|
{"title": "Task with Extra Information Example", "description": "Description for Task 2"},
|
||||||
|
]
|
||||||
|
elif list_board_position == 2:
|
||||||
|
placeholder_tasks = [
|
||||||
|
{"title": "Time Task Example #1", "description": "Description for Task 2",
|
||||||
|
"start_event": timezone.now(), "end_event": timezone.now() + timezone.timedelta(days=5)},
|
||||||
|
]
|
||||||
|
elif list_board_position == 3:
|
||||||
|
placeholder_tasks = [
|
||||||
|
{"title": "Time Task Example #2", "description": "Description for Task 2",
|
||||||
|
"start_event": timezone.now(), "end_event": timezone.now() + timezone.timedelta(days=30)},
|
||||||
|
]
|
||||||
|
elif list_board_position == 4:
|
||||||
|
placeholder_tasks = [
|
||||||
|
{"title": "Completed Task Example", "description": "Description for Task 2",
|
||||||
|
"start_event": timezone.now(), "completed": True},
|
||||||
|
]
|
||||||
|
else:
|
||||||
|
placeholder_tasks = [
|
||||||
|
{"title": "Default Task Example"},
|
||||||
|
]
|
||||||
|
|
||||||
if first_list_board:
|
for task_data in placeholder_tasks:
|
||||||
instance.list_board = first_list_board
|
Todo.objects.create(
|
||||||
instance.save()
|
list_board=instance,
|
||||||
|
user=instance.board.user,
|
||||||
|
title=task_data["title"],
|
||||||
|
notes=task_data.get("description", ""),
|
||||||
|
is_active=True,
|
||||||
|
start_event=task_data.get("start_event"),
|
||||||
|
end_event=task_data.get("end_event"),
|
||||||
|
completed=task_data.get("completed", False),
|
||||||
|
creation_date=timezone.now(),
|
||||||
|
last_update=timezone.now(),
|
||||||
|
)
|
||||||
@ -55,6 +55,8 @@ export function SignUp() {
|
|||||||
const googleLoginImplicit = useGoogleLogin({
|
const googleLoginImplicit = useGoogleLogin({
|
||||||
flow: "auth-code",
|
flow: "auth-code",
|
||||||
redirect_uri: "postmessage",
|
redirect_uri: "postmessage",
|
||||||
|
scope:
|
||||||
|
"https://www.googleapis.com/auth/userinfo.email https://www.googleapis.com/auth/userinfo.profile https://www.googleapis.com/auth/calendar.acls.readonly https://www.googleapis.com/auth/calendar.events.readonly",
|
||||||
onSuccess: async (response) => {
|
onSuccess: async (response) => {
|
||||||
try {
|
try {
|
||||||
const loginResponse = await googleLogin(response.code);
|
const loginResponse = await googleLogin(response.code);
|
||||||
|
|||||||
@ -7,7 +7,6 @@ import { TaskCard } from "./taskCard";
|
|||||||
import { axiosInstance } from "src/api/AxiosConfig";
|
import { axiosInstance } from "src/api/AxiosConfig";
|
||||||
|
|
||||||
export function KanbanBoard() {
|
export function KanbanBoard() {
|
||||||
const [refreshKey, setRefreshKey] = useState(0);
|
|
||||||
const [columns, setColumns] = useState([]);
|
const [columns, setColumns] = useState([]);
|
||||||
const [boardId, setBoardData] = useState();
|
const [boardId, setBoardData] = useState();
|
||||||
const [isLoading, setLoading] = useState(false);
|
const [isLoading, setLoading] = useState(false);
|
||||||
@ -17,10 +16,6 @@ export function KanbanBoard() {
|
|||||||
|
|
||||||
// ---------------- END STATE INITIATE ----------------
|
// ---------------- END STATE INITIATE ----------------
|
||||||
|
|
||||||
const refreshSortableContext = () => {
|
|
||||||
setRefreshKey((prevKey) => prevKey + 1);
|
|
||||||
};
|
|
||||||
|
|
||||||
const sensors = useSensors(
|
const sensors = useSensors(
|
||||||
useSensor(PointerSensor, {
|
useSensor(PointerSensor, {
|
||||||
activationConstraint: {
|
activationConstraint: {
|
||||||
@ -42,7 +37,7 @@ export function KanbanBoard() {
|
|||||||
const createTask = async (columnId) => {
|
const createTask = async (columnId) => {
|
||||||
try {
|
try {
|
||||||
const response = await axiosInstance.post("todo/", {
|
const response = await axiosInstance.post("todo/", {
|
||||||
title: `Task ${tasks.length + 1}`,
|
title: `New Task`,
|
||||||
importance: 1,
|
importance: 1,
|
||||||
difficulty: 1,
|
difficulty: 1,
|
||||||
challenge: false,
|
challenge: false,
|
||||||
@ -53,7 +48,6 @@ export function KanbanBoard() {
|
|||||||
priority: 1,
|
priority: 1,
|
||||||
list_board: columnId,
|
list_board: columnId,
|
||||||
});
|
});
|
||||||
|
|
||||||
const newTask = {
|
const newTask = {
|
||||||
id: response.data.id,
|
id: response.data.id,
|
||||||
columnId,
|
columnId,
|
||||||
@ -61,13 +55,12 @@ export function KanbanBoard() {
|
|||||||
};
|
};
|
||||||
|
|
||||||
setTasks((prevTasks) => [...prevTasks, newTask]);
|
setTasks((prevTasks) => [...prevTasks, newTask]);
|
||||||
refreshSortableContext();
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
handleApiError(error, "creating task");
|
handleApiError(error, "creating task");
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const deleteTask = async (id, tasks) => {
|
const deleteTask = async (id) => {
|
||||||
try {
|
try {
|
||||||
await axiosInstance.delete(`todo/${id}/`);
|
await axiosInstance.delete(`todo/${id}/`);
|
||||||
const newTasks = tasks.filter((task) => task.id !== id);
|
const newTasks = tasks.filter((task) => task.id !== id);
|
||||||
@ -80,7 +73,7 @@ export function KanbanBoard() {
|
|||||||
const updateTask = async (id, content, tasks) => {
|
const updateTask = async (id, content, tasks) => {
|
||||||
try {
|
try {
|
||||||
if (content === "") {
|
if (content === "") {
|
||||||
await deleteTask(id, tasks, setTasks);
|
await deleteTask(id);
|
||||||
} else {
|
} else {
|
||||||
const response = await axiosInstance.put(`todo/${id}/`, { content });
|
const response = await axiosInstance.put(`todo/${id}/`, { content });
|
||||||
|
|
||||||
@ -188,7 +181,7 @@ export function KanbanBoard() {
|
|||||||
createTask={createTask}
|
createTask={createTask}
|
||||||
deleteTask={deleteTask}
|
deleteTask={deleteTask}
|
||||||
updateTask={updateTask}
|
updateTask={updateTask}
|
||||||
tasks={tasks.filter((task) => task.columnId === col.id)}
|
tasks={(tasks || []).filter((task) => task.columnId === col.id)}
|
||||||
/>
|
/>
|
||||||
))}{" "}
|
))}{" "}
|
||||||
</SortableContext>
|
</SortableContext>
|
||||||
@ -201,7 +194,7 @@ export function KanbanBoard() {
|
|||||||
{createPortal(
|
{createPortal(
|
||||||
<DragOverlay className="bg-white" dropAnimation={null} zIndex={20}>
|
<DragOverlay className="bg-white" dropAnimation={null} zIndex={20}>
|
||||||
{/* Render the active task as a draggable overlay */}
|
{/* Render the active task as a draggable overlay */}
|
||||||
{activeTask && <TaskCard task={activeTask} deleteTask={deleteTask} updateTask={updateTask} />}
|
<TaskCard task={activeTask} deleteTask={deleteTask} updateTask={updateTask} />
|
||||||
</DragOverlay>,
|
</DragOverlay>,
|
||||||
document.body
|
document.body
|
||||||
)}
|
)}
|
||||||
@ -297,9 +290,8 @@ export function KanbanBoard() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const isOverAColumn = over.data.current?.type === "Column";
|
const isOverAColumn = over.data.current?.type === "Column";
|
||||||
|
|
||||||
// Move the Task to a different column and update columnId
|
// Move the Task to a different column and update columnId
|
||||||
if (isActiveATask && isOverAColumn) {
|
if (isActiveATask && isOverAColumn && tasks.some((task) => task.columnId !== overId)) {
|
||||||
setTasks((tasks) => {
|
setTasks((tasks) => {
|
||||||
const activeIndex = tasks.findIndex((t) => t.id === activeId);
|
const activeIndex = tasks.findIndex((t) => t.id === activeId);
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user