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

Fix profile list infinite requests issue #343

Merged
merged 16 commits into from
Dec 1, 2023
11 changes: 5 additions & 6 deletions FrontEnd/src/components/profileList/ProfileCard.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -61,16 +61,15 @@ export default function ProfileCard({ isAuthorized, data }) {
await trigger(
{ company_pk: profile.id },
{ optimisticData: () => setIsSaved(!isSaved) }
);
} catch (error) {
);
mutate((key) => typeof key === 'string' && key.startsWith('/api/profiles/'), {
revalidate: true,
});
} catch (error) {
console.error(error);
}
};

mutate((key) => typeof key === 'string' && key.startsWith('/api/profiles/'), {
revalidate: true,
});

const filledStar = (
<StarFilled
style={{ color: '#FFD800', fontSize: '24px' }}
Expand Down
17 changes: 9 additions & 8 deletions FrontEnd/src/components/profileList/ProfileListPage.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,18 +17,19 @@ export default function ProfileListPage({ isAuthorized }) {
const [currentPage, setCurrentPage] = useState(1);

const [profileFilter, setProfileFilter] = useState('');
const FILTER_MAP = {
companies: 'is_registered=True',
startups: 'is_startup=True',
producers: 'activities__name=Виробник',
importers: 'activities__name=Імпортер',
retailers: 'activities__name=Роздрібна мережа',
horeca: 'activities__name=HORECA'
};

useEffect(() => {
const FILTER_MAP = {
companies: 'is_registered=True',
startups: 'is_startup=True',
producers: 'activities__name=Виробник',
importers: 'activities__name=Імпортер',
retailers: 'activities__name=Роздрібна мережа',
horeca: 'activities__name=HORECA'
};
setProfileFilter(FILTER_MAP[filter]);
setFilterSaved(false);
setCurrentPage(1);
}, [filter]);

const urlForAll = `${process.env.REACT_APP_BASE_API_URL}/api/profiles/?${profileFilter}&page=${currentPage}`;
Expand Down
Loading