Skip to content

Commit

Permalink
chore: Update highlights type, remove unused useEffect, vars
Browse files Browse the repository at this point in the history
  • Loading branch information
Anush008 committed Jun 3, 2023
1 parent b6f1dd0 commit b2ec143
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 20 deletions.
22 changes: 5 additions & 17 deletions src/pages/home.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,27 +18,22 @@ import { getHighlights } from "../utils/fetchOpenSaucedApiData";

import Help from "./help";
import { OPEN_SAUCED_INSIGHTS_DOMAIN } from "../constants";
interface Highlight {
highlight: string;
title: string;
name: string;
url: string;
login: string;
}

import type { Highlight } from "../ts/types";

const Home = () => {
const { user } = useAuth();
const { currentTabIsOpensaucedUser, checkedUser } = useOpensaucedUserCheck();
const [highlights, setHighlights] = useState<Highlight[]>([]);
const [currentPage, setCurrentPage] = useState(0);
const [currentName, setCurrentName] = useState<string>("");


useEffect(() => {
const fetchHighlights = async () => {
try {
const userHighlightsData = await getHighlights();

if (!userHighlightsData) {
return;
}
const highlights = userHighlightsData.data;

setHighlights(highlights);
Expand All @@ -58,13 +53,6 @@ const Home = () => {
setCurrentPage(prevPage => prevPage + 1);
};

useEffect(() => {
// Update the current name when the highlight changes
if (highlights[currentPage]?.login) {
setCurrentName(highlights[currentPage].login);
}
}, [highlights, currentPage]);

return (
<div className="p-4 bg-slate-800">
<div className="grid grid-cols-1 divide-y divide-white/40 divider-y-center-2 min-w-[320px] text-white">
Expand Down
30 changes: 30 additions & 0 deletions src/ts/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,33 @@ export interface IUserPR {
readonly changed_files: number;
readonly repo_id: number;
}

export interface Highlights {
data: Highlight[];
meta: HighlightsMeta;
}

export interface Highlight {
id: number;
user_id: number;
url: string;
title: string;
highlight: string;
pinned: boolean;
created_at: string;
updated_at: string;
deleted_at: string;
shipped_at: string;
full_name: string;
name: string;
login: string;
}

interface HighlightsMeta {
page: number;
limit: number;
itemCount: number;
pageCount: number;
hasPreviousPage: boolean;
hasNextPage: boolean;
}
13 changes: 10 additions & 3 deletions src/utils/fetchOpenSaucedApiData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {
OPEN_SAUCED_HIGHLIGHTS_ENDPOINT,
} from "../constants";
import { IInsight } from "../ts/InsightDto";
import { Highlights } from "../ts/types";

export const isOpenSaucedUser = async (username: string) => {
try {
Expand Down Expand Up @@ -178,12 +179,18 @@ export const updateInsight = async (userToken: string, repoId: string, checked:

return response.status === 200;
};
export const getHighlights = async () => {
const response = await fetch(
export const getHighlights = async (): Promise<Highlights | undefined> => {
const response = await cachedFetch(
`${OPEN_SAUCED_HIGHLIGHTS_ENDPOINT}`,
{ method: "GET" },
{
method: "GET",
expireInSeconds: 300,
},
);

if (!response) {
return;
}
return response.json();
};

Expand Down

0 comments on commit b2ec143

Please sign in to comment.