fix: isEqual
This commit is contained in:
@@ -43,6 +43,7 @@
|
||||
"linkify-plugin-mention": "^3.0.4",
|
||||
"linkifyjs": "^3.0.5",
|
||||
"localforage": "^1.10.0",
|
||||
"lodash": "^4.17.21",
|
||||
"masonry-layout": "^4.2.2",
|
||||
"mini-css-extract-plugin": "^2.6.0",
|
||||
"pwa-badge": "^1.1.1",
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { useEffect, useState } from "react";
|
||||
import toast from "react-hot-toast";
|
||||
import { isObjectEqual } from "../utils";
|
||||
import { isEqual } from "lodash";
|
||||
import {
|
||||
useUpdateLoginConfigMutation,
|
||||
useUpdateSMTPConfigMutation,
|
||||
@@ -101,7 +101,7 @@ export default function useConfig(config = "smtp") {
|
||||
useEffect(() => {
|
||||
// 空对象
|
||||
if (Object.keys(values).length == 0) return;
|
||||
if (!isObjectEqual(originalValue, values)) {
|
||||
if (!isEqual(originalValue, values)) {
|
||||
setChanged(true);
|
||||
} else {
|
||||
setChanged(false);
|
||||
|
||||
@@ -11,25 +11,6 @@ export const isImage = (file_type = "", size = 0) => {
|
||||
return file_type.startsWith("image") && size <= FILE_IMAGE_SIZE;
|
||||
};
|
||||
|
||||
const deepSortObject = (obj) => {
|
||||
return Object.fromEntries(
|
||||
Object.entries(obj)
|
||||
.map((entry) => [
|
||||
entry[0],
|
||||
typeof entry[1] === "object" ? deepSortObject(entry[1]) : entry[1]
|
||||
])
|
||||
.sort()
|
||||
);
|
||||
};
|
||||
|
||||
export const isObjectEqual = (obj1, obj2) => {
|
||||
// Check for reference equal
|
||||
if (obj1 === obj2) return true;
|
||||
// Check for deep equal
|
||||
let o1 = JSON.stringify(deepSortObject(obj1 ?? {}));
|
||||
let o2 = JSON.stringify(deepSortObject(obj2 ?? {}));
|
||||
return o1 === o2;
|
||||
};
|
||||
export const isTreatAsImage = (file) => {
|
||||
let isImage = false;
|
||||
if (!file) return isImage;
|
||||
|
||||
Reference in New Issue
Block a user