Feature/homepage reordering (#4)

* Added changes for servers ordering

* fix spacing issue after new servers

* Fixed spacing issue between servers
pull/1060/head
Harish Vishwakarma 2024-11-14 08:29:11 +05:30 committed by Harish Vishwakarma
parent 7b3db4f251
commit 931a9a1799
2 changed files with 17 additions and 27 deletions

View File

@ -10,16 +10,7 @@
align-items: center; align-items: center;
height: 100%; height: 100%;
padding: 12px; padding: 12px;
padding-top: 64px;
h3 {
margin: 20px 0;
font-size: 48px;
text-align: center;
img {
height: 36px;
}
}
a { a {
font-size: 13px; font-size: 13px;
@ -54,4 +45,3 @@
[data-light="true"] .home svg { [data-light="true"] .home svg {
filter: invert(100%); filter: invert(100%);
} }

View File

@ -36,9 +36,10 @@ const Overlay = styled.div`
} }
`; `;
const DisabledButtonWrapper = styled.div` const DisabledWrapper = styled.div`
opacity: 0.5; opacity: 0.5;
pointer-events: none; pointer-events: none;
margin-bottom: -10px;
`; `;
interface Server { interface Server {
@ -47,14 +48,15 @@ interface Server {
description: string; description: string;
inviteCode: string; inviteCode: string;
disabled: boolean; disabled: boolean;
new: boolean; // Add the new field new: boolean;
sortorder: number;
} }
// Add a styled component for the new text color // Add a styled component for the new text color
const NewServerWrapper = styled.div` const NewServerWrapper = styled.div`
color: #fadf4f; color: #fadf4f;
display: contents;
// Preserve all other styles
a { a {
color: #fadf4f; color: #fadf4f;
} }
@ -108,13 +110,18 @@ const Home: React.FC = () => {
return; return;
} }
// Sort the servers by sortorder before caching
const sortedData = [...result.data].sort(
(a, b) => (a.sortorder || 0) - (b.sortorder || 0),
);
const cacheData: CachedData = { const cacheData: CachedData = {
timestamp: Date.now(), timestamp: Date.now(),
data: result.data, data: sortedData,
}; };
safeStorage.setItem(CACHE_KEY, JSON.stringify(cacheData)); safeStorage.setItem(CACHE_KEY, JSON.stringify(cacheData));
setServers(result.data); setServers(sortedData);
setLoading(false); setLoading(false);
}, },
error: (err) => { error: (err) => {
@ -167,7 +174,6 @@ const Home: React.FC = () => {
const buttonContent = ( const buttonContent = (
<CategoryButton <CategoryButton
key={server.id}
action={server.disabled ? undefined : "chevron"} action={server.disabled ? undefined : "chevron"}
icon={ icon={
server.disabled ? ( server.disabled ? (
@ -183,19 +189,14 @@ const Home: React.FC = () => {
</CategoryButton> </CategoryButton>
); );
const content = server.disabled ? ( let content = server.disabled ? (
<DisabledButtonWrapper key={server.id}> <DisabledWrapper>{buttonContent}</DisabledWrapper>
{buttonContent}
</DisabledButtonWrapper>
) : ( ) : (
<Link to={linkTo} key={server.id}> <Link to={linkTo}>{buttonContent}</Link>
{buttonContent}
</Link>
); );
// Wrap with NewServerWrapper if server is new
return server.new ? ( return server.new ? (
<NewServerWrapper key={server.id}>{content}</NewServerWrapper> <NewServerWrapper>{content}</NewServerWrapper>
) : ( ) : (
content content
); );
@ -217,7 +218,6 @@ const Home: React.FC = () => {
<Text id="app.navigation.tabs.home" /> <Text id="app.navigation.tabs.home" />
</PageHeader> </PageHeader>
<div className={styles.homeScreen}> <div className={styles.homeScreen}>
<h3>Welcome to PepChat</h3>
<div className={styles.actions}> <div className={styles.actions}>
{servers.map(renderServerButton)} {servers.map(renderServerButton)}
</div> </div>