Commit 38f983db authored by Omar Luna Hernández's avatar Omar Luna Hernández
Browse files

Correcion de error de carga infinita

parent fc5f86f3
Loading
Loading
Loading
Loading
+10 −13
Original line number Diff line number Diff line
@@ -5,15 +5,14 @@ import { useGetStatesList } from "./useGetStatesList";
// Custom hook for managing town information in admin panel
export const useAdminTownInfo = (updateTown: () => void) => {
  const [isEnglish, setIsEnglish] = useState(false);
  const [isLoading, setIsLoading] = useState(true);
  const [renderCount, setRenderCount] = useState(0);
  const { getStates, statesList } = useGetStatesList();

  // Function to force re-render the list
  const forceRenderList = () => {
    updateTown();
    setRenderCount(prevCount => prevCount + 1);
  }
    setRenderCount((prevCount) => prevCount + 1);
  };

  // Fetch states on component mount
  useEffect(() => {
@@ -23,11 +22,9 @@ export const useAdminTownInfo = (updateTown: ()=>void) => {

  return {
    isEnglish,
    isLoading,
    setIsEnglish,
    setIsLoading,
    forceRenderList,
    renderCount,
    statesList,
  }
}
 No newline at end of file
  };
};
+7 −27
Original line number Diff line number Diff line
@@ -13,6 +13,7 @@ interface props {
  setIsWindowActive: Dispatch<SetStateAction<boolean>>;
  town: Town | undefined;
  updateTown: () => Promise<void>;
  isLoading: boolean;
}

// Main component function
@@ -21,17 +22,11 @@ export const AdminTownInfo = ({
  isWindowActive,
  setIsWindowActive,
  town,
  isLoading,
}: props) => {
  // Destructure values from the custom hook
  const {
    isEnglish,
    isLoading,
    setIsEnglish,
    setIsLoading,
    renderCount,
    forceRenderList,
    statesList,
  } = useAdminTownInfo(updateTown);
  const { isEnglish, setIsEnglish, renderCount, forceRenderList, statesList } =
    useAdminTownInfo(updateTown);

  // State to manage the visibility of the town register window
  const [isTownRegisterWindowActive, setIsTownRegisterWindowActive] =
@@ -59,6 +54,8 @@ export const AdminTownInfo = ({
    );
  }

  if (isLoading) return <LoadingScreen />;

  // Main render of the component
  return (
    <div className="town_info_root">
@@ -73,29 +70,12 @@ export const AdminTownInfo = ({
        />
      )}
      <div className="town_info_cnt" key={renderCount}>
        {isLoading && (
          <div
            style={{
              width: "100%",
              height: "100%",
              background: "#eaeaea",
              position: "fixed",
            }}
          >
            <LoadingScreen />
          </div>
        )}

        <div className="info_header">
          <p>{town?.name}</p>
        </div>
        <div className="info_body">
          <div className="town_image_cnt">
            <img
              src={town?.imageURL as string}
              onLoad={() => setIsLoading(false)}
              alt=""
            />
            <img src={town?.imageURL as string} alt="" />
          </div>
          <div className="info_fields_cnt">
            <div className="buttons_cnt">
+1 −0
Original line number Diff line number Diff line
@@ -114,6 +114,7 @@ export const AdminHomePage = () => {
                    setIsWindowActive={setIsWindowActive}
                    isWindowActive={isWindowActive}
                    town={town}
                    isLoading={isLoading}
                  />
                );
              case AdminSelectedPanel.PLACES:
+1 −1

File changed.

Contains only whitespace changes.