Skip to content

Commit

Permalink
with refreshing page
Browse files Browse the repository at this point in the history
  • Loading branch information
BelousSofiya committed Oct 20, 2023
1 parent d678197 commit 0bb7e00
Showing 1 changed file with 3 additions and 10 deletions.
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
import { Link } from 'react-router-dom';
import { StarOutlined, StarFilled } from '@ant-design/icons';
import { useState, useEffect } from 'react';
// import { useState } from 'react';
import { useSWRConfig } from 'swr';
import useSWRMutation from 'swr/mutation';
// import useSWRImmutable from 'swr/immutable'
// import useSWR from 'swr';
import axios from 'axios';
import styles from './CompanyCard.module.css';

Expand All @@ -20,6 +17,7 @@ const CompanyCard = ({ companyData, isAuthorized }) => {
const [usersSavedList, setUsersSavedList] = useState([]);
const [star, setStar] = useState(false);
const [isSaved, setIsSaved] = useState(false);
const [searchPerformed, setSearchPerformed] = useState(false);

async function sendRequest(url, { arg: data }) {
return fetch(url, {
Expand All @@ -33,7 +31,6 @@ const CompanyCard = ({ companyData, isAuthorized }) => {
}

async function getRequest(url) {
// if (isAuthorized.isAuth) {
const data = await axios
.get(url, {
withCredentials: true,
Expand All @@ -51,17 +48,13 @@ const CompanyCard = ({ companyData, isAuthorized }) => {

setUsersSavedList(NewList);
if (usersSavedList.includes(companyData.id)) {
console.log(
companyData.id,
usersSavedList,
usersSavedList.includes(companyData.id)
);
setStar(filledStar);
setIsSaved(true);
} else {
setIsSaved(false);
setStar(outlinedStar);
}
setSearchPerformed(true);
}

const { trigger } = useSWRMutation(
Expand Down Expand Up @@ -104,7 +97,7 @@ const CompanyCard = ({ companyData, isAuthorized }) => {
console.error(error);
}
}
}, [companyData, isAuthorized, isSaved]);
}, [companyData, isAuthorized, isSaved, searchPerformed]);

return (
<div className={styles['company-card']}>
Expand Down

0 comments on commit 0bb7e00

Please sign in to comment.