mirror of
https://github.com/TurTaskProject/TurTaskWeb.git
synced 2025-12-18 21:44: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
|
||||
|
||||
|
||||
@receiver(post_save, sender=Todo)
|
||||
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."""
|
||||
# @receiver(post_save, sender=Todo)
|
||||
# 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."""
|
||||
# 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:
|
||||
user_board = instance.user.board_set.first()
|
||||
list_board_position = instance.position
|
||||
|
||||
if user_board:
|
||||
first_list_board = user_board.listboard_set.order_by('position').first()
|
||||
if list_board_position == 1:
|
||||
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:
|
||||
instance.list_board = first_list_board
|
||||
instance.save()
|
||||
for task_data in placeholder_tasks:
|
||||
Todo.objects.create(
|
||||
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({
|
||||
flow: "auth-code",
|
||||
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) => {
|
||||
try {
|
||||
const loginResponse = await googleLogin(response.code);
|
||||
|
||||
@ -7,7 +7,6 @@ import { TaskCard } from "./taskCard";
|
||||
import { axiosInstance } from "src/api/AxiosConfig";
|
||||
|
||||
export function KanbanBoard() {
|
||||
const [refreshKey, setRefreshKey] = useState(0);
|
||||
const [columns, setColumns] = useState([]);
|
||||
const [boardId, setBoardData] = useState();
|
||||
const [isLoading, setLoading] = useState(false);
|
||||
@ -17,10 +16,6 @@ export function KanbanBoard() {
|
||||
|
||||
// ---------------- END STATE INITIATE ----------------
|
||||
|
||||
const refreshSortableContext = () => {
|
||||
setRefreshKey((prevKey) => prevKey + 1);
|
||||
};
|
||||
|
||||
const sensors = useSensors(
|
||||
useSensor(PointerSensor, {
|
||||
activationConstraint: {
|
||||
@ -42,7 +37,7 @@ export function KanbanBoard() {
|
||||
const createTask = async (columnId) => {
|
||||
try {
|
||||
const response = await axiosInstance.post("todo/", {
|
||||
title: `Task ${tasks.length + 1}`,
|
||||
title: `New Task`,
|
||||
importance: 1,
|
||||
difficulty: 1,
|
||||
challenge: false,
|
||||
@ -53,7 +48,6 @@ export function KanbanBoard() {
|
||||
priority: 1,
|
||||
list_board: columnId,
|
||||
});
|
||||
|
||||
const newTask = {
|
||||
id: response.data.id,
|
||||
columnId,
|
||||
@ -61,13 +55,12 @@ export function KanbanBoard() {
|
||||
};
|
||||
|
||||
setTasks((prevTasks) => [...prevTasks, newTask]);
|
||||
refreshSortableContext();
|
||||
} catch (error) {
|
||||
handleApiError(error, "creating task");
|
||||
}
|
||||
};
|
||||
|
||||
const deleteTask = async (id, tasks) => {
|
||||
const deleteTask = async (id) => {
|
||||
try {
|
||||
await axiosInstance.delete(`todo/${id}/`);
|
||||
const newTasks = tasks.filter((task) => task.id !== id);
|
||||
@ -80,7 +73,7 @@ export function KanbanBoard() {
|
||||
const updateTask = async (id, content, tasks) => {
|
||||
try {
|
||||
if (content === "") {
|
||||
await deleteTask(id, tasks, setTasks);
|
||||
await deleteTask(id);
|
||||
} else {
|
||||
const response = await axiosInstance.put(`todo/${id}/`, { content });
|
||||
|
||||
@ -188,7 +181,7 @@ export function KanbanBoard() {
|
||||
createTask={createTask}
|
||||
deleteTask={deleteTask}
|
||||
updateTask={updateTask}
|
||||
tasks={tasks.filter((task) => task.columnId === col.id)}
|
||||
tasks={(tasks || []).filter((task) => task.columnId === col.id)}
|
||||
/>
|
||||
))}{" "}
|
||||
</SortableContext>
|
||||
@ -201,7 +194,7 @@ export function KanbanBoard() {
|
||||
{createPortal(
|
||||
<DragOverlay className="bg-white" dropAnimation={null} zIndex={20}>
|
||||
{/* Render the active task as a draggable overlay */}
|
||||
{activeTask && <TaskCard task={activeTask} deleteTask={deleteTask} updateTask={updateTask} />}
|
||||
<TaskCard task={activeTask} deleteTask={deleteTask} updateTask={updateTask} />
|
||||
</DragOverlay>,
|
||||
document.body
|
||||
)}
|
||||
@ -297,9 +290,8 @@ export function KanbanBoard() {
|
||||
}
|
||||
|
||||
const isOverAColumn = over.data.current?.type === "Column";
|
||||
|
||||
// Move the Task to a different column and update columnId
|
||||
if (isActiveATask && isOverAColumn) {
|
||||
if (isActiveATask && isOverAColumn && tasks.some((task) => task.columnId !== overId)) {
|
||||
setTasks((tasks) => {
|
||||
const activeIndex = tasks.findIndex((t) => t.id === activeId);
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user