mirror of
https://github.com/zadam/trilium.git
synced 2025-10-20 23:29:02 +02:00
style(collections/board): better new item that creates only after enter
This commit is contained in:
parent
e99748e45f
commit
ede4b99bcd
@ -20,7 +20,7 @@ export default class BoardApi {
|
|||||||
private setBranchIdToEdit: (branchId: string | undefined) => void
|
private setBranchIdToEdit: (branchId: string | undefined) => void
|
||||||
) {};
|
) {};
|
||||||
|
|
||||||
async createNewItem(column: string) {
|
async createNewItem(column: string, title: string) {
|
||||||
try {
|
try {
|
||||||
// Get the parent note path
|
// Get the parent note path
|
||||||
const parentNotePath = this.parentNote.noteId;
|
const parentNotePath = this.parentNote.noteId;
|
||||||
@ -28,12 +28,11 @@ export default class BoardApi {
|
|||||||
// Create a new note as a child of the parent note
|
// Create a new note as a child of the parent note
|
||||||
const { note: newNote, branch: newBranch } = await note_create.createNote(parentNotePath, {
|
const { note: newNote, branch: newBranch } = await note_create.createNote(parentNotePath, {
|
||||||
activate: false,
|
activate: false,
|
||||||
title: "New item"
|
title
|
||||||
});
|
});
|
||||||
|
|
||||||
if (newNote && newBranch) {
|
if (newNote && newBranch) {
|
||||||
await this.changeColumn(newNote.noteId, column);
|
await this.changeColumn(newNote.noteId, column);
|
||||||
this.startEditing(newBranch?.branchId);
|
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error("Failed to create new item:", error);
|
console.error("Failed to create new item:", error);
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
import { useCallback, useContext, useEffect, useRef } from "preact/hooks";
|
import { useCallback, useContext, useEffect, useRef, useState } from "preact/hooks";
|
||||||
import FBranch from "../../../entities/fbranch";
|
import FBranch from "../../../entities/fbranch";
|
||||||
import FNote from "../../../entities/fnote";
|
import FNote from "../../../entities/fnote";
|
||||||
import { BoardViewContext, TitleEditor } from ".";
|
import { BoardViewContext, TitleEditor } from ".";
|
||||||
@ -117,14 +117,37 @@ export default function Column({
|
|||||||
<div className="board-drop-placeholder show" />
|
<div className="board-drop-placeholder show" />
|
||||||
)}
|
)}
|
||||||
|
|
||||||
<div className="board-new-item" onClick={() => api.createNewItem(column)}>
|
<AddNewItem api={api} column={column} />
|
||||||
<Icon icon="bx bx-plus" />{" "}
|
|
||||||
{t("board_view.new-item")}
|
|
||||||
</div>
|
|
||||||
</div>
|
</div>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function AddNewItem({ column, api }: { column: string, api: BoardApi }) {
|
||||||
|
const [ isCreatingNewItem, setIsCreatingNewItem ] = useState(false);
|
||||||
|
const addItemCallback = useCallback(() => setIsCreatingNewItem(true), []);
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div
|
||||||
|
className={`board-new-item ${isCreatingNewItem ? "editing" : ""}`}
|
||||||
|
onClick={addItemCallback}
|
||||||
|
>
|
||||||
|
{!isCreatingNewItem ? (
|
||||||
|
<>
|
||||||
|
<Icon icon="bx bx-plus" />{" "}
|
||||||
|
{t("board_view.new-item")}
|
||||||
|
</>
|
||||||
|
) : (
|
||||||
|
<TitleEditor
|
||||||
|
currentValue={t("board_view.new-item")}
|
||||||
|
save={(title) => api.createNewItem(column, title)}
|
||||||
|
dismiss={() => setIsCreatingNewItem(false)}
|
||||||
|
multiline isNewItem
|
||||||
|
/>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
function useDragging({ column, columnIndex, columnItems }: DragContext) {
|
function useDragging({ column, columnIndex, columnItems }: DragContext) {
|
||||||
const { api, draggedColumn, setDraggedColumn, setDropTarget, setDropPosition, draggedCard, dropPosition, setDraggedCard } = useContext(BoardViewContext);
|
const { api, draggedColumn, setDraggedColumn, setDropTarget, setDropPosition, draggedCard, dropPosition, setDraggedCard } = useContext(BoardViewContext);
|
||||||
|
|
||||||
|
@ -111,7 +111,8 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
.board-view-container .board-note {
|
.board-view-container .board-note,
|
||||||
|
.board-view-container .board-new-item.editing {
|
||||||
box-shadow: 1px 1px 4px rgba(0, 0, 0, 0.1);
|
box-shadow: 1px 1px 4px rgba(0, 0, 0, 0.1);
|
||||||
margin: 0.65em 0;
|
margin: 0.65em 0;
|
||||||
padding: var(--card-padding);
|
padding: var(--card-padding);
|
||||||
@ -120,7 +121,6 @@
|
|||||||
position: relative;
|
position: relative;
|
||||||
background-color: var(--main-background-color);
|
background-color: var(--main-background-color);
|
||||||
border: 1px solid var(--main-border-color);
|
border: 1px solid var(--main-border-color);
|
||||||
transition: transform 0.2s ease, box-shadow 0.2s ease, opacity 0.15s ease, margin-top 0.2s ease;
|
|
||||||
opacity: 1;
|
opacity: 1;
|
||||||
line-height: var(--card-line-height);
|
line-height: var(--card-line-height);
|
||||||
overflow-wrap: break-word;
|
overflow-wrap: break-word;
|
||||||
@ -128,6 +128,10 @@
|
|||||||
font-size: var(--card-font-size);
|
font-size: var(--card-font-size);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.board-view-container .board-note {
|
||||||
|
transition: transform 0.2s ease, box-shadow 0.2s ease, opacity 0.15s ease, margin-top 0.2s ease;
|
||||||
|
}
|
||||||
|
|
||||||
.board-view-container .board-note .icon {
|
.board-view-container .board-note .icon {
|
||||||
margin-right: 0.25em;
|
margin-right: 0.25em;
|
||||||
display: inline;
|
display: inline;
|
||||||
@ -179,16 +183,17 @@
|
|||||||
box-shadow: 4px 8px 16px rgba(0, 0, 0, 0.5);
|
box-shadow: 4px 8px 16px rgba(0, 0, 0, 0.5);
|
||||||
}
|
}
|
||||||
|
|
||||||
.board-view-container .board-note.editing {
|
.board-view-container .board-note.editing,
|
||||||
box-shadow: 2px 4px 8px rgba(0, 0, 0, 0.35);
|
.board-view-container .board-new-item.editing {
|
||||||
|
box-shadow: 2px 4px 8px rgba(0, 0, 0, 0.2);
|
||||||
border-color: var(--main-text-color);
|
border-color: var(--main-text-color);
|
||||||
display: flex;
|
display: flex;
|
||||||
align-items: center;
|
align-items: center;
|
||||||
padding: 0;
|
padding: 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
.board-view-container .board-note.editing input,
|
.board-view-container .board-note.editing textarea,
|
||||||
.board-view-container .board-note.editing textarea {
|
.board-view-container .board-new-item textarea.form-control {
|
||||||
background: transparent;
|
background: transparent;
|
||||||
border: none;
|
border: none;
|
||||||
outline: none;
|
outline: none;
|
||||||
|
@ -257,11 +257,12 @@ function AddNewColumn({ viewConfig, saveConfig }: { viewConfig?: BoardViewData,
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
export function TitleEditor({ currentValue, save, dismiss, multiline }: {
|
export function TitleEditor({ currentValue, save, dismiss, multiline, isNewItem }: {
|
||||||
currentValue: string,
|
currentValue: string,
|
||||||
save: (newValue: string) => void,
|
save: (newValue: string) => void,
|
||||||
dismiss: () => void,
|
dismiss: () => void,
|
||||||
multiline?: boolean
|
multiline?: boolean,
|
||||||
|
isNewItem?: boolean
|
||||||
}) {
|
}) {
|
||||||
const inputRef = useRef<any>(null);
|
const inputRef = useRef<any>(null);
|
||||||
|
|
||||||
@ -280,7 +281,7 @@ export function TitleEditor({ currentValue, save, dismiss, multiline }: {
|
|||||||
onKeyDown={(e) => {
|
onKeyDown={(e) => {
|
||||||
if (e.key === "Enter") {
|
if (e.key === "Enter") {
|
||||||
const newValue = e.currentTarget.value;
|
const newValue = e.currentTarget.value;
|
||||||
if (newValue !== currentValue) {
|
if (newValue !== currentValue || isNewItem) {
|
||||||
save(newValue);
|
save(newValue);
|
||||||
}
|
}
|
||||||
dismiss();
|
dismiss();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user