Fix flickering issue on the profile pages

pull/3671/head
Kamran Ahmed 1 year ago
parent f4635d794f
commit a3470cd844
  1. 17
      src/components/PageProgress.tsx
  2. 5
      src/components/Setting/UpdatePasswordForm.tsx
  3. 1
      src/components/Setting/UpdateProfileForm.tsx
  4. 13
      src/hooks/use-is-first-render.ts
  5. 4
      src/layouts/BaseLayout.astro
  6. 7
      src/pages/settings/update-password.astro
  7. 6
      src/pages/settings/update-profile.astro

@ -1,12 +1,23 @@
import { useStore } from '@nanostores/preact';
import { pageLoadingMessage } from '../stores/page';
import { useIsFirstRender } from '../hooks/use-is-first-render';
import SpinnerIcon from '../icons/spinner.svg';
import { pageLoadingMessage } from '../stores/page';
export interface Props {
initialMessage: string;
}
export function PageProgress() {
export function PageProgress(props: Props) {
const { initialMessage } = props;
const isFirstRender = useIsFirstRender();
const $pageLoadingMessage = useStore(pageLoadingMessage);
if (!$pageLoadingMessage) {
if (!initialMessage || !isFirstRender) {
return null;
}
}
return (
<div>
@ -19,7 +30,7 @@ export function PageProgress() {
className="h-4 w-4 animate-spin fill-blue-600 text-gray-200 sm:h-4 sm:w-4"
/>
<h1 className="ml-2">
{$pageLoadingMessage}
{$pageLoadingMessage || initialMessage}
<span className="animate-pulse">...</span>
</h1>
</div>

@ -1,6 +1,4 @@
import { useCallback, useEffect, useState } from 'preact/hooks';
import Cookies from 'js-cookie';
import { TOKEN_COOKIE_NAME } from '../../lib/jwt';
import { useEffect, useState } from 'preact/hooks';
import { httpGet, httpPost } from '../../lib/http';
import { pageLoadingMessage } from '../../stores/page';
@ -73,7 +71,6 @@ export default function UpdatePasswordForm() {
};
useEffect(() => {
pageLoadingMessage.set('Loading profile');
loadProfile().finally(() => {
pageLoadingMessage.set('');
});

@ -74,7 +74,6 @@ export function UpdateProfileForm() {
// Make a request to the backend to fill in the form with the current values
useEffect(() => {
pageLoadingMessage.set('Loading profile');
loadProfile().finally(() => {
pageLoadingMessage.set('');
});

@ -0,0 +1,13 @@
import { useRef } from "preact/hooks"
export function useIsFirstRender(): boolean {
const isFirst = useRef(true)
if (isFirst.current) {
isFirst.current = false
return true
}
return isFirst.current
}

@ -18,6 +18,7 @@ export interface Props {
keywords?: string[];
noIndex?: boolean;
canonicalUrl?: string;
initialLoadingMessage?: string;
permalink?: string;
jsonLd?: Record<string, unknown>[];
}
@ -32,6 +33,7 @@ const {
canonicalUrl: givenCanonical = '',
jsonLd = [],
redirectUrl = '',
initialLoadingMessage = '',
} = Astro.props;
// Remove trailing slashes to consider the page as canonical
@ -148,7 +150,7 @@ const gaPageIdentifier = Astro.url.pathname
</slot>
<Authenticator />
<PageProgress client:idle />
<PageProgress initialMessage={initialLoadingMessage} client:idle />
<PageSponsor
gaPageIdentifier={briefTitle || gaPageIdentifier}
client:load

@ -4,7 +4,12 @@ import UpdatePasswordForm from '../../components/Setting/UpdatePasswordForm';
import SettingLayout from '../../layouts/SettingLayout.astro';
---
<SettingLayout title='Change Password' description='' noIndex={true}>
<SettingLayout
title='Change Password'
description=''
noIndex={true}
initialLoadingMessage={'Loading profile'}
>
<SettingSidebar pageUrl='change-password' name='Change Password'>
<UpdatePasswordForm client:load />
</SettingSidebar>

@ -4,7 +4,11 @@ import { UpdateProfileForm } from '../../components/Setting/UpdateProfileForm';
import SettingLayout from '../../layouts/SettingLayout.astro';
---
<SettingLayout title='Update Profile' noIndex={true}>
<SettingLayout
title='Update Profile'
noIndex={true}
initialLoadingMessage={'Loading profile'}
>
<SettingSidebar pageUrl='profile' name='Profile'>
<UpdateProfileForm client:load />
</SettingSidebar>

Loading…
Cancel
Save