-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
6456aa6
commit 41fb21c
Showing
4 changed files
with
187 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,65 @@ | ||
import Card from "~/components/Card/Card"; | ||
import clsx from "clsx"; | ||
import { useState } from "react"; | ||
import Card, { CardPropsTypes } from "~/components/Card/Card"; | ||
import { useSubmit } from "@remix-run/react"; | ||
|
||
type ColumnPropsTypes = { | ||
cards: CardPropsTypes[]; | ||
columnId: number; | ||
}; | ||
|
||
export default function Column({ cards, columnId }: ColumnPropsTypes) { | ||
const [isDraggedOver, setIsDraggedOver] = useState(false); | ||
const [hasDrop, setHasDrop] = useState(false); | ||
const submit = useSubmit(); | ||
|
||
const handleOnDrop = (e: React.DragEvent<HTMLDivElement>) => { | ||
// Needed to be a droppable zone | ||
e.preventDefault(); // Should add filtering to check if valid drop | ||
const cardId = e.dataTransfer.getData("application/hunters-card"); | ||
console.log("drop", { cardId, columnId }); | ||
submit({ cardId, columnId }, { method: "POST", navigate: false }); | ||
setIsDraggedOver(false); | ||
setHasDrop(true); | ||
setTimeout(() => { | ||
setHasDrop(false); | ||
}, 1000); | ||
}; | ||
|
||
const handleOnDragOver = (e: React.DragEvent<HTMLDivElement>) => { | ||
e.dataTransfer.setData("application/hunters-column", columnId.toString()); | ||
|
||
// Needed to be a droppable zone | ||
e.preventDefault(); // Should add filtering to check if valid drop | ||
setIsDraggedOver(true); | ||
}; | ||
|
||
const handleOnDragLeave = (e: React.DragEvent<HTMLDivElement>) => { | ||
e.dataTransfer.clearData("application/hunters-column"); | ||
setIsDraggedOver(false); | ||
}; | ||
|
||
const handleOnDragEnter = (e: React.DragEvent<HTMLDivElement>) => { | ||
e.dataTransfer.setData("application/hunters-column", columnId.toString()); | ||
console.log("drag enter"); | ||
}; | ||
|
||
export default function Column() { | ||
return ( | ||
<div | ||
className="border border-solid border-1 border-gray-700 rounded-md py-5 px-2" | ||
onDragOver={() => console.log("dragging over")} | ||
className={clsx( | ||
"border-1 min-h-48 rounded-md border border-solid border-gray-700 px-2 py-5", | ||
isDraggedOver ? "bg-sky-50" : "bg-slate-500", | ||
[hasDrop && "bg-red-400"], | ||
)} | ||
onDrop={handleOnDrop} | ||
onDragOver={handleOnDragOver} | ||
onDragLeave={handleOnDragLeave} | ||
onDragEnter={handleOnDragEnter} | ||
> | ||
<h1>This is a column</h1> | ||
<Card title="hello" content="world" /> | ||
{cards.map((card) => ( | ||
<Card key={card.id} {...card} /> | ||
))} | ||
</div> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import db from "~/db/db.server"; | ||
|
||
export async function getBoards() { | ||
const { rows } = await db.execute("SELECT * FROM queries"); | ||
return rows; | ||
} | ||
|
||
export type ColumnType = { id: number; name: string }; | ||
export type CardType = { id: number; name: string; columnId: number }; | ||
export async function getCardsAndColumns() { | ||
const { rows: column } = await db.execute({ | ||
sql: ` | ||
SELECT column.id, column.name FROM column | ||
LEFT JOIN board ON column.boardId = board.id | ||
WHERE board.id = ?; | ||
`, | ||
args: [1], | ||
}); | ||
|
||
const { rows: card } = await db.execute({ | ||
sql: ` | ||
SELECT card.id, card.name, card.columnId FROM card | ||
FULL JOIN column ON card.columnId = column.id | ||
FULL JOIN board ON column.boardId = board.id | ||
WHERE board.id = ?; | ||
`, | ||
args: [1], | ||
}); | ||
|
||
return { column, card } as unknown as { | ||
column: ColumnType[]; | ||
card: CardType[]; | ||
}; | ||
} | ||
|
||
export async function mutateCardColumn(cardId: number, columnId: number) { | ||
await db.execute({ | ||
sql: "UPDATE card SET columnId = ? WHERE id = ?;", | ||
args: [columnId, cardId], | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters