Skip to content

Commit

Permalink
replaced wimdow.location.reload with appropriate refecth in update app
Browse files Browse the repository at this point in the history
  • Loading branch information
sriharsh05 committed Dec 21, 2023
1 parent 153f971 commit 24ea76b
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 9 deletions.
9 changes: 7 additions & 2 deletions src/Components/Common/UpdatableApp.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ const APP_UPDATED_KEY = "app-updated";
interface UpdatableAppProps {
children: ReactNode;
silentlyAutoUpdate?: boolean;
onUpdateLocalStorage?: (() => void) | undefined;
}

export const checkForUpdate = async () => {
Expand Down Expand Up @@ -46,7 +47,11 @@ export const checkForUpdate = async () => {
}
};

const UpdatableApp = ({ children, silentlyAutoUpdate }: UpdatableAppProps) => {
const UpdatableApp = ({
children,
silentlyAutoUpdate,
onUpdateLocalStorage,
}: UpdatableAppProps) => {
const [newVersion, setNewVersion] = useState<string>();
const [appUpdated, setAppUpdated] = useState(false);

Expand Down Expand Up @@ -77,7 +82,7 @@ const UpdatableApp = ({ children, silentlyAutoUpdate }: UpdatableAppProps) => {
// A second of delay to appreciate the update animation.
const updateLocalStorageAndReload = () => {
localStorage.setItem(APP_UPDATED_KEY, "true");
window.location.reload();
onUpdateLocalStorage && onUpdateLocalStorage();
localStorage.setItem(APP_VERSION_KEY, newVersion);
};

Expand Down
23 changes: 16 additions & 7 deletions src/Components/Users/UserProfile.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -164,12 +164,18 @@ export default function UserProfile() {
},
});

const { data: skillsView, loading: isSkillsLoading } = useQuery(
routes.userListSkill,
{
pathParams: { username: authUser.username },
}
);
const {
data: skillsView,
refetch: skillsFetch,
loading: isSkillsLoading,
} = useQuery(routes.userListSkill, {
pathParams: { username: authUser.username },
});

const onUpdateLocalStorage = () => {
skillsFetch();
refetchUserData();
};

const validateForm = () => {
const errors = { ...initError };
Expand Down Expand Up @@ -776,7 +782,10 @@ export default function UserProfile() {
</div>
</div>
{updateStatus.isUpdateAvailable && (
<UpdatableApp silentlyAutoUpdate={false}>
<UpdatableApp
silentlyAutoUpdate={false}
onUpdateLocalStorage={onUpdateLocalStorage}
>
<ButtonV2 disabled={true}>
<div className="flex items-center gap-4">
<CareIcon className="care-l-exclamation text-2xl" />
Expand Down

0 comments on commit 24ea76b

Please sign in to comment.