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

#305 Active tab highlighting #323

Merged
merged 10 commits into from
Nov 29, 2023
Merged
Show file tree
Hide file tree
Changes from 5 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
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ function MainInfoSection({ isAuthorized, data, containsNotRequiredData }) {
return (
<div className={classes['basic-info-content']}>
<TitleInfo isAuthorized={isAuthorized} data={data} />
{containsNotRequiredData ? <ProfileDetailNavBar /> : null}
{containsNotRequiredData ? <ProfileDetailNavBar data={data}/> : null}
</div>
);
}
Expand Down Expand Up @@ -35,6 +35,8 @@ MainInfoSection.propTypes = {
),
common_info: PropTypes.string,
is_saved: PropTypes.bool.isRequired,
is_registered: PropTypes.bool.isRequired,
is_startup: PropTypes.bool.isRequired,
}).isRequired,
containsNotRequiredData: PropTypes.bool.isRequired,
};
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import { HashLink } from 'react-router-hash-link';
import { useLocation } from 'react-router-dom';
import { useLocation, useNavigate } from 'react-router-dom';
import { useState, useEffect } from 'react';
import { PropTypes } from 'prop-types';
import classes from './ProfileDetailNavBar.module.css';

const MENU_LINKS = {
Expand All @@ -10,38 +12,65 @@ const MENU_LINKS = {
'cooperation': 'Формат співпраці',
};

function ProfileDetailNavBar() {

function ProfileDetailNavBar({ data }) {
const { hash } = useLocation ();
const navigate = useNavigate ();
const [activeLink, setActiveLink] = useState('');

useEffect(() => {
if (hash) {
setActiveLink(hash.substring(1));
} else {
setActiveLink(
data.is_registered && document.getElementById('about-company') ? 'about-company' :
data.is_startup && document.getElementById('startup') ? 'startup' : ''
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a very bad practice to rely on DOM. Do we need to use document.getElementById here and could we replace it?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I read about it. But I didn't find another solution.
Only tabs for components with provided information have to be shown. And I wanted to check if component is on the page using id of that component.
Maybe you can recommend some solution? What is better to use here?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Menu tabs functionality has been implemented with Context.

);
}
}, [hash, data.is_registered, data.is_startup]);

useEffect(() => {
navigate(hash.pathname, {replace: true});
}, [navigate, hash.pathname]);

return (
<div className={classes['navbar-menu']}>
{Object.entries(MENU_LINKS).map(([link, label]) => (
<div key={link} className={classes['navbar-menu__block']}>
<div className={classes['navbar-menu__item']}>
<HashLink
smooth
to={`#${link}`}
className={
`#${link}` === hash
? `${classes['active-link']}`
: `${classes['inactive-link']}`
}
>
{label}
</HashLink>
</div>
<div
className={
`#${link}` === hash
? `${classes['active-devider']}`
: `${classes['inactive-devider']}`
}
/>
</div>
))}
return (
<div>
<div className={classes['navbar-menu']}>
{Object.entries(MENU_LINKS).map(
([link, label]) =>
document.getElementById(link) && (
<div key={link} className={classes['navbar-menu__block']}>
<div className={classes['navbar-menu__item']}>
<HashLink
smooth
to={`#${link}`}
className={
link === activeLink
? `${classes['active-link']}`
: `${classes['inactive-link']}`
}
>
{label}
</HashLink>
</div>
<div
className={
link === activeLink ? `${classes['active-devider']}` : null
}
/>
</div>
)
)}
</div>
<div className={classes['devider']}></div>
</div>
);
}

export default ProfileDetailNavBar;

ProfileDetailNavBar.propTypes = {
data: PropTypes.shape({
is_registered: PropTypes.bool.isRequired,
is_startup: PropTypes.bool.isRequired,
}).isRequired,
};
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,12 @@
letter-spacing: -0.16px;
}

.devider {
width: 795px;
height: 1px;
background: var(--main-grey-20, #DEE1E8);
}

.inactive-devider {
height: 1px;
align-self: stretch;
Expand Down
8 changes: 7 additions & 1 deletion FrontEnd/src/components/profileList/ProfileCard.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,20 @@ import { PropTypes } from 'prop-types';
import { useSWRConfig } from 'swr';
import useSWRMutation from 'swr/mutation';

import { useUser } from '../../hooks';
import css from './ProfileCard.module.css';

const { Paragraph } = Typography;


export default function ProfileCard({ isAuthorized, data }) {
const { mutate } = useSWRConfig();
const { user } = useUser();
const [isSaved, setIsSaved] = useState(data.is_saved);
const profile = useMemo(() => {
return {
id: data.id,
personId: data.person,
name: data.name,
activities: !data.activities.length
? null
Expand All @@ -34,6 +37,8 @@ export default function ProfileCard({ isAuthorized, data }) {
};
}, [data]);

const ownProfile = user && user.id === profile.personId;

async function sendRequest(url, { arg: data }) {
const authToken = localStorage.getItem('Token');
return fetch(url, {
Expand Down Expand Up @@ -133,7 +138,7 @@ export default function ProfileCard({ isAuthorized, data }) {
</div>
</div>
</Link>
{isAuthorized ? (isSaved ? filledStar : outlinedStar) : null}
{isAuthorized && !ownProfile ? (isSaved ? filledStar : outlinedStar) : null}
</div>
);
}
Expand All @@ -142,6 +147,7 @@ ProfileCard.propTypes = {
isAuthorized: PropTypes.bool,
data: PropTypes.shape({
id: PropTypes.number.isRequired,
person: PropTypes.number.isRequired,
name: PropTypes.string.isRequired,
address: PropTypes.string,
region_display: PropTypes.string,
Expand Down
9 changes: 5 additions & 4 deletions FrontEnd/src/components/profileList/ProfileCard.module.css
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
.company-card {
display: flex;
width: 100%;
padding: 8px;
align-items: flex-start;
gap: 16px;
Expand Down Expand Up @@ -34,7 +35,7 @@
flex-direction: column;
align-items: flex-end;
border-radius: 100px;
border: 3px solid var(--secondary-white, #e2e5eb) ;
border: 3px solid var(--secondary-white, #e2e5eb);
background: var(--main-white, #fff);
}

Expand Down Expand Up @@ -65,7 +66,7 @@
display: flex;
align-items: center;
color: var(--main-grey-20, #767f86);
font-feature-settings: "calt"off;
font-feature-settings: "calt" off;

font-family: Inter, sans-serif;
font-size: 16px;
Expand Down Expand Up @@ -95,7 +96,7 @@
align-items: flex-start;
gap: 4px;
color: var(--main-grey-80, #292e32);
font-feature-settings: "calt"off;
font-feature-settings: "calt" off;

font-family: Inter, sans-serif;
font-size: 10px;
Expand All @@ -107,7 +108,7 @@
.content__common-info {
width: 1169px;
color: var(--main-grey-90, #25292c);
font-feature-settings: "calt"off;
font-feature-settings: "calt" off;

font-family: Inter;
font-size: 14px;
Expand Down
Loading