Persistent nodedb (#780)
* Refactor and consolitdate store imports - Created a new index file in the core stores directory to export all stores from a single module. - Updated imports to use consolidated store exports. * Remove unnecessary import * Update imports * First steps to persist nodeDB * Use named exports * Change store import after merge * Persistent nodeDB initial work * Key mishmatch warning, new serialization handler * Minor copilot changes * Add NODEDB_RETENTION_NUM * Updated tests * Refactor PKI mismatch logic * Clear persisted db on reset * Only persist on featureFlag * Mock featureFlag in tests --------- Co-authored-by: philon- <philon-@users.noreply.github.com>
This commit is contained in:
co-authored by
philon-
parent
e33463b371
commit
68ec7ee5d8
@@ -14,12 +14,19 @@ const mockNode = {
|
||||
const mockUpdateFavorite = vi.fn();
|
||||
const mockGetNode = vi.fn(() => mockNode);
|
||||
const mockToast = vi.fn();
|
||||
const mockSendAdminMessage = vi.fn();
|
||||
|
||||
vi.mock("@core/stores", () => ({
|
||||
useDevice: () => ({
|
||||
CurrentDeviceContext: {
|
||||
_currentValue: { deviceId: 1234 },
|
||||
},
|
||||
useNodeDB: () => ({
|
||||
updateFavorite: mockUpdateFavorite,
|
||||
getNode: mockGetNode,
|
||||
}),
|
||||
useDevice: () => ({
|
||||
sendAdminMessage: mockSendAdminMessage,
|
||||
}),
|
||||
}));
|
||||
|
||||
vi.mock("@core/hooks/useToast.ts", () => ({
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
import { create } from "@bufbuild/protobuf";
|
||||
import { useToast } from "@core/hooks/useToast.ts";
|
||||
import { useDevice } from "@core/stores";
|
||||
import { useDevice, useNodeDB } from "@core/stores";
|
||||
import { Protobuf } from "@meshtastic/core";
|
||||
import { useCallback } from "react";
|
||||
import { useTranslation } from "react-i18next";
|
||||
|
||||
@@ -9,7 +11,8 @@ interface FavoriteNodeOptions {
|
||||
}
|
||||
|
||||
export function useFavoriteNode() {
|
||||
const { updateFavorite, getNode } = useDevice();
|
||||
const { sendAdminMessage } = useDevice();
|
||||
const { getNode, updateFavorite } = useNodeDB();
|
||||
const { t } = useTranslation();
|
||||
const { toast } = useToast();
|
||||
|
||||
@@ -20,6 +23,16 @@ export function useFavoriteNode() {
|
||||
return;
|
||||
}
|
||||
|
||||
sendAdminMessage(
|
||||
create(Protobuf.Admin.AdminMessageSchema, {
|
||||
payloadVariant: {
|
||||
case: isFavorite ? "setFavoriteNode" : "removeFavoriteNode",
|
||||
value: nodeNum,
|
||||
},
|
||||
}),
|
||||
);
|
||||
|
||||
// TODO: Wait for response before changing the store
|
||||
updateFavorite(nodeNum, isFavorite);
|
||||
|
||||
toast({
|
||||
@@ -34,7 +47,7 @@ export function useFavoriteNode() {
|
||||
}),
|
||||
});
|
||||
},
|
||||
[updateFavorite, getNode, t, toast],
|
||||
[updateFavorite, sendAdminMessage, getNode, t, toast],
|
||||
);
|
||||
|
||||
return { updateFavorite: updateFavoriteCB };
|
||||
|
||||
@@ -14,12 +14,19 @@ const mockNode = {
|
||||
const mockUpdateIgnore = vi.fn();
|
||||
const mockGetNode = vi.fn(() => mockNode);
|
||||
const mockToast = vi.fn();
|
||||
const mockSendAdminMessage = vi.fn();
|
||||
|
||||
vi.mock("@core/stores", () => ({
|
||||
useDevice: () => ({
|
||||
updateIgnored: mockUpdateIgnore,
|
||||
CurrentDeviceContext: {
|
||||
_currentValue: { deviceId: 1234 },
|
||||
},
|
||||
useNodeDB: () => ({
|
||||
updateIgnore: mockUpdateIgnore,
|
||||
getNode: mockGetNode,
|
||||
}),
|
||||
useDevice: () => ({
|
||||
sendAdminMessage: mockSendAdminMessage,
|
||||
}),
|
||||
}));
|
||||
|
||||
vi.mock("@core/hooks/useToast.ts", () => ({
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
import { create } from "@bufbuild/protobuf";
|
||||
import { useToast } from "@core/hooks/useToast.ts";
|
||||
import { useDevice } from "@core/stores";
|
||||
import { useDevice, useNodeDB } from "@core/stores";
|
||||
import { Protobuf } from "@meshtastic/core";
|
||||
import { useCallback } from "react";
|
||||
import { useTranslation } from "react-i18next";
|
||||
|
||||
@@ -9,7 +11,9 @@ interface IgnoreNodeOptions {
|
||||
}
|
||||
|
||||
export function useIgnoreNode() {
|
||||
const { updateIgnored, getNode } = useDevice();
|
||||
const { sendAdminMessage } = useDevice();
|
||||
const { getNode, updateIgnore } = useNodeDB();
|
||||
|
||||
const { t } = useTranslation();
|
||||
|
||||
const { toast } = useToast();
|
||||
@@ -21,7 +25,17 @@ export function useIgnoreNode() {
|
||||
return;
|
||||
}
|
||||
|
||||
updateIgnored(nodeNum, isIgnored);
|
||||
sendAdminMessage(
|
||||
create(Protobuf.Admin.AdminMessageSchema, {
|
||||
payloadVariant: {
|
||||
case: isIgnored ? "setIgnoredNode" : "removeIgnoredNode",
|
||||
value: nodeNum,
|
||||
},
|
||||
}),
|
||||
);
|
||||
|
||||
// TODO: Wait for response before changing the store
|
||||
updateIgnore(nodeNum, isIgnored);
|
||||
|
||||
toast({
|
||||
title: t("toast.ignoreNode.title", {
|
||||
@@ -35,7 +49,7 @@ export function useIgnoreNode() {
|
||||
}),
|
||||
});
|
||||
},
|
||||
[updateIgnored, getNode, t, toast],
|
||||
[sendAdminMessage, updateIgnore, getNode, t, toast],
|
||||
);
|
||||
|
||||
return { updateIgnored: updateIgnoredCB };
|
||||
|
||||
Reference in New Issue
Block a user