tu2-atmanand / Task-Board

An Obsidian plugin to view and manage all your task in a much more efficient Kanban Board format. Easily manage your tasks throught your vault.
https://tu2-atmanand.github.io/task-board-docs/
GNU General Public License v3.0
5 stars 0 forks source link

Bigger issues with refreshing board using REFRESH_COLUMN #53

Open tu2-atmanand opened 1 month ago

tu2-atmanand commented 1 month ago

There are the below three major issues I am facing, after I make the board Operations or when the board refreshes after detecting a file change, the changes didnt update in the board, this is basically with the REFRESH_COLUMN event :

tu2-atmanand commented 1 month ago

The possible reason, why I think this must be happening is due to the fact that, I am using MarkdownRenderer for SubTasks and Description. But still, the Show Description button should have shown, after updating/adding Description content to the task. So, something is happening.

Also, now, i have to think on using an method to refresh only a specific taskItem Card whenever it changes. Like, incase of realTime Scanning, if suppose say, i figure out how to detect only the specific part of file being modified by user, then i can find out whether the task has been changed or other part of the file is being modified. This way, In the UI side, i can assign the taskItem with an id, which will be the task.id. And i can use function like getElementById to refresh that specific task.

Other than this, for now i have to come up with a better solution, because, when task is suppose to move from one column to another, then both of this columns should be refreshed. Or in case of editing just the content of the task, then the taskItem Card HTML should be re-rendered. I will have to go through my code again to see if any such thing will be possible.

tu2-atmanand commented 1 month ago
tu2-atmanand commented 1 month ago

Solution

The second biggest issue which i was facing in this main issue when any task's due date has been updated, then the task was suppose to go along with its subTasks and Description from one column to another. But earlier, its subTasks and Description were not getting moved and also those properties of this task was getting replaced to the task which was below to the task under consideration. So, to solve this issue i came up with a best solution of assigning a unique Id which was an combination of task.id and index of the subTasks, and this has been solved the issue using the following code :

    const subtaskTextRefs = useRef<{ [key: string]: HTMLDivElement | null }>({});
    useEffect(() => {
        // Render subtasks after componentRef is initialized
        task.body.forEach((subtaskText, index) => {
            const uniqueKey = `${task.id}-${index}`;
            const element = subtaskTextRefs.current[uniqueKey];

            if (element) {
                element.innerHTML = ''; // Clear previous content

                const strippedSubtaskText = subtaskText.replace(/- \[.*?\]/, "").trim();

                MarkdownUIRenderer.renderSubtaskText(
                    app,
                    strippedSubtaskText,
                    element,
                    task.filePath,
                    componentRef.current
                );

                hookMarkdownLinkMouseEventHandlers(app, element, task.filePath, task.filePath);
            }
        });
    }, [task.body, task.filePath, app]);

    // Render sub-tasks and remaining body separately
    const renderSubTasks = () => {
        try {
            if (task.body.length > 0) {
                return (
                    <>
                        {task.body.map((line, index) => {
                            const isCompleted = line.trim().startsWith('- [x]');
                            const isSubTask = line.trim().startsWith('- [ ]') || line.trim().startsWith('- [x]');
                            const subtaskText = line.replace(/- \[.\] /, '').trim();

                            // Calculate padding based on the number of tabs
                            const numTabs = line.match(/^\t+/)?.[0].length || 0;
                            const paddingLeft = numTabs > 1 ? `${(numTabs - 1) * 15}px` : '0px';

                            // Create a unique key for this subtask based on task.id and index
                            const uniqueKey = `${task.id}-${index}`;

                            return isSubTask ? (
                                <div
                                    className="taskItemBodySubtaskItem"
                                    key={uniqueKey}
                                    style={{ paddingLeft }}
                                    id={uniqueKey} // Assign a unique ID for each subtask element
                                >
                                    <input
                                        type="checkbox"
                                        className="taskItemBodySubtaskItemCheckbox"
                                        checked={isCompleted}
                                        onChange={() => handleSubtaskCheckboxChange(index, isCompleted)}
                                    />
                                    {/* Render each subtask separately */}
                                    <div
                                        className="subtaskTextRenderer"
                                        ref={(el) => (subtaskTextRefs.current[uniqueKey] = el)} // Assign unique ref to each subtask
                                    />
                                </div>
                            ) : null;
                        })}
                    </>
                );
            } else {
                return null;
            }
        } catch (error) {
            console.log('Getting error while trying to render the SubTasks: ', error);
            return null;
        }
    };
tu2-atmanand commented 1 month ago

In summary, now,

If we could focus on this two things, then the whole issue will be resolved.

tu2-atmanand commented 1 month ago

This is not related to this issue but still adding :

tu2-atmanand commented 3 weeks ago

It was a very silly mistake of mine, because of which I has to write so many things. I knew a long back it uses to refreshes only columns and not the whole board when i use to do the checkbox operation or edit operations, etc.

MISTAKE : While making changes in the TaskItemUtils file, i removed the emmit lines which were refreshing the tasks after those json operatoins.🤣

Now, even though I have solved that problem, keep testing the board thoroughly, to find out in which case the board is not updating. Obviously the issue of Description getting appending to previous task issue is still there, but now the board has became usable, after solving this error now. I have to still keep optimizing the code now. I am not telling to write high level code this time, that is before releasing, keep the code simple only, but there may be some HTML methods only to refresh a specific taskItem kind of approaches which i can use to solve this problem, or to make the refreshing operation more optimized.

tu2-atmanand commented 2 weeks ago