Skip to content

Commit

Permalink
fix: redirect to home page after posting a highlight (#203)
Browse files Browse the repository at this point in the history
* fix: redirect to home page after posting a highligh

* Added forceRefresh param to force cache invalidation

* chore: default val forceRefresh, typo

---------

Co-authored-by: Anush008 <[email protected]>
  • Loading branch information
marcusgchan and Anush008 authored Jul 20, 2023
1 parent 311f456 commit 4ebd2d1
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 5 deletions.
4 changes: 2 additions & 2 deletions src/popup/pages/home.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import type { Highlight } from "../../ts/types";
import { usGetGitHubPageInfo } from "../../hooks/useGetGitHubPageInfo";
import { HighlightSlide } from "../components/HighlightSlide";

const Home = () => {
const Home = ({ forceRefresh }: { forceRefresh: boolean } = { forceRefresh: false }) => {
const { user } = useAuth();
const { currentTabIsOpensaucedUser, checkedUser } = useOpensaucedUserCheck();
const { pageUrl, pageTitle, type: GitHubPageType } = usGetGitHubPageInfo();
Expand All @@ -37,7 +37,7 @@ const Home = () => {
useEffect(() => {
const fetchHighlights = async () => {
try {
const userHighlightsData = await getHighlights();
const userHighlightsData = await getHighlights(forceRefresh);

if (!userHighlightsData) {
return;
Expand Down
6 changes: 4 additions & 2 deletions src/popup/pages/posthighlight.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@ import OpenSaucedLogo from "../../assets/opensauced-logo.svg";
import { useAuth } from "../../hooks/useAuth";
import toast, { Toaster } from "react-hot-toast";
import { createHighlight } from "../../utils/fetchOpenSaucedApiData";
import { goBack } from "react-chrome-extension-router";
import { goBack, goTo } from "react-chrome-extension-router";
import { OPEN_SAUCED_INSIGHTS_DOMAIN } from "../../constants";
import { getAiDescription } from "../../content-scripts/components/GenerateAIDescription/DescriptionGeneratorButton";
import Home from "./home";

const PostOnHighlight = ({ prUrl, prTitle }: { prUrl: string, prTitle: string }) => {
const { authToken, user } = useAuth();
Expand Down Expand Up @@ -45,8 +46,9 @@ const PostOnHighlight = ({ prUrl, prTitle }: { prUrl: string, prTitle: string })
success: data => {
enableSendButton(true);
if (!data.ok) {
throw new Error(`Statues code ${data.status}`);
throw new Error(`Status code ${data.status}`);
}
goTo(Home, { forceRefresh: true });
return (
<span>
<a
Expand Down
3 changes: 2 additions & 1 deletion src/utils/fetchOpenSaucedApiData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -171,12 +171,13 @@ export const updateInsight = async (userToken: string, repoId: string, checked:

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

Expand Down

0 comments on commit 4ebd2d1

Please sign in to comment.