fix various bugs related to app crashing

This commit is contained in:
Triston Armstrong 2024-03-27 22:39:42 -05:00
parent a8293784d2
commit 38346be965
5 changed files with 26 additions and 21 deletions

View File

@ -19,8 +19,8 @@ export function HomePage() {
const [showArchived, setShowArchived] = useState(false) const [showArchived, setShowArchived] = useState(false)
const [menuOpen, setMenuOpen] = useState(false) const [menuOpen, setMenuOpen] = useState(false)
const { boards, addBoard } = useGlobal() const { boards, addBoard } = useGlobal()
const activeBoards = boards.filter((b) => !b.archived) const activeBoards = boards?.filter((b) => !b.archived) ?? []
const archivedBoards = boards.filter((b) => b.archived) const archivedBoards = boards?.filter((b) => b.archived) ?? []
return ( return (
<main className="p-8"> <main className="p-8">
@ -77,7 +77,9 @@ export function HomePage() {
const data = await readFile(file) const data = await readFile(file)
console.log("IMPORT", data) console.log("IMPORT", data)
await JsonUtils.import(data) await JsonUtils.import(data)
window.location = "/" const newLoc = new Location()
newLoc.replace("/")
window.location = newLoc
}, },
}) })
input.click() input.click()

View File

@ -55,7 +55,9 @@ export function Board({ boardId }: { boardId: string }) {
(b) => String(b.id) === boardId || b.uuid === boardId (b) => String(b.id) === boardId || b.uuid === boardId
) )
if (!board) { if (!board) {
window.location = "/" const newLoc = new Location()
newLoc.replace("/")
window.location = newLoc
return return
} }
selectBoard(board) selectBoard(board)

View File

@ -227,10 +227,10 @@ function Item({ item, idx, listId }: ItemProps) {
const { const {
value: { tags, itemTags }, value: { tags, itemTags },
removeItemTag removeItemTag
} = useBoardTagsStore((state) => [ } = useBoardTagsStore((state) => ({
...state.tags, tags: state.tags,
...state.itemTags.filter((it) => it.itemId === item.id), itemTags: state.itemTags.filter((it) => it.itemId === item.id)
]) }))
const itemItemTags: Array<Tag | undefined> = useMemo(() => { const itemItemTags: Array<Tag | undefined> = useMemo(() => {
const tagsForThisItem = itemTags.filter((it) => it.itemId === item.id) const tagsForThisItem = itemTags.filter((it) => it.itemId === item.id)

View File

@ -10,18 +10,19 @@ import {
} from "../types" } from "../types"
import { addBoard as addBoardDb } from "../idb" import { addBoard as addBoardDb } from "../idb"
export const GlobalCtx = createContext<GlobalState>(null) export const GlobalCtx = createContext<GlobalState | null>(null)
export const GlobalDispatchCtx = export const GlobalDispatchCtx = createContext<
createContext<(action: GlobalDispatchAction) => void>(null) ((action: GlobalDispatchAction) => void) | null
>(null)
export function useGlobal() { export function useGlobal() {
const dispatch = useContext(GlobalDispatchCtx) const dispatch = useContext(GlobalDispatchCtx)
const setItemDragTarget = (payload: ItemDragTarget | null) => const setItemDragTarget = (payload: ItemDragTarget | null) =>
dispatch({ type: "SET_ITEM_DRAG_TARGET", payload }) dispatch?.({ type: "SET_ITEM_DRAG_TARGET", payload })
const setListDragTarget = (payload: ListDragTarget | null) => const setListDragTarget = (payload: ListDragTarget | null) =>
dispatch({ type: "SET_LIST_DRAG_TARGET", payload }) dispatch?.({ type: "SET_LIST_DRAG_TARGET", payload })
function handleListDrag(e: MouseEvent, clickedList: ClickedList) { function handleListDrag(e: MouseEvent, clickedList: ClickedList) {
if (!clickedList.mouseOffset) throw new Error("no mouseoffset") if (!clickedList.mouseOffset) throw new Error("no mouseoffset")
@ -48,7 +49,7 @@ export function useGlobal() {
const addBoard = async () => { const addBoard = async () => {
const newBoard = await addBoardDb() const newBoard = await addBoardDb()
dispatch({ type: "ADD_BOARD", payload: newBoard }) dispatch?.({ type: "ADD_BOARD", payload: newBoard })
} }
function handleItemDrag( function handleItemDrag(
@ -86,27 +87,27 @@ export function useGlobal() {
} }
function setBoardEditorOpen(value: boolean) { function setBoardEditorOpen(value: boolean) {
dispatch({ type: "SET_BOARD_EDITOR_OPEN", payload: value }) dispatch?.({ type: "SET_BOARD_EDITOR_OPEN", payload: value })
} }
return { return {
...useContext(GlobalCtx), ...useContext(GlobalCtx),
addBoard, addBoard,
setRootElement: (payload: HTMLDivElement) => setRootElement: (payload: HTMLDivElement) =>
dispatch({ type: "SET_ROOT_EL", payload }), dispatch?.({ type: "SET_ROOT_EL", payload }),
setBoardEditorOpen, setBoardEditorOpen,
setDragging: (dragging: boolean) => setDragging: (dragging: boolean) =>
dispatch({ type: "SET_DRAGGING", payload: { dragging } }), dispatch?.({ type: "SET_DRAGGING", payload: { dragging } }),
setClickedItem: (payload: ClickedItem | null) => setClickedItem: (payload: ClickedItem | null) =>
dispatch({ type: "SET_CLICKED_ITEM", payload }), dispatch?.({ type: "SET_CLICKED_ITEM", payload }),
setItemDragTarget, setItemDragTarget,
handleItemDrag, handleItemDrag,
setClickedList: (payload: ClickedList | null) => setClickedList: (payload: ClickedList | null) =>
dispatch({ type: "SET_CLICKED_LIST", payload }), dispatch?.({ type: "SET_CLICKED_LIST", payload }),
setListDragTarget, setListDragTarget,
handleListDrag, handleListDrag,
updateBoards: (payload: Board[]) => updateBoards: (payload: Board[]) =>
dispatch({ type: "SET_BOARDS", payload }), dispatch?.({ type: "SET_BOARDS", payload }),
} }
} }

View File

@ -6,5 +6,5 @@ type MouseContext = {
setValue: (payload: Vector2) => void setValue: (payload: Vector2) => void
} }
export const MouseCtx = createContext<MouseContext>(null) export const MouseCtx = createContext<MouseContext | null>(null)
export const useMouse = () => useContext(MouseCtx) export const useMouse = () => useContext(MouseCtx)