File size: 1,080 Bytes
eecbedf
 
1cf8f01
 
eecbedf
1cf8f01
 
 
 
eecbedf
 
 
 
 
 
1cf8f01
 
 
 
 
 
 
 
 
 
eecbedf
 
 
 
1cf8f01
 
 
 
 
eecbedf
 
1cf8f01
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
import { defaultHTML } from "@/lib/consts";
import { HtmlHistory, Page } from "@/types";
import { useState } from "react";

export const useEditor = (initialPages?: Page[], initialPrompts?: string[], initialHtmlStorage?: string) => {
  /**
   * State to manage the HTML content of the editor.
   * This will be the main content that users edit.
   */
  const [pages, setPages] = useState<Array<Page>>(initialPages ??[
    {
      path: "index.html",
      html: initialHtmlStorage ?? defaultHTML,
    },
  ]);
  /**
   * State to manage the history of HTML edits.
   * This will store previous versions of the HTML content along with metadata. (not saved to DB)
   */
  const [htmlHistory, setHtmlHistory] = useState<HtmlHistory[]>([]);

  /**
   * State to manage the prompts used for generating HTML content.
   * This can be used to track what prompts were used in the editor.
   */
  const [prompts, setPrompts] = useState<string[]>(
    initialPrompts ?? []
  );


  return {
    htmlHistory,
    setHtmlHistory,
    prompts,
    pages,
    setPages,
    setPrompts,
  };
};