@@ -28,7 +26,6 @@ const ListRepositories = ({ activeLink, limit, handleLoadingMore, fetchedData, u
))
}
diff --git a/src/components/PostGrid.tsx b/src/components/PostGrid.tsx
index 343d5dd2..0902a3ac 100644
--- a/src/components/PostGrid.tsx
+++ b/src/components/PostGrid.tsx
@@ -7,12 +7,12 @@ import useSupabaseAuth from "../hooks/useSupabaseAuth";
import Avatar from "./Avatar";
export declare interface PostGridProps {
- data: DbRecomendation;
+ data: DbRepo;
user?: User;
}
const PostGrid = ({ data, user }: PostGridProps): JSX.Element => {
- const { user_metadata: { sub: user_id } } = user! || { user_metadata: { sub: null } };
+ const { user_metadata: { sub: user_id } } = user!;
const {
id: repo_id,
votesRelation: [{ votesCount }],
diff --git a/src/components/PostList.tsx b/src/components/PostList.tsx
index 8ec44332..a59ab44b 100644
--- a/src/components/PostList.tsx
+++ b/src/components/PostList.tsx
@@ -1,21 +1,22 @@
-import { useState } from "react";
-import { User } from "@supabase/supabase-js";
-import handleVoteUpdateByRepo from "../lib/handleVoteUpdateByRepo";
+import { useEffect, useState } from "react";
import { FaArrowAltCircleUp, FaDotCircle, FaStar } from "react-icons/fa";
import humanizeNumber from "../lib/humanizeNumber";
import { getAvatarLink, getRepoLink } from "../lib/github";
-import useSupabaseAuth from "../hooks/useSupabaseAuth";
import StackedAvatar from "./StackedAvatar";
+import useVotedRepos from "../hooks/useVotedRepos";
+import { RiCheckboxCircleFill } from "react-icons/ri";
+import cx from "classnames";
export declare interface PostListProps {
- data: DbRecomendation;
- user?: User;
+ data: DbRepo;
}
-const PostList = ({ data, user }: PostListProps): JSX.Element => {
- const { user_metadata: { sub: user_id } } = user! || { user_metadata: { sub: null } };
+const PostList = ({ data }: PostListProps): JSX.Element => {
+ const { votedReposIds, checkVoted, voteHandler } = useVotedRepos();
+ const [isVoted, setIsVoted] = useState(false);
+
const {
- id: repo_id,
+ id,
votesRelation: [{ votesCount }],
name,
full_name,
@@ -25,14 +26,14 @@ const PostList = ({ data, user }: PostListProps): JSX.Element => {
contributions,
} = data;
- const [votes, updateVotesState] = useState(votesCount || 0);
- const { signIn } = useSupabaseAuth();
+ useEffect(() => {
+ setIsVoted(checkVoted(data.id));
+ }, [votedReposIds]);
- async function handleVoteUpdate (votes: number, repo_id: number) {
- const updatedVotes = await handleVoteUpdateByRepo(votes, repo_id, user_id);
+ const repo_id = parseInt(`${id}`);
+ const owner = full_name.replace(`/${String(name)}`, "").trim();
- updatedVotes > 0 && updateVotesState(updatedVotes);
- }
+ const [votes, setVotes] = useState(votesCount);
return (
@@ -46,7 +47,7 @@ const PostList = ({ data, user }: PostListProps): JSX.Element => {
>
@@ -96,12 +97,28 @@ const PostList = ({ data, user }: PostListProps): JSX.Element => {
diff --git a/src/components/PostsWrap.tsx b/src/components/PostsWrap.tsx
index c8f028b8..16dfc365 100644
--- a/src/components/PostsWrap.tsx
+++ b/src/components/PostsWrap.tsx
@@ -7,8 +7,8 @@ import HotRepositories from "./HotRepositories";
import ListRepositories from "./ListRepositories";
import SecondaryNav from "./SecondaryNav";
-interface PostWrapProps {
- textToSearch: string;
+export declare interface PostWrapProps {
+ textToSearch?: string;
}
const parseLimitValue = (limit: string | null): number => {
@@ -28,7 +28,7 @@ const parseLimitValue = (limit: string | null): number => {
const PostsWrap = ({ textToSearch }: PostWrapProps): JSX.Element => {
const [searchParams, setSearchParams] = useSearchParams();
- const [fetchedData, setFetchedData] = useState