|
|
@@ -11,9 +11,10 @@ import { setAreas } from "../../../features/areas/areasSlice";
|
|
|
import { Area } from "../../../services/product/type";
|
|
|
import { useNavigate } from "react-router";
|
|
|
import { useTranslation } from "react-i18next";
|
|
|
+import { getWithExpiry, setWithExpiry } from "@/src/logic/loigicUtils";
|
|
|
+import { get } from "http";
|
|
|
|
|
|
const HomeSearch = () => {
|
|
|
- const areas = useSelector((state: any) => state.areas.areas);
|
|
|
const dispatch = useDispatch();
|
|
|
const navigate = useNavigate();
|
|
|
const { t } = useTranslation();
|
|
|
@@ -21,6 +22,7 @@ const HomeSearch = () => {
|
|
|
const [isDropdownOpen, setIsDropdownOpen] = useState(false);
|
|
|
const dropdownRef = useRef<HTMLDivElement>(null);
|
|
|
const [areasList, setAreasList] = useState<Area[]>([]);
|
|
|
+ const areas = getWithExpiry<Area[] | []>("areas");
|
|
|
|
|
|
useEffect(() => {
|
|
|
if (!areas || areas.length === 0) getAreaMutation.mutate();
|
|
|
@@ -44,7 +46,8 @@ const HomeSearch = () => {
|
|
|
console.log("Get area response data:", data);
|
|
|
if (data && data.errorCode === "0") {
|
|
|
console.log("Get area successful");
|
|
|
- dispatch(setAreas(data.data as Area[]));
|
|
|
+ // dispatch(setAreas(data.data as Area[]));
|
|
|
+ setWithExpiry("areas", JSON.stringify(data.data));
|
|
|
setAreasList(data.data as Area[]);
|
|
|
} else {
|
|
|
console.error("Get area failed, no token received");
|