Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: 💡 optimize the initialization of website view #1446

Merged
merged 2 commits into from
Nov 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "src",
"version": "0.8.0+71.3.1",
"version": "0.8.0+73.2",
"private": true,
"scripts": {
"dev": "next dev",
Expand Down
16 changes: 13 additions & 3 deletions src/components/notification_item/notification_item.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, {useState, useContext} from 'react';
import React, {useState, useContext, useEffect} from 'react';
import Image from 'next/image';
import {NotificationContext} from '../../contexts/notification_context';
import {useGlobal} from '../../contexts/global_context';
Expand All @@ -18,6 +18,16 @@ export default function NotificationItem(notificationItem: INotificationItem) {
const globalCtx = useGlobal();

const [itemStyle, setItemStyle] = useState('h-160px translate-x-0 opacity-100');
const [displayedTime, setDisplayedTime] = useState<{date: string; time: string}>({
date: '',
time: '',
});

useEffect(() => {
const str = timestampToString(timestamp);

setDisplayedTime({date: str.date, time: str.time});
}, [notificationItem.timestamp]);

const messageType =
notificationLevel === NotificationLevel.CRITICAL
Expand Down Expand Up @@ -81,8 +91,8 @@ export default function NotificationItem(notificationItem: INotificationItem) {
</div>
{/* Info: (20231019 - Julian) Date */}
<div className="whitespace-nowrap text-end text-xs text-lightGray">
<p>{displayTime.date}</p>
<p>{displayTime.time}</p>
<p>{displayedTime.date}</p>
<p>{displayedTime.time}</p>
</div>
</div>
</div>
Expand Down
32 changes: 13 additions & 19 deletions src/pages/404.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,26 +26,20 @@ const Custom404 = () => {

const initUI = (
<>
{appCtx.isInit ? (
<>
<Head>
<title>Not Found - TideBit DeFi</title>
<link rel="icon" href={TIDEBIT_FAVICON} />
</Head>
<div>
{displayedNavBar}
<div className="relative flex min-h-600px flex-col items-center justify-center">
<Lottie animationData={notFoundAnimation} />
<div className="absolute bottom-1/3 text-center text-white">
{t('NOT_FOUND_PAGE.DESCRIPTION')}
</div>
</div>
<Footer />
<Head>
<title>Not Found - TideBit DeFi</title>
<link rel="icon" href={TIDEBIT_FAVICON} />
</Head>
<div>
{displayedNavBar}
<div className="relative flex min-h-600px flex-col items-center justify-center">
<Lottie animationData={notFoundAnimation} />
<div className="absolute bottom-1/3 text-center text-white">
{t('NOT_FOUND_PAGE.DESCRIPTION')}
</div>
</>
) : (
<div>Loading...</div>
)}
</div>
<Footer />
</div>
</>
);

Expand Down
34 changes: 14 additions & 20 deletions src/pages/500.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,28 +27,22 @@ const Custom500 = () => {

const initUI = (
<>
{appCtx.isInit ? (
<>
<Head>
<title>Error - TideBit DeFi</title>
<link rel="icon" href={TIDEBIT_FAVICON} />
</Head>
<div>
{displayedNavBar}
<div className="relative flex min-h-600px flex-col items-center justify-center">
<Lottie animationData={errorAnimation} />
<div className="absolute bottom-1/3 text-center text-white">
<div className="w-200px sm:w-auto sm:whitespace-nowrap">
{t('ERROR_PAGE.DESCRIPTION1')} {t('ERROR_PAGE.DESCRIPTION2')}
</div>
</div>
<Head>
<title>Error - TideBit DeFi</title>
<link rel="icon" href={TIDEBIT_FAVICON} />
</Head>
<div>
{displayedNavBar}
<div className="relative flex min-h-600px flex-col items-center justify-center">
<Lottie animationData={errorAnimation} />
<div className="absolute bottom-1/3 text-center text-white">
<div className="w-200px sm:w-auto sm:whitespace-nowrap">
{t('ERROR_PAGE.DESCRIPTION1')} {t('ERROR_PAGE.DESCRIPTION2')}
</div>
<Footer />
</div>
</>
) : (
<div>Loading...</div>
)}
</div>
<Footer />
</div>
</>
);

Expand Down
34 changes: 14 additions & 20 deletions src/pages/coming-soon.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,27 +27,21 @@ const ComingSoon = () => {

const initUI = (
<>
{appCtx.isInit ? (
<>
<Head>
<title>Coming Soon - TideBit DeFi</title>
<link rel="icon" href={TIDEBIT_FAVICON} />
</Head>
<div>
{displayedNavBar}
<div className="relative flex min-h-600px flex-col items-center justify-center">
<Lottie animationData={comingSoonAnimation} />
<div className="absolute bottom-1/3 text-center text-white">
<div>{t('COMING_SOON_PAGE.DESCRIPTION1')}</div>
<div>{t('COMING_SOON_PAGE.DESCRIPTION2')}</div>
</div>
</div>
<Footer />
<Head>
<title>Coming Soon - TideBit DeFi</title>
<link rel="icon" href={TIDEBIT_FAVICON} />
</Head>
<div>
{displayedNavBar}
<div className="relative flex min-h-600px flex-col items-center justify-center">
<Lottie animationData={comingSoonAnimation} />
<div className="absolute bottom-1/3 text-center text-white">
<div>{t('COMING_SOON_PAGE.DESCRIPTION1')}</div>
<div>{t('COMING_SOON_PAGE.DESCRIPTION2')}</div>
</div>
</>
) : (
<div>Loading...</div>
)}
</div>
<Footer />
</div>
</>
);

Expand Down
4 changes: 1 addition & 3 deletions src/pages/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ const Home = () => {
}
}, []);

return appCtx.isInit ? (
return (
<>
<Head>
<title>TideBit DeFi</title>
Expand All @@ -33,8 +33,6 @@ const Home = () => {

<Footer />
</>
) : (
<div>Loading...</div>
);
};

Expand Down
28 changes: 11 additions & 17 deletions src/pages/leaderboard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,26 +20,20 @@ const Leaderboard = () => {

const initUI = (
<>
{appCtx.isInit ? (
<>
<Head>
<title>Leaderboard - TideBit DeFi</title>
<link rel="icon" href={TIDEBIT_FAVICON} />
</Head>
<Head>
<title>Leaderboard - TideBit DeFi</title>
<link rel="icon" href={TIDEBIT_FAVICON} />
</Head>

<div>
{displayedNavBar}
<div>
{displayedNavBar}

<main>
<div>
<BoardPageBody />
</div>
</main>
<main>
<div>
<BoardPageBody />
</div>
</>
) : (
<div>Loading...</div>
)}
</main>
</div>
</>
);

Expand Down
28 changes: 11 additions & 17 deletions src/pages/my-assets.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,26 +20,20 @@ const MyAssets = () => {

const initUI = (
<>
{appCtx.isInit ? (
<>
<Head>
<title>My Assets - TideBit DeFi</title>
<link rel="icon" href={TIDEBIT_FAVICON} />
</Head>
<Head>
<title>My Assets - TideBit DeFi</title>
<link rel="icon" href={TIDEBIT_FAVICON} />
</Head>

<div>
{displayedNavBar}
<div>
{displayedNavBar}

<main>
<div>
<AssetsPageBody />
</div>
</main>
<main>
<div>
<AssetsPageBody />
</div>
</>
) : (
<div>Loading...</div>
)}
</main>
</div>
</>
);

Expand Down
28 changes: 11 additions & 17 deletions src/pages/news.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,25 +29,19 @@ const News = (props: IPageProps) => {

const initUI = (
<>
{appCtx.isInit ? (
<>
<Head>
<title>News - TideBit DeFi</title>
<link rel="icon" href="/favicon.ico" />
</Head>
<Head>
<title>News - TideBit DeFi</title>
<link rel="icon" href="/favicon.ico" />
</Head>

<nav className="">{displayedNavBar}</nav>
<main className="">
<div>
<NewsPageBody briefs={props.briefs} />
</div>
</main>
<nav className="">{displayedNavBar}</nav>
<main className="">
<div>
<NewsPageBody briefs={props.briefs} />
</div>
</main>

<Footer />
</>
) : (
<div>Loading...</div>
)}
<Footer />
</>
);

Expand Down
38 changes: 17 additions & 21 deletions src/pages/news/[newsId].tsx
Original file line number Diff line number Diff line change
Expand Up @@ -74,28 +74,24 @@ const NewsPage = (props: IPageProps) => {
<meta name="twitter:image:alt" content={newsTitle} />
</Head>

{appCtx.isInit ? (
<>
<nav className="">{displayedNavBar}</nav>
<main className="w-full">
<div className="w-full">
<NewsArticle
post={props.newsData}
shareId={props.newsId}
img={newsImg}
recommendations={props.brief}
/>
</div>
</main>

<div className="w-full mx-0">
{' '}
<Footer />
<>
<nav className="">{displayedNavBar}</nav>
<main className="w-full">
<div className="w-full">
<NewsArticle
post={props.newsData}
shareId={props.newsId}
img={newsImg}
recommendations={props.brief}
/>
</div>
</>
) : (
<div>Loading...</div>
)}
</main>

<div className="w-full mx-0">
{' '}
<Footer />
</div>
</>
</>
);

Expand Down
4 changes: 1 addition & 3 deletions src/pages/trade/cfd/[instId].tsx
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ const Trading = (props: IPageProps) => {
return <Error statusCode={404} />;
}

return appCtx.isInit ? (
return (
<>
<Head>
<title>CFD - TideBit DeFi</title>
Expand All @@ -73,8 +73,6 @@ const Trading = (props: IPageProps) => {
/>
</main>
</>
) : (
<div>Loading...</div>
);
};

Expand Down
Loading