File size: 3,046 Bytes
246d201
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
import React from "react";
import { useDispatch } from "react-redux";
import { useTranslation } from "react-i18next";
import posthog from "posthog-js";
import { I18nKey } from "#/i18n/declaration";
import { setImportedProjectZip } from "#/state/initial-query-slice";
import { convertZipToBase64 } from "#/utils/convert-zip-to-base64";
import { useGitHubUser } from "#/hooks/query/use-github-user";
import { useGitHubAuthUrl } from "#/hooks/use-github-auth-url";
import { useConfig } from "#/hooks/query/use-config";
import { useAuth } from "#/context/auth-context";
import { ImportProjectSuggestionBox } from "../../components/features/suggestions/import-project-suggestion-box";
import { GitHubRepositoriesSuggestionBox } from "#/components/features/github/github-repositories-suggestion-box";
import { HeroHeading } from "#/components/shared/hero-heading";
import { TaskForm } from "#/components/shared/task-form";

function Home() {
  const { t } = useTranslation();
  const { gitHubToken } = useAuth();
  const dispatch = useDispatch();
  const formRef = React.useRef<HTMLFormElement>(null);

  const { data: config } = useConfig();
  const { data: user } = useGitHubUser();

  const gitHubAuthUrl = useGitHubAuthUrl({
    gitHubToken,
    appMode: config?.APP_MODE || null,
    gitHubClientId: config?.GITHUB_CLIENT_ID || null,
  });

  const latestConversation = localStorage.getItem("latest_conversation_id");

  return (
    <div className="bg-root-secondary h-full rounded-xl flex flex-col items-center justify-center relative overflow-y-auto px-2">

      <HeroHeading />

      <div className="flex flex-col gap-8 w-full md:w-[600px] items-center">

        <div className="flex flex-col gap-2 w-full">

          <TaskForm ref={formRef} />

        </div>



        <div className="flex gap-4 w-full flex-col md:flex-row">

          <GitHubRepositoriesSuggestionBox

            handleSubmit={() => formRef.current?.requestSubmit()}

            gitHubAuthUrl={gitHubAuthUrl}

            user={user || null}

          />

          <ImportProjectSuggestionBox

            onChange={async (event) => {

              if (event.target.files) {

                const zip = event.target.files[0];

                dispatch(setImportedProjectZip(await convertZipToBase64(zip)));

                posthog.capture("zip_file_uploaded");

                formRef.current?.requestSubmit();

              } else {

                // TODO: handle error

              }

            }}

          />

        </div>

      </div>

      {latestConversation && (

        <div className="flex gap-4 w-full text-center mt-8">

          <p className="text-center w-full">

            {t(I18nKey.LANDING$OR)}&nbsp;

            <a

              className="underline"

              href={`/conversations/${latestConversation}`}

            >

              {t(I18nKey.LANDING$RECENT_CONVERSATION)}

            </a>

          </p>

        </div>

      )}

    </div>
  );
}

export default Home;