Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add "Close" button to close kanban and disable auto closing #44

Merged
merged 1 commit into from
Jul 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion src/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,10 @@ export interface NewNoteAction {
};
}

export interface CloseAction {
type: "close";
}

export type Action =
| MoveNoteAction
| LoadAction
Expand All @@ -66,4 +70,5 @@ export type Action =
| OpenNoteAction
| AddColumnAction
| DeleteColAction
| NewNoteAction;
| NewNoteAction
| CloseAction;
11 changes: 9 additions & 2 deletions src/gui/index.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React from "react";
import { render } from "react-dom";
import styled from "styled-components";
import { IoMdSettings, IoMdAdd } from "react-icons/io";
import { IoMdSettings, IoMdAdd, IoMdClose } from "react-icons/io";

import { capitalize } from "../utils";
import { DispatchFn, useRemoteBoard } from "./hooks";
Expand Down Expand Up @@ -59,6 +59,13 @@ function App() {
const cont = board ? (
<Container>
<Header>
<IconCont
onClick={() => {
dispatch({ type: "close" })
}}
>
<IoMdClose size="20px"/>
</IconCont>
{board.name}
<IconCont
onClick={() =>
Expand Down Expand Up @@ -147,7 +154,7 @@ const IconCont = styled("div")({
alignItems: "center",
borderRadius: "5px",

"&:first-child": {
"&:nth-child(2)": {
marginLeft: "auto",
},
"&:hover": {
Expand Down
20 changes: 15 additions & 5 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -127,10 +127,9 @@ async function reloadConfig(noteId: string) {
const valid = ymlConfig !== null && (await board.loadConfig(ymlConfig));
if (valid) {
openBoard = board;
} else {
openBoard = undefined;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

wouldn't it be good to set openBoard as undefined in this case?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove the code to prevent the board from closing automatically and keep the current board working.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If it set to undefined, I am afraid the current board will not be working any more.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, I'll need more time to understand the code on my side then

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, after additional test, this part is ok

hideBoard();
}
// Do nothing if it is not valid.
// User could close the kanban by using the "x" button
}

// EVENT HANDLERS
Expand Down Expand Up @@ -220,6 +219,10 @@ async function handleKanbanMessage(msg: Action) {
case "load":
break;

case "close":
openBoard = undefined;
return hideBoard();

// Propagete action to the active board
default: {
if (!openBoard.isValid) break;
Expand Down Expand Up @@ -273,12 +276,19 @@ async function handleKanbanMessage(msg: Action) {
* the domain of the current board.
*/
async function handleNewlyOpenedNote(newNoteId: string) {

if (openBoard) {
if (openBoard.configNoteId === newNoteId) return;
if (await openBoard.isNoteIdOnBoard(newNoteId)) return;
else {
Copy link
Collaborator

@mhelleboid mhelleboid Jul 1, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this code was already there, but is this "else" useful?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes. Let's say you have opened Kanban A note , and then open another Kanban B note, the else code handle this condition and replace the the board to Kanban B. If no such code, you need to close the current board and then open the Kanban note B manually.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remark: The reloadConfig() replace the "openBoard" variable. That is why it looks a bit weird.

hideBoard();
openBoard = undefined;
const originalOpenBoard = openBoard;
await reloadConfig(newNoteId);
if (openBoard && openBoard.isValid && originalOpenBoard!==openBoard) {
// If user opened a new board, close and open again to refresh the content
hideBoard()
showBoard();
}
return;
}
}

Expand Down