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

View File

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

View File

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

View File

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