Skip to content

Commit

Permalink
Pass crdtMode properly
Browse files Browse the repository at this point in the history
  • Loading branch information
raimohanska committed Feb 25, 2024
1 parent 94801e3 commit 49d2a40
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 12 deletions.
3 changes: 0 additions & 3 deletions common/src/board-reducer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -147,9 +147,6 @@ export function boardReducer(
board.items,
(items) => {
event.items.forEach((item) => {
if (board.crdt && isTextItem(item)) {
item = { ...item, crdt: board.crdt }
}
if (
item.containerId &&
!findItem(board)(item.containerId) &&
Expand Down
4 changes: 4 additions & 0 deletions common/src/domain.ts
Original file line number Diff line number Diff line change
Expand Up @@ -405,6 +405,7 @@ export function newSimilarNote(note: Note) {
}

export function newText(
crdt: CrdtMode,
text: string = "HELLO",
x: number = 20,
y: number = 20,
Expand All @@ -423,10 +424,12 @@ export function newText(
z,
color: "none",
locked: false,
crdt,
}
}

export function newContainer(
crdt: CrdtMode,
x: number = 20,
y: number = 20,
width: number = 30,
Expand All @@ -444,6 +447,7 @@ export function newContainer(
z,
color: "white",
locked: false,
crdt,
}
}

Expand Down
4 changes: 2 additions & 2 deletions frontend/src/board/item-create.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ export function itemCreateHandler(
onAdd: (item: Item) => void,
) {
installKeyboardShortcut(plainKey("n"), () => onAdd(newSimilarNote(latestNote.get())))
installKeyboardShortcut(plainKey("a"), () => onAdd(newContainer()))
installKeyboardShortcut(plainKey("t"), () => onAdd(newText()))
installKeyboardShortcut(plainKey("a"), () => onAdd(newContainer(board.get().crdt)))
installKeyboardShortcut(plainKey("t"), () => onAdd(newText(board.get().crdt)))

installDoubleClickHandler((e) => {
shouldCreateOnDblClick(e) && onAdd(newSimilarNote(latestNote.get()))
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/board/item-cut-copy-paste.ts
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ export function cutCopyPasteHandler(
const currentCenter = coordinateHelper.currentBoardCoordinates.get()
let toCreate
if (sanitized.length > 50) {
toCreate = [newText(sanitized, currentCenter.x, currentCenter.y)]
toCreate = [newText(board.get().crdt, sanitized, currentCenter.x, currentCenter.y)]
} else {
toCreate = [newNote(sanitized, DEFAULT_NOTE_COLOR, currentCenter.x, currentCenter.y)]
}
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/board/toolbars/MainToolBar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ export const MainToolBar = ({
onTouchMove={onTouchMove}
onTouchStart={onTouchStart}
>
<PaletteView {...{ latestNote, addItem: onAdd, focus, tool: toolController.tool }} />
<PaletteView {...{ latestNote, addItem: onAdd, focus, tool: toolController.tool, board }} />
<ToolSelector {...{ toolController }} />
<DeleteIcon {...{ focus, dispatch, board }} />
<DuplicateIcon {...{ focus, dispatch, board, crdtStore: boardStore.crdtStore }} />
Expand Down
16 changes: 11 additions & 5 deletions frontend/src/board/toolbars/PaletteView.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { h, Fragment, HarmajaChild } from "harmaja"
import * as L from "lonna"
import { Item, newContainer, newSimilarNote, newText, Note } from "../../../../common/src/domain"
import { Board, Item, newContainer, newSimilarNote, newText, Note } from "../../../../common/src/domain"
import { BoardFocus } from "../board-focus"
import { Tool } from "../tool-selection"

Expand All @@ -9,17 +9,19 @@ export const PaletteView = ({
addItem,
focus,
tool,
board,
}: {
latestNote: L.Property<Note>
addItem: (item: Item) => void
focus: L.Atom<BoardFocus>
tool: L.Atom<Tool>
board: L.Property<Board>
}) => {
return (
<>
<NewNote {...{ addItem, latestNote, focus, tool }} />
<NewContainer {...{ addItem, focus, tool }} />
<NewText {...{ addItem, focus, tool }} />
<NewContainer {...{ addItem, focus, tool, board }} />
<NewText {...{ addItem, focus, tool, board }} />
</>
)
}
Expand All @@ -28,10 +30,12 @@ export const NewText = ({
addItem: onAdd,
focus,
tool,
board,
}: {
addItem: (i: Item) => void
focus: L.Atom<BoardFocus>
tool: L.Atom<Tool>
board: L.Property<Board>
}) => {
const svg = () => (
<svg viewBox="0 0 44 49" fill="none" xmlns="http://www.w3.org/2000/svg">
Expand All @@ -53,7 +57,7 @@ export const NewText = ({
tooltip="Drag to add new text area"
svg={svg}
focus={focus}
createItem={newText}
createItem={() => newText(board.get().crdt)}
addItem={onAdd}
tool={tool}
/>
Expand Down Expand Up @@ -116,10 +120,12 @@ export const NewContainer = ({
addItem: onAdd,
focus,
tool,
board,
}: {
addItem: (i: Item) => void
focus: L.Atom<BoardFocus>
tool: L.Atom<Tool>
board: L.Property<Board>
}) => {
const svg = () => (
<svg viewBox="0 0 44 49" fill="none" xmlns="http://www.w3.org/2000/svg">
Expand All @@ -142,7 +148,7 @@ export const NewContainer = ({
tooltip="Drag to add new area for organizing items"
svg={svg}
focus={focus}
createItem={newContainer}
createItem={() => newContainer(board.get().crdt)}
addItem={onAdd}
tool={tool}
/>
Expand Down

0 comments on commit 49d2a40

Please sign in to comment.