瀏覽代碼

模式改变通知其他组件

visuddhinanda 2 年之前
父節點
當前提交
86b2384514
共有 1 個文件被更改,包括 25 次插入1 次删除
  1. 25 1
      dashboard/src/components/template/SentEdit/SentTabCopy.tsx

+ 25 - 1
dashboard/src/components/template/SentEdit/SentTabCopy.tsx

@@ -4,8 +4,12 @@ import {
   ShoppingCartOutlined,
   ShoppingCartOutlined,
   CheckOutlined,
   CheckOutlined,
 } from "@ant-design/icons";
 } from "@ant-design/icons";
-import { useState } from "react";
+import { useEffect, useState } from "react";
 import { IWbw } from "../Wbw/WbwWord";
 import { IWbw } from "../Wbw/WbwWord";
+import store from "../../../store";
+import { modeChange } from "../../../reducers/cart-mode";
+import { useAppSelector } from "../../../hooks";
+import { mode as _mode } from "../../../reducers/cart-mode";
 
 
 export interface ISentCart {
 export interface ISentCart {
   id: string;
   id: string;
@@ -18,6 +22,25 @@ interface IWidget {
 const SentTabCopyWidget = ({ text, wbwData }: IWidget) => {
 const SentTabCopyWidget = ({ text, wbwData }: IWidget) => {
   const [mode, setMode] = useState("copy");
   const [mode, setMode] = useState("copy");
   const [success, setSuccess] = useState(false);
   const [success, setSuccess] = useState(false);
+  const currMode = useAppSelector(_mode);
+
+  useEffect(() => {
+    const modeSetting = localStorage.getItem("cart/mode");
+    if (modeSetting === "cart") {
+      setMode("cart");
+    }
+  }, []);
+
+  useEffect(() => {
+    localStorage.setItem("cart/mode", mode);
+  }, [mode]);
+
+  useEffect(() => {
+    if (currMode) {
+      setMode(currMode);
+    }
+  }, [currMode]);
+
   const copy = (mode: string) => {
   const copy = (mode: string) => {
     if (text) {
     if (text) {
       if (mode === "copy") {
       if (mode === "copy") {
@@ -61,6 +84,7 @@ const SentTabCopyWidget = ({ text, wbwData }: IWidget) => {
         ],
         ],
         onClick: (e) => {
         onClick: (e) => {
           setMode(e.key);
           setMode(e.key);
+          store.dispatch(modeChange(e.key));
           copy(e.key);
           copy(e.key);
         },
         },
       }}
       }}