diff --git a/src/components/RepoList.tsx b/src/components/RepoList.tsx
index 38f6833c..95956872 100644
--- a/src/components/RepoList.tsx
+++ b/src/components/RepoList.tsx
@@ -1,12 +1,10 @@
import { emojify } from "node-emoji";
-import { useEffect, useState } from "react";
-import { FaArrowAltCircleUp, FaDotCircle, FaStar } from "react-icons/fa";
+import { useEffect } from "react";
+import { FaDotCircle, FaStar } from "react-icons/fa";
import humanizeNumber from "../lib/humanizeNumber";
import { getAvatarLink, getRepoLink } from "../lib/github";
import StackedAvatar from "./StackedAvatar";
import useVotedRepos from "../hooks/useVotedRepos";
-import { RiCheckboxCircleFill } from "react-icons/ri";
-import cx from "classnames";
import useContributions from "../hooks/useContributions";
export declare interface RepoListProps {
@@ -14,9 +12,6 @@ export declare interface RepoListProps {
}
const RepoList = ({ data }: RepoListProps): JSX.Element => {
- const { votedReposIds, checkVoted, voteHandler } = useVotedRepos();
- const [isVoted, setIsVoted] = useState(false);
-
const {
id,
name,
@@ -31,11 +26,6 @@ const RepoList = ({ data }: RepoListProps): JSX.Element => {
// {full_name} consists of `{owner}/{repo}`, so this link is actually `repos/{owner}/{repo}/contributions`
const { data: contributions } = useContributions(full_name);
- useEffect(() => {
- setIsVoted(checkVoted(id));
- }, [votedReposIds]);
-
- const repo_id = parseInt(`${id}`);
const owner = full_name.replace(`/${String(name)}`, "").trim();
return (
diff --git a/src/components/VotedRepoListWrap.tsx b/src/components/VotedRepoListWrap.tsx
deleted file mode 100644
index d9127a85..00000000
--- a/src/components/VotedRepoListWrap.tsx
+++ /dev/null
@@ -1,50 +0,0 @@
-import { useLocation, useSearchParams } from "react-router-dom";
-import locationsHash from "../lib/locationsHash";
-import ListRepositories from "./ListRepositories";
-import { BsFillCalendar2Fill } from "react-icons/bs";
-
-export enum RepoOrderByEnum {
- popular = "stars",
- recent = "created_at",
- discussed = "issues",
-}
-
-const parseLimitValue = (limit: string | null): number => {
- if (!limit) {
- return 25;
- }
- const value = parseInt(limit);
-
- if (isNaN(value) || value <= 0) {
- return 15;
- }
- if (value > 25) {
- return 50;
- }
- return value;
-};
-
-const VotedRepoListWrap = (): JSX.Element => {
- const [searchParams, setSearchParams] = useSearchParams();
- const location = useLocation();
-
- const activeLink = (locationsHash[location.pathname] ?? "recent") as keyof typeof RepoOrderByEnum;
- const limit = parseLimitValue(searchParams.get("limit"));
- const pageNumber = parseInt(searchParams.get("pageNumber")!) || 1;
-
- const handleLoadingMore = () => {
- setSearchParams({ pageNumber: String(pageNumber + 1), limit: String(limit) });
- };
-
- return (
-
- );
-};
-
-export default VotedRepoListWrap;
diff --git a/src/hooks/useVotedRepos.ts b/src/hooks/useVotedRepos.ts
deleted file mode 100644
index a7b75889..00000000
--- a/src/hooks/useVotedRepos.ts
+++ /dev/null
@@ -1,58 +0,0 @@
-import { useCallback, useEffect, useState } from "react";
-import { User } from "@supabase/supabase-js";
-import useSupabaseAuth from "./useSupabaseAuth";
-import { fetchRecommendations } from "../lib/supabase";
-import handleVoteUpdateByRepo from "../lib/handleVoteUpdateByRepo";
-
-const useVotedRepos = () => {
- const [votedReposIds, setVotedReposIds] = useState([]);
- const { signIn, userAndTokens } = useSupabaseAuth();
-
- const fetchVotedData = useCallback(async (user?: User) => {
- try {
- if (user) {
- const data = await fetchRecommendations("myVotes", 1000, user, "");
-
- return setVotedReposIds(data.map(({ id }) => id));
- }
- } catch (e) {
- console.error(e);
- }
-
- setVotedReposIds([]);
- }, []);
-
- const checkVoted = (repo_id: number | string) =>
- votedReposIds.includes(parseInt(`${repo_id}`));
-
- const handleVoteUpdate = async (votes: number, repo_id: number) => {
- const voteCount = await handleVoteUpdateByRepo(votes, repo_id, userAndTokens?.user.user_metadata.sub);
-
- handleVoted(repo_id);
-
- return voteCount;
- };
-
- const handleVoted = (repo_id: number) => {
- const hasVoted = checkVoted(repo_id);
-
- if (hasVoted) {
- setVotedReposIds(votedReposIds.filter(id => id !== repo_id));
- } else {
- setVotedReposIds([...votedReposIds, repo_id]);
- }
- };
-
- useEffect(() => {
- fetchVotedData(userAndTokens?.user)
- .catch(console.error);
- }, [userAndTokens?.user]);
-
- return {
- votedReposIds,
- checkVoted,
- voteHandler: async (votes = 0, repo_id: number) => (userAndTokens ? handleVoteUpdate(votes, repo_id) : signIn({ provider: "github" })),
- };
-};
-
-export default useVotedRepos;
diff --git a/src/hooks/useVotedRepositoriesList.ts b/src/hooks/useVotedRepositoriesList.ts
deleted file mode 100644
index db1b4734..00000000
--- a/src/hooks/useVotedRepositoriesList.ts
+++ /dev/null
@@ -1,44 +0,0 @@
-import useSWR from "swr";
-import { supabase } from "../lib/supabase";
-
-interface PaginatedRepoResponse {
- readonly data: DbRepo[];
- readonly meta: PageMetaDto;
-}
-
-const apiFetcherWithToken = async (apiUrl: string) => {
- const authSession = supabase.auth.session();
-
- const authToken = authSession ? authSession.access_token : "";
- const response = await fetch(`${import.meta.env.VITE_API_URL}/${apiUrl}`, { headers: { accept: "application/json", Authorization: `Bearer ${authToken}` } });
-
- if (!response.ok) {
- const error = new Error("HttpError");
-
- error.message = `${response.status} ${response.statusText}`;
- error.stack = JSON.stringify(await response.json());
-
- throw error;
- }
-
- return response.json();
-};
-
-const useVotedRepositoriesList = (orderBy = "stars", limit = 10, pageNumber = 1) => {
- // setting this param as constant, to be avoid lint issue and to be handled in another ticket
- orderBy = "stars";
- const { data, error, mutate } = useSWR(
- `repos/listUserVoted?orderDirection=DESC&orderBy=${orderBy}&limit=${limit}&page=${pageNumber}`,
- apiFetcherWithToken,
- );
-
- return {
- data: data?.data ?? [],
- meta: data?.meta ?? { itemCount: 0, hasNextPage: false },
- isLoading: !error && !data,
- isError: !!error,
- mutate,
- };
-};
-
-export { useVotedRepositoriesList };
diff --git a/src/lib/handleVoteUpdateByRepo.ts b/src/lib/handleVoteUpdateByRepo.ts
deleted file mode 100644
index 35ab0517..00000000
--- a/src/lib/handleVoteUpdateByRepo.ts
+++ /dev/null
@@ -1,21 +0,0 @@
-import { capturePostHogAnayltics } from "./analytics";
-import { updateVotesByRepo } from "./supabase";
-import { ToastTrigger } from "./reactHotToast";
-
-// this function handles votes update across components
-async function handleVoteUpdateByRepo (votes: number, repo_id: number, user_id: unknown): Promise {
- const checkUserId = parseInt(String(user_id));
-
- if (checkUserId !== 0) {
- capturePostHogAnayltics("User voted", "voteClick", "true");
-
- const updatedVotes = await updateVotesByRepo(votes, repo_id, checkUserId);
-
- return updatedVotes;
- }
-
- ToastTrigger({ message: "You must be signed in to vote", type: "error" });
- return 0;
-}
-
-export default handleVoteUpdateByRepo;