fix: isEqual

This commit is contained in:
Tristan Yang
2022-06-23 15:55:59 +08:00
parent 0f7072cc8c
commit 0310d764ac
3 changed files with 3 additions and 21 deletions
+1
View File
@@ -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",
+2 -2
View File
@@ -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);
-19
View File
@@ -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;