mirror of
https://github.com/kamranahmedse/developer-roadmap.git
synced 2025-09-02 13:52:46 +02:00
Fix flickering issue on the profile pages
This commit is contained in:
@@ -1,11 +1,22 @@
|
|||||||
import { useStore } from '@nanostores/preact';
|
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 SpinnerIcon from '../icons/spinner.svg';
|
||||||
|
import { pageLoadingMessage } from '../stores/page';
|
||||||
|
|
||||||
export function PageProgress() {
|
export interface Props {
|
||||||
|
initialMessage: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
export function PageProgress(props: Props) {
|
||||||
|
const { initialMessage } = props;
|
||||||
|
|
||||||
|
const isFirstRender = useIsFirstRender();
|
||||||
const $pageLoadingMessage = useStore(pageLoadingMessage);
|
const $pageLoadingMessage = useStore(pageLoadingMessage);
|
||||||
|
|
||||||
if (!$pageLoadingMessage) {
|
if (!$pageLoadingMessage) {
|
||||||
return null;
|
if (!initialMessage || !isFirstRender) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
@@ -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"
|
className="h-4 w-4 animate-spin fill-blue-600 text-gray-200 sm:h-4 sm:w-4"
|
||||||
/>
|
/>
|
||||||
<h1 className="ml-2">
|
<h1 className="ml-2">
|
||||||
{$pageLoadingMessage}
|
{$pageLoadingMessage || initialMessage}
|
||||||
<span className="animate-pulse">...</span>
|
<span className="animate-pulse">...</span>
|
||||||
</h1>
|
</h1>
|
||||||
</div>
|
</div>
|
||||||
|
@@ -1,6 +1,4 @@
|
|||||||
import { useCallback, useEffect, useState } from 'preact/hooks';
|
import { useEffect, useState } from 'preact/hooks';
|
||||||
import Cookies from 'js-cookie';
|
|
||||||
import { TOKEN_COOKIE_NAME } from '../../lib/jwt';
|
|
||||||
import { httpGet, httpPost } from '../../lib/http';
|
import { httpGet, httpPost } from '../../lib/http';
|
||||||
import { pageLoadingMessage } from '../../stores/page';
|
import { pageLoadingMessage } from '../../stores/page';
|
||||||
|
|
||||||
@@ -73,7 +71,6 @@ export default function UpdatePasswordForm() {
|
|||||||
};
|
};
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
pageLoadingMessage.set('Loading profile');
|
|
||||||
loadProfile().finally(() => {
|
loadProfile().finally(() => {
|
||||||
pageLoadingMessage.set('');
|
pageLoadingMessage.set('');
|
||||||
});
|
});
|
||||||
|
@@ -74,7 +74,6 @@ export function UpdateProfileForm() {
|
|||||||
|
|
||||||
// Make a request to the backend to fill in the form with the current values
|
// Make a request to the backend to fill in the form with the current values
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
pageLoadingMessage.set('Loading profile');
|
|
||||||
loadProfile().finally(() => {
|
loadProfile().finally(() => {
|
||||||
pageLoadingMessage.set('');
|
pageLoadingMessage.set('');
|
||||||
});
|
});
|
||||||
|
13
src/hooks/use-is-first-render.ts
Normal file
13
src/hooks/use-is-first-render.ts
Normal file
@@ -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[];
|
keywords?: string[];
|
||||||
noIndex?: boolean;
|
noIndex?: boolean;
|
||||||
canonicalUrl?: string;
|
canonicalUrl?: string;
|
||||||
|
initialLoadingMessage?: string;
|
||||||
permalink?: string;
|
permalink?: string;
|
||||||
jsonLd?: Record<string, unknown>[];
|
jsonLd?: Record<string, unknown>[];
|
||||||
}
|
}
|
||||||
@@ -32,6 +33,7 @@ const {
|
|||||||
canonicalUrl: givenCanonical = '',
|
canonicalUrl: givenCanonical = '',
|
||||||
jsonLd = [],
|
jsonLd = [],
|
||||||
redirectUrl = '',
|
redirectUrl = '',
|
||||||
|
initialLoadingMessage = '',
|
||||||
} = Astro.props;
|
} = Astro.props;
|
||||||
|
|
||||||
// Remove trailing slashes to consider the page as canonical
|
// Remove trailing slashes to consider the page as canonical
|
||||||
@@ -148,7 +150,7 @@ const gaPageIdentifier = Astro.url.pathname
|
|||||||
</slot>
|
</slot>
|
||||||
|
|
||||||
<Authenticator />
|
<Authenticator />
|
||||||
<PageProgress client:idle />
|
<PageProgress initialMessage={initialLoadingMessage} client:idle />
|
||||||
<PageSponsor
|
<PageSponsor
|
||||||
gaPageIdentifier={briefTitle || gaPageIdentifier}
|
gaPageIdentifier={briefTitle || gaPageIdentifier}
|
||||||
client:load
|
client:load
|
||||||
|
@@ -4,7 +4,12 @@ import UpdatePasswordForm from '../../components/Setting/UpdatePasswordForm';
|
|||||||
import SettingLayout from '../../layouts/SettingLayout.astro';
|
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'>
|
<SettingSidebar pageUrl='change-password' name='Change Password'>
|
||||||
<UpdatePasswordForm client:load />
|
<UpdatePasswordForm client:load />
|
||||||
</SettingSidebar>
|
</SettingSidebar>
|
||||||
|
@@ -4,7 +4,11 @@ import { UpdateProfileForm } from '../../components/Setting/UpdateProfileForm';
|
|||||||
import SettingLayout from '../../layouts/SettingLayout.astro';
|
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'>
|
<SettingSidebar pageUrl='profile' name='Profile'>
|
||||||
<UpdateProfileForm client:load />
|
<UpdateProfileForm client:load />
|
||||||
</SettingSidebar>
|
</SettingSidebar>
|
||||||
|
Reference in New Issue
Block a user