set in storage current html after clicking login button
Browse files
src/components/App.tsx
CHANGED
@@ -3,7 +3,13 @@ import { useRef, useState } from "react";
|
|
3 |
import Editor from "@monaco-editor/react";
|
4 |
import classNames from "classnames";
|
5 |
import { editor } from "monaco-editor";
|
6 |
-
import {
|
|
|
|
|
|
|
|
|
|
|
|
|
7 |
import { toast } from "react-toastify";
|
8 |
|
9 |
import Header from "./header/header";
|
@@ -21,6 +27,8 @@ const useBreakpoint = createBreakpoint({
|
|
21 |
|
22 |
function App() {
|
23 |
const breakpoint = useBreakpoint();
|
|
|
|
|
24 |
|
25 |
const preview = useRef<HTMLDivElement>(null);
|
26 |
const editor = useRef<HTMLDivElement>(null);
|
@@ -29,7 +37,7 @@ function App() {
|
|
29 |
|
30 |
const [isResizing, setIsResizing] = useState(false);
|
31 |
const [error, setError] = useState(false);
|
32 |
-
const [html, setHtml] = useState(defaultHTML);
|
33 |
const [isAiWorking, setisAiWorking] = useState(false);
|
34 |
const [auth, setAuth] = useState<Auth | undefined>(undefined);
|
35 |
|
@@ -72,6 +80,10 @@ function App() {
|
|
72 |
|
73 |
useMount(() => {
|
74 |
fetchMe();
|
|
|
|
|
|
|
|
|
75 |
if (!editor.current || !preview.current) return;
|
76 |
|
77 |
if (breakpoint === "lg") {
|
|
|
3 |
import Editor from "@monaco-editor/react";
|
4 |
import classNames from "classnames";
|
5 |
import { editor } from "monaco-editor";
|
6 |
+
import {
|
7 |
+
useMount,
|
8 |
+
useUnmount,
|
9 |
+
useEvent,
|
10 |
+
createBreakpoint,
|
11 |
+
useLocalStorage,
|
12 |
+
} from "react-use";
|
13 |
import { toast } from "react-toastify";
|
14 |
|
15 |
import Header from "./header/header";
|
|
|
27 |
|
28 |
function App() {
|
29 |
const breakpoint = useBreakpoint();
|
30 |
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
31 |
+
const [htmlStorage, _, removeHtmlStorage] = useLocalStorage("html_content");
|
32 |
|
33 |
const preview = useRef<HTMLDivElement>(null);
|
34 |
const editor = useRef<HTMLDivElement>(null);
|
|
|
37 |
|
38 |
const [isResizing, setIsResizing] = useState(false);
|
39 |
const [error, setError] = useState(false);
|
40 |
+
const [html, setHtml] = useState((htmlStorage as string) ?? defaultHTML);
|
41 |
const [isAiWorking, setisAiWorking] = useState(false);
|
42 |
const [auth, setAuth] = useState<Auth | undefined>(undefined);
|
43 |
|
|
|
80 |
|
81 |
useMount(() => {
|
82 |
fetchMe();
|
83 |
+
if (htmlStorage) {
|
84 |
+
removeHtmlStorage();
|
85 |
+
toast.warn("Previous HTML content restored from local storage.");
|
86 |
+
}
|
87 |
if (!editor.current || !preview.current) return;
|
88 |
|
89 |
if (breakpoint === "lg") {
|
src/components/ask-ai/ask-ai.tsx
CHANGED
@@ -137,7 +137,7 @@ function AskAI({
|
|
137 |
}
|
138 |
)}
|
139 |
>
|
140 |
-
<Login>
|
141 |
<p className="text-gray-500 text-sm mb-3">
|
142 |
You reached the limit of free AI usage. Please login to continue.
|
143 |
</p>
|
|
|
137 |
}
|
138 |
)}
|
139 |
>
|
140 |
+
<Login html={html}>
|
141 |
<p className="text-gray-500 text-sm mb-3">
|
142 |
You reached the limit of free AI usage. Please login to continue.
|
143 |
</p>
|
src/components/deploy-button/deploy-button.tsx
CHANGED
@@ -101,7 +101,7 @@ function DeployButton({
|
|
101 |
)}
|
102 |
>
|
103 |
{!auth ? (
|
104 |
-
<Login />
|
105 |
) : (
|
106 |
<>
|
107 |
<header className="flex items-center text-sm px-4 py-2 border-b border-gray-200 gap-2 bg-gray-100 font-semibold text-gray-700">
|
|
|
101 |
)}
|
102 |
>
|
103 |
{!auth ? (
|
104 |
+
<Login html={html} />
|
105 |
) : (
|
106 |
<>
|
107 |
<header className="flex items-center text-sm px-4 py-2 border-b border-gray-200 gap-2 bg-gray-100 font-semibold text-gray-700">
|
src/components/login/login.tsx
CHANGED
@@ -1,4 +1,23 @@
|
|
1 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2 |
return (
|
3 |
<>
|
4 |
<header className="flex items-center text-sm px-4 py-2 border-b border-gray-200 gap-2 bg-gray-100 font-semibold text-gray-700">
|
@@ -9,7 +28,7 @@ function Login({ children }: { children?: React.ReactNode }) {
|
|
9 |
</header>
|
10 |
<main className="px-4 py-4 space-y-3">
|
11 |
{children}
|
12 |
-
<a href="/api/login">
|
13 |
<img
|
14 |
src="https://huggingface.co/datasets/huggingface/badges/resolve/main/sign-in-with-huggingface-lg-dark.svg"
|
15 |
alt="Sign in with Hugging Face"
|
|
|
1 |
+
import { useLocalStorage } from "react-use";
|
2 |
+
import { defaultHTML } from "../../utils/consts";
|
3 |
+
|
4 |
+
function Login({
|
5 |
+
html,
|
6 |
+
children,
|
7 |
+
}: {
|
8 |
+
html?: string;
|
9 |
+
children?: React.ReactNode;
|
10 |
+
}) {
|
11 |
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
12 |
+
const [_, setStorage] = useLocalStorage("html_content");
|
13 |
+
|
14 |
+
const handleClick = () => {
|
15 |
+
if (html !== defaultHTML) {
|
16 |
+
setStorage(html);
|
17 |
+
}
|
18 |
+
console.log("store current HTML in local storage");
|
19 |
+
};
|
20 |
+
|
21 |
return (
|
22 |
<>
|
23 |
<header className="flex items-center text-sm px-4 py-2 border-b border-gray-200 gap-2 bg-gray-100 font-semibold text-gray-700">
|
|
|
28 |
</header>
|
29 |
<main className="px-4 py-4 space-y-3">
|
30 |
{children}
|
31 |
+
<a href="/api/login" onClick={handleClick}>
|
32 |
<img
|
33 |
src="https://huggingface.co/datasets/huggingface/badges/resolve/main/sign-in-with-huggingface-lg-dark.svg"
|
34 |
alt="Sign in with Hugging Face"
|