Skip to content

Commit

Permalink
fix: replace the useLocalStorage
Browse files Browse the repository at this point in the history
  • Loading branch information
JimmyLv committed Mar 11, 2023
1 parent 8ca9c06 commit 9853cf4
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 12 deletions.
2 changes: 1 addition & 1 deletion components/ActionsAfterResult.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import Image from "next/image";
import Link from "next/link";
import React from "react";
import { useLocalStorage } from "react-use";
import { useSaveToFlomo } from "~/hooks/notes/flomo";
import { useLocalStorage } from "~/hooks/useLocalStorage";

export function ActionsAfterResult({
curVideo,
Expand Down
2 changes: 1 addition & 1 deletion hooks/useLocalStorage.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React from 'react'

export function useLocalStorage<T>(key: string, initialValue: T) {
export function useLocalStorage<T>(key: string, initialValue?: T) {
// State to store our value
// Pass initial state function to useState so logic is only executed once
const [storedValue, setStoredValue] = React.useState<T>(() => {
Expand Down
7 changes: 2 additions & 5 deletions pages/[...slug].tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import type { NextPage } from "next";
import { useSearchParams } from "next/navigation";
import { useRouter } from "next/router";
import React, { useEffect, useState } from "react";
import { useLocalStorage } from "react-use";
import { useAnalytics } from "~/components/context/analytics";
import { SubmitButton } from "~/components/SubmitButton";
import { SummaryResult } from "~/components/SummaryResult";
Expand All @@ -17,6 +16,7 @@ import { VideoService } from "~/lib/types";
import { extractUrl } from "~/utils/extractUrl";
import { getVideoIdFromUrl } from "~/utils/getVideoIdFromUrl";
import getVideoId from "get-video-id";
import { useLocalStorage } from "~/hooks/useLocalStorage";

export const Home: NextPage<{
showSingIn: (show: boolean) => void;
Expand All @@ -31,7 +31,7 @@ export const Home: NextPage<{
const [currentVideoUrl, setCurrentVideoUrl] = useState<string>("");
const [shouldShowTimestamp, setShouldShowTimestamp] =
useLocalStorage<boolean>("should-show-timestamp");
const [userKey, setUserKey, remove] =
const [userKey, setUserKey] =
useLocalStorage<string>("user-openai-apikey");
const { loading, summary, resetSummary, summarize } =
useSummarize(showSingIn);
Expand Down Expand Up @@ -115,9 +115,6 @@ export const Home: NextPage<{
analytics.track("GenerateButton Clicked");
};
const handleApiKeyChange = (e: any) => {
if (!e.target.value) {
remove();
}
setUserKey(e.target.value);
};

Expand Down
7 changes: 2 additions & 5 deletions pages/user/integration.tsx
Original file line number Diff line number Diff line change
@@ -1,15 +1,12 @@
import React from "react";
import { useLocalStorage } from "react-use";
import { Sidebar } from "~/components/sidebar";
import { useLocalStorage } from "~/hooks/useLocalStorage";

export default () => {
const [flomoWebhook, setFlomoWebhook, remove] =
const [flomoWebhook, setFlomoWebhook] =
useLocalStorage<string>("user-flomo-webhook");

const handleFlomoWebhook = (e: any) => {
if (!e.target.value) {
remove();
}
setFlomoWebhook(e.target.value);
};

Expand Down

1 comment on commit 9853cf4

@vercel
Copy link

@vercel vercel bot commented on 9853cf4 Mar 11, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.