Skip to content

Commit

Permalink
Merge pull request #145 from Katyusha-Group/fix/timeline
Browse files Browse the repository at this point in the history
Fix/timeline
  • Loading branch information
er-ebrahimi authored Jan 28, 2024
2 parents 38923bd + 4287a47 commit 7f06cf8
Show file tree
Hide file tree
Showing 12 changed files with 181 additions and 124 deletions.
5 changes: 4 additions & 1 deletion src/assets/css/Timeline/Tweet.module.css
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,13 @@
margin-right: 10px;
margin-left: 10px;
border: 2px solid #32325d;
display: flex;
justify-content: center;
align-items: center;
}
.avatarimg{
width: 50px;
padding: 2px;
height: 50px;
border-radius: 50%;
object-fit: cover;
}
Expand Down
3 changes: 0 additions & 3 deletions src/assets/css/UserPage.module.css
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,6 @@ div {
border-width: 0.1875rem;
border-color: "red";
}
/* TODO */
.color {
width: 23%;
height: 5rem;
Expand Down Expand Up @@ -210,8 +209,6 @@ p {
justify-content: right;
padding-right: 5px;
}

/* TODO fix chart */
.cart {
width: 25px;
height: 25px;
Expand Down
1 change: 0 additions & 1 deletion src/components/Timeline/Reply.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import styles from "../../assets/css/Timeline/Reply.module.css";
import { useState } from "react";
import { Card } from "reactstrap";
import SendMessage from "../Tweet/SendMessage";
import { useTweets } from "../../hooks/Twitter/useTweets";
import { useParams } from "react-router-dom";
function Reply() {
const [activeTab, setActiveTab] = useState("tweets");
Expand Down
2 changes: 0 additions & 2 deletions src/components/Tweet/SendMessage.jsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import React, { useState } from "react";
import { Button, Input } from "reactstrap";
import styles from "../../assets/css/Tweet/SendMessage.module.css";
import { useSendTweets } from "../../hooks/Twitter/sendTweets";
import { useTweets } from "../../hooks/Twitter/useTweets";

export default function SendMessage({
fetchData = () => {},
Expand Down
36 changes: 22 additions & 14 deletions src/hooks/Twitter/useTweets.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,15 @@ import { apis } from "../../assets/apis";
import { useState } from "react";
import { useEffect } from "react";
import { returnToken } from "../../Functions/returnToken";
export const fetchData = (setLoading, setData, num, initial, info, setInfo) => {
const token = returnToken()
export const fetchData = async (
setLoading,
setData,
num,
initial,
info,
setInfo,
) => {
const token = returnToken();
setLoading(true);

let config = {
Expand All @@ -17,24 +24,25 @@ export const fetchData = (setLoading, setData, num, initial, info, setInfo) => {
Authorization: `Bearer ${token}`,
},
};
axios
.request(config)
.then((response) => {
setLoading(false);
setInfo(response.data)
setData((x) => {
if (!initial) return ({ ...x, results: [...x.results, ...response.data.results] });
return response.data;
});
try {
var response = await axios.request(config);
setLoading(false);
setInfo(response.data);
setData((x) => {
if (!initial)
return { ...x, results: [...x.results, ...response.data.results] };
return response.data;
})
.catch();
});
return response.data;
} catch (error) {
console.error("Error fetching data: ", error);
throw error;
}
};
export const useTweets = () => {
const [data, setData] = useState({ results: [] });
const [loading, setLoading] = useState(false);
const [info, setInfo] = useState(null);
// console.log("my tweeets",data.results)

useEffect(() => {
fetchData(setLoading, setData, 1, true, info, setInfo);
Expand Down
36 changes: 19 additions & 17 deletions src/hooks/Twitter/useTweetsForYou.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,38 +4,40 @@ import { apis } from "../../assets/apis";
import { useState } from "react";
import { useEffect } from "react";
import { returnToken } from "../../Functions/returnToken";
export const fetchData = (setLoading, setData, num, initial) => {
const token = returnToken()
export const fetchData = async (setLoading, setData, num, initial) => {
const token = returnToken();
setLoading(true);

let config = {
method: "get",
maxBodyLength: Infinity,
url: apis["forYouTwittes"]["forYouTwittes"],
url: apis["forYouTwittes"]["forYouTwittes"] + "?page=" + num,
headers: {
"Content-Type": "application/json",
Authorization: `Bearer ${token}`,
},
};
axios
.request(config)
.then((response) => {
setLoading(false);
setData((x) => {
if (!initial) return( {...x,results:[...x.results, ...response.data.results]});
return response.data;
});
try {
let response = await axios.request(config);
setLoading(false);
setData((x) => {
if (!initial)
return { ...x, results: [...x.results, ...response.data.results] };
return response.data;
})
.catch();
});
return response.data;
} catch (error) {
console.error("Error fetching data: ", error);
throw error;
}
};
export const useTweetsForYou = () => {
const [data, setData] = useState({results:[]});
const [data, setData] = useState({ results: [] });
const [loading, setLoading] = useState(false);
const [info, setInfo] = useState(null);
useEffect(() => {
fetchData(setLoading, setData, 1, true);
}, []);

return { data, setData, loading, setLoading};
};
return { data, setData, loading, setLoading };
};
10 changes: 6 additions & 4 deletions src/hooks/useProfileMe.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,10 @@ import { returnToken } from "../Functions/returnToken";
export const usesProfileMe = () => {
const [profile, setProfile] = useState(null);
const [loading, setLoading] = useState(true);
const { changeInfo } = useInfo();
const { info,changeInfo } = useInfo();
useEffect(() => {
const token = returnToken()

const fetchData = async () => {
try {

Expand All @@ -26,9 +27,10 @@ export const usesProfileMe = () => {
console.error(error);
}
};

fetchData();
if(info.userName !== ""){
fetchData();
}
}, []);

return { profile, setProfile, loading };

};
11 changes: 6 additions & 5 deletions src/hooks/useSearchprofile.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,17 @@ export const useAllProfiles = (searchQuery) => {
const [allProfiles, setAllProfiles] = useState([]);
const [filteredProfiles, setFilteredProfiles] = useState([]);
const [loading, setLoading] = useState(true);

useEffect(() => {
axios(apis["profiles"]["all"] + searchQuery, {
headers: { Authorization: `Bearer ${token}` },
})
.then((data) => {
setFilteredProfiles(data.data);
setLoading(false);
})
.then((data) => {
setFilteredProfiles(data.data);
setLoading(false);
})
.catch((error) => console.error("error"));
}, [searchQuery]);

return { filteredProfiles, loading };
};
Loading

0 comments on commit 7f06cf8

Please sign in to comment.