Skip to content

Commit

Permalink
Merge pull request #12 from Dinujaya-Sandaruwan/build/beta (Bug Fix)
Browse files Browse the repository at this point in the history
Bugfix: Alignment of the post component
  • Loading branch information
Dinujaya-Sandaruwan committed Mar 8, 2024
2 parents 4ef8b3a + 66fd451 commit aadb9d4
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 30 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
"firebase": "^10.3.1",
"react": "^18.2.0",
"react-burger-menu": "^3.0.9",
"react-content-loader": "^6.2.1",
"react-dom": "^18.2.0",
"react-icons": "^4.10.1",
"react-infinite-scroll-component": "^6.1.0",
Expand Down
12 changes: 12 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

34 changes: 7 additions & 27 deletions src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ import useAuthStore from "./global/authStore";
import useDisplayForm from "./global/displayFormStore";
import { Posts } from "./interfaces/postFaces";
import { slide as Menu } from "react-burger-menu";
import InfiniteScroll from "react-infinite-scroll-component";

function App() {
const { displayForm } = useDisplayForm();
Expand All @@ -39,9 +38,7 @@ function App() {
const [lastPost, setLastPost] = useState<any>(null);
const [loading, setLoading] = useState<boolean>(false);
const [hasMore, setHasMore] = useState<boolean>(true);
const [showLoadButton, setShowLoadButton] = useState<boolean>(true);
const observer = useRef<IntersectionObserver | null>(null);
// const [isOpen, setIsOpen] = useState<boolean>(false);

const isAdmin = userId === import.meta.env.VITE_USER_ID;

Expand Down Expand Up @@ -133,21 +130,12 @@ function App() {
setLastPost(snapshot.docs[snapshot.docs.length - 1]);
} else {
setHasMore(false);
setShowLoadButton(false); // Hide the load more button when no more posts
}
setLoading(false);
}
};

const handleLoadMorePosts = () => {
fetchMorePosts();
};

const [isOpen, setIsOpen] = useState(false);
// const showSettings = (event) => {
// event.preventDefault();
// // Your logic here
// };

return (
<main>
Expand Down Expand Up @@ -184,21 +172,13 @@ function App() {
(post) => post.userId === userId && post.isApproved === false
)
.map((post, index) => <Post key={index} {...post} />)}
<InfiniteScroll
dataLength={posts.filter((post) => post.isApproved === true).length} //This is important field to render the next data
next={handleLoadMorePosts}
hasMore={true}
loader={showLoadButton ? <h4>Loading...</h4> : <h4></h4>}
// below props only if you need pull down functionality
refreshFunction={handleLoadMorePosts}
pullDownToRefresh
pullDownToRefreshThreshold={5}
>
{!isAdmin &&
posts
.filter((post) => post.isApproved === true)
.map((post, index) => <Post key={index} {...post} />)}
</InfiniteScroll>
{/* Render posts */}
{!isAdmin &&
posts
.filter((post) => post.isApproved === true)
.map((post, index) => <Post key={index} {...post} />)}
{/* Loader */}
{loading && <h4>Loading...</h4>}
</div>
<aside className="rightSide">
<Trending />
Expand Down
15 changes: 12 additions & 3 deletions src/components/Post.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ import { Menu, MenuItem, MenuButton } from "@szhsin/react-menu";
import "@szhsin/react-menu/dist/index.css";
import "@szhsin/react-menu/dist/transitions/slide.css";

import ContentLoader from "react-content-loader";

const Post = ({
userName,
userPhotoURL,
Expand Down Expand Up @@ -188,9 +190,15 @@ const Post = ({
width="100%"
/>
) : (
<div className="react-loading-skeleton">
<div className="test"></div>
</div>
<ContentLoader
speed={2}
height={0}
viewBox="0 0 200 200"
backgroundColor="#f3f3f3"
foregroundColor="#ecebeb"
>
<rect x="0" y="0" rx="5" ry="5" width="200" height="200" />
</ContentLoader>
)}

{postPhotoURL.length > 1 && (
Expand All @@ -211,6 +219,7 @@ const Post = ({
</div>
)}
</div>

<div className="postButtons">
<button
className="like"
Expand Down
15 changes: 15 additions & 0 deletions src/style/layout/_main.scss
Original file line number Diff line number Diff line change
Expand Up @@ -510,3 +510,18 @@
}
}
}

.infinite-scroll-component {
width: 100%;
display: flex;
flex-direction: column;
align-items: center;
margin-top: 20px;

& > * {
width: clamp(300px, 85%, 800px);
@media (width > 1700px) {
width: 800px;
}
}
}

0 comments on commit aadb9d4

Please sign in to comment.