Skip to content

Commit

Permalink
fix Pin
Browse files Browse the repository at this point in the history
  • Loading branch information
BOUDEFFAZAKARYA committed Oct 28, 2022
1 parent 4cc7758 commit b24d5b1
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 34 deletions.
1 change: 0 additions & 1 deletion src/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ const App = () => {
<BrowserRouter>
<Routes className='text-3xl font-bold underline'>
<Route path= "/*" element={user ? <Home userinfo={user}/> : <Login/>}/>
<Route path="/" element={ <Pin userinfo={user}/> } />


</Routes>
Expand Down
45 changes: 14 additions & 31 deletions src/components/Pin.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,42 +10,17 @@ import firebase from "firebase/compat/app";

import { PinsQuery } from '../utils/data';

const Pin = ({ userinfo }) => {
const [postHovered, setPostHoverYed] = useState(false);
const Pin = ({ pin }) => {
const [postHovered, setPostHovered] = useState(false);
const [savingPost, setSavingPost] = useState(false);
const [user, setUser] = useState();

const [pin, setPins] = useState();



const navigate = useNavigate();



useEffect(() => {
userinfo.providerData.forEach((user) => {
console.log('User info for provider: ', user);
const query = userQuery(user?.uid);

client.fetch(query).then((data) => {
setUser(data[0]);
})

})
const query = PinsQuery();

client.fetch(query).then((data) => {
setPins(data[0]);
})

const { image ,postedBy, _id, destination } = pin;

console.log("pin"+pin);





}), []
const user = localStorage.getItem('user') !== 'undefined' ? JSON.parse(localStorage.getItem('user')) : localStorage.clear();

const deletePin = (id) => {
client
Expand All @@ -55,7 +30,9 @@ const Pin = ({ userinfo }) => {
});
};

let alreadySaved = pin?.save?.filter((item) => item?.postedBy?._id === user?.googleId);

alreadySaved = alreadySaved?.length > 0 ? alreadySaved : [];

const savePin = (id) => {
if (alreadySaved?.length === 0) {
Expand All @@ -80,6 +57,11 @@ const Pin = ({ userinfo }) => {
}
};

useEffect(() =>{
console.log(image)

})

return (
<div className="m-2">
<div
Expand All @@ -88,7 +70,7 @@ const Pin = ({ userinfo }) => {
onClick={() => navigate(`/pin-detail/${_id}`)}
className=" relative cursor-zoom-in w-auto hover:shadow-lg rounded-lg overflow-hidden transition-all duration-500 ease-in-out"
>
{pin?.image && (
{image && (
<img className="rounded-lg w-full " src={(urlFor(image).width(250).url())} alt="user-post" /> )}
{postHovered && (
<div
Expand Down Expand Up @@ -155,6 +137,7 @@ const Pin = ({ userinfo }) => {
</div>
)}
</div>

<Link to={`/user-profile/${postedBy?._id}`} className="flex gap-2 mt-2 items-center">
<img
className="w-8 h-8 rounded-full object-cover"
Expand Down
2 changes: 1 addition & 1 deletion src/container/Home.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import UserProfile from '../components/UserProfile';

import Sidebar from '../components/Sidebar';

import { userQuery } from '../utils/data';
import { userQuery } from '../utils/data';
import { client } from '../client';
import Pins from './Pins';
import logo from '../assets/logo.png';
Expand Down
2 changes: 1 addition & 1 deletion src/container/Pins.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ const Pins = ({ user }) => {
<Routes>
<Route path="/" element={<Feed />} />
<Route path="/category/:categoryId" element={<Feed />} />
<Route element={<Pin user={user && user} />}/>
{/* <Route element={<Pin user={user && user} />}/> */}
<Route path="/pin-detail/:pinId" element={<PinDetail user={user && user} />} />
<Route path="/create-pin" element={<CreatePin user={user && user} />} />
<Route path="/search" element={<Search searchTerm={searchTerm} setSearchTerm={setSearchTerm} />} />
Expand Down

0 comments on commit b24d5b1

Please sign in to comment.