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

731 saved comapnies updates UI #735

Merged
merged 11 commits into from
Aug 30, 2024
7 changes: 7 additions & 0 deletions FrontEnd/public/svg/bell-icon.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
17 changes: 17 additions & 0 deletions FrontEnd/src/components/MiniComponents/BellForUpdates.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import PropTypes from 'prop-types';
import styles from './BellForUpdates.module.css';

export default function BellForUpdates({ savedIsUpdated }){
return (
<img
src={`${process.env.PUBLIC_URL}/svg/bell-icon.svg`}
className={`${styles['bell']} ${!savedIsUpdated ? styles['hidden'] : ''}`}
alt="Bell Icon"
/>

);
}

BellForUpdates.propTypes={
savedIsUpdated: PropTypes.bool.isRequired,
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
.bell {
color: #ffd800;
font-size: 24px;
margin-right: 5px;
}

.bell.hidden {
visibility: hidden;
}
38 changes: 31 additions & 7 deletions FrontEnd/src/components/profileList/ProfileCard.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,11 @@ import css from './ProfileCard.module.css';
import axios from 'axios';
import CategoryBadges from '../MiniComponents/CategoryBadges';
import StarForLike from '../MiniComponents/StarForLike';
import BellForUpdates from '../MiniComponents/BellForUpdates';

const { Paragraph } = Typography;

export default function ProfileCard({ isAuthorized, data }) {
export default function ProfileCard({ isAuthorized, data, savedIsUpdated, onClearUpdate }) {
const { user } = useAuth();
const [isSaved, setIsSaved] = useState(data.is_saved);
const profile = useMemo(() => {
Expand All @@ -26,6 +27,7 @@ export default function ProfileCard({ isAuthorized, data }) {
region: data.regions_ukr_display ? data.regions_ukr_display : '',
categories: data.categories,
isSaved: data.is_saved,
savedIsUpdated: savedIsUpdated,
commonInfo: data.common_info,
logo: data.logo,
};
Expand All @@ -51,11 +53,26 @@ export default function ProfileCard({ isAuthorized, data }) {
}
};

const handleProfileViewed = async () => {
if (savedIsUpdated) {
onClearUpdate(false);
try {
await axios.patch(`${process.env.REACT_APP_BASE_API_URL}/api/saved-list/${profile.id}/`, {
is_updated: false
});
} catch (error) {
console.error(error);
onClearUpdate(true);
}
}
};

return (
<div className={css['company-card']}>
<Link
className={css['company-card__link']}
to={`/profile-detail/${profile.id}`}
onClick={handleProfileViewed}
>
<div className={css['logo-box']}>
<img
Expand Down Expand Up @@ -89,12 +106,17 @@ export default function ProfileCard({ isAuthorized, data }) {
</div>
</div>
</Link>
<StarForLike
isSaved={isSaved}
isAuthorized={isAuthorized}
ownProfile={ownProfile}
handleClick={isSaved ? handleDeleteSaved : handleSave}
></StarForLike>
<div className={css['bell-container']}>
<BellForUpdates
savedIsUpdated={savedIsUpdated}
Copy link
Collaborator

Choose a reason for hiding this comment

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

I'm wondering why we can't use data.saved_is_updated directly.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Fixed it

></BellForUpdates>
</div>
<StarForLike
isSaved={isSaved}
isAuthorized={isAuthorized}
ownProfile={ownProfile}
handleClick={isSaved ? handleDeleteSaved : handleSave}
></StarForLike>
</div>
);
}
Expand Down Expand Up @@ -126,4 +148,6 @@ ProfileCard.propTypes = {
uuid: PropTypes.string,
}),
}).isRequired,
savedIsUpdated: PropTypes.bool.isRequired,
onClearUpdate: PropTypes.func.isRequired,
};
10 changes: 9 additions & 1 deletion FrontEnd/src/components/profileList/ProfileCard.module.css
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@
}

.content__common-info {
width: 1169px;
width: 1150px;
Copy link
Collaborator

@popovycholeg popovycholeg Aug 23, 2024

Choose a reason for hiding this comment

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

Have you tested it with screens different than 1150?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Everything seems to work ok with this task on various resolutions, but this whole issue with hardcoded sizes in pixels will be fixed in future

color: var(--main-grey-90, #25292c);
font-feature-settings: "calt" off;

Expand All @@ -126,4 +126,12 @@
align-self: stretch;
max-width: 100%;
gap: 8px;
}

.bell-container {
display: flex;
justify-content: center;
align-items: center;
width: 30px;
height: 100%;
}
25 changes: 24 additions & 1 deletion FrontEnd/src/components/profileList/ProfileList.jsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { useState, useEffect } from 'react';
import { List } from 'antd';
import ProfileCard from './ProfileCard';
import css from './ProfileList.module.css';
Expand Down Expand Up @@ -27,6 +28,23 @@ export default function ProfileList({
data,
paginationFunc,
}) {
const [savedIsUpdatedMap, setSavedIsUpdatedMap] = useState({});

useEffect(() => {
const initialMap = data.results.reduce((acc, item) => {
acc[item.id] = item.saved_is_updated;
return acc;
}, {});
setSavedIsUpdatedMap(initialMap);
}, [data]);

const handleClearUpdate = (profileId, isUpdated) => {
setSavedIsUpdatedMap((prev) => ({
...prev,
[profileId]: isUpdated,
}));
};

return (
<List
pagination={{
Expand All @@ -45,7 +63,12 @@ export default function ProfileList({
split={false}
renderItem={(item) => (
<List.Item key={item.id}>
<ProfileCard isAuthorized={isAuthorized} data={item} />
<ProfileCard
isAuthorized={isAuthorized}
data={item}
savedIsUpdated={savedIsUpdatedMap[item.id]}
onClearUpdate={(isUpdated) => handleClearUpdate(item.id, isUpdated)}
/>
</List.Item>
)}
/>
Expand Down
Loading