Feature: Node favourites (and ignores) (#618)
* Add favourite icon to node Avatar * Favourites WIP * Save isFavorite and isIgnored to device * Fix spelling * Clean up * Always sort favorites first * Add unread count to "Messages" top level menu * Renaming, UI tweaks * Add hook tests * Handle undefined node better
This commit is contained in:
@@ -0,0 +1,31 @@
|
||||
import { useCallback } from "react";
|
||||
import { useDevice } from "@core/stores/deviceStore.ts";
|
||||
import { useToast } from "@core/hooks/useToast.ts";
|
||||
|
||||
interface IgnoreNodeOptions {
|
||||
nodeNum: number;
|
||||
isIgnored: boolean;
|
||||
}
|
||||
|
||||
export function useIgnoreNode() {
|
||||
const { updateIgnored, getNode } = useDevice();
|
||||
const { toast } = useToast();
|
||||
|
||||
const updateIgnoredCB = useCallback(
|
||||
({ nodeNum, isIgnored }: IgnoreNodeOptions) => {
|
||||
const node = getNode(nodeNum);
|
||||
if (!node) return;
|
||||
|
||||
updateIgnored(nodeNum, isIgnored);
|
||||
|
||||
toast({
|
||||
title: `${isIgnored ? "Added" : "Removed"} ${
|
||||
node?.user?.longName ?? "node"
|
||||
} ${isIgnored ? "to" : "from"} ignore list`,
|
||||
});
|
||||
},
|
||||
[updateIgnored, getNode],
|
||||
);
|
||||
|
||||
return { updateIgnored: updateIgnoredCB };
|
||||
}
|
||||
Reference in New Issue
Block a user