9 changed files with 191 additions and 81 deletions
@ -0,0 +1,30 @@ |
|||
import { useCallback } from "react"; |
|||
import { useDevice } from "@core/stores/deviceStore.ts"; |
|||
import { useToast } from "@core/hooks/useToast.ts"; |
|||
|
|||
interface UpdateFavoriteOptions { |
|||
nodeNum: number; |
|||
isFavorite: boolean; |
|||
} |
|||
|
|||
export function useUpdateFavorite() { |
|||
const { updateFavorite, getNode } = useDevice(); |
|||
const { toast } = useToast(); |
|||
|
|||
const updateFavoriteCB = useCallback( |
|||
({ nodeNum, isFavorite }: UpdateFavoriteOptions) => { |
|||
updateFavorite(nodeNum, isFavorite); |
|||
|
|||
const node = getNode(nodeNum); |
|||
|
|||
toast({ |
|||
title: `${isFavorite ? "Added" : "Removed"} ${ |
|||
node?.user?.longName ?? "node" |
|||
} ${isFavorite ? "to" : "from"} favorites`,
|
|||
}); |
|||
}, |
|||
[updateFavorite, getNode], |
|||
); |
|||
|
|||
return { updateFavorite: updateFavoriteCB }; |
|||
} |
|||
@ -0,0 +1,30 @@ |
|||
import { useCallback } from "react"; |
|||
import { useDevice } from "@core/stores/deviceStore.ts"; |
|||
import { useToast } from "@core/hooks/useToast.ts"; |
|||
|
|||
interface UpdateIgnoredOptions { |
|||
nodeNum: number; |
|||
isIgnored: boolean; |
|||
} |
|||
|
|||
export function useUpdateIgnored() { |
|||
const { updateIgnored, getNode } = useDevice(); |
|||
const { toast } = useToast(); |
|||
|
|||
const updateIgnoredCB = useCallback( |
|||
({ nodeNum, isIgnored }: UpdateIgnoredOptions) => { |
|||
updateIgnored(nodeNum, isIgnored); |
|||
|
|||
const node = getNode(nodeNum); |
|||
|
|||
toast({ |
|||
title: `${isIgnored ? "Added" : "Removed"} ${ |
|||
node?.user?.longName ?? "node" |
|||
} ${isIgnored ? "to" : "from"} ignore list`,
|
|||
}); |
|||
}, |
|||
[updateIgnored, getNode], |
|||
); |
|||
|
|||
return { updateIgnored: updateIgnoredCB }; |
|||
} |
|||
Loading…
Reference in new issue