Skip to content

Commit

Permalink
formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
Gupta-Anubhav12 committed Feb 12, 2023
1 parent 39588fc commit c1d4cbe
Show file tree
Hide file tree
Showing 9 changed files with 208 additions and 181 deletions.
2 changes: 0 additions & 2 deletions apiFunctions/generate.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
import Request from "../utils/request";



export interface ChatGeneration {
answer: string;
chat_history: any;
Expand Down
21 changes: 17 additions & 4 deletions components/Header.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,20 +27,33 @@ const Header = () => {
</p>
<div className="ml-2">
<Tooltip message={"Follow us on Twitter!"}>
<a href="https://twitter.com/ShriKrishna" target="_blank" rel="noreferrer">
<Image src="/icons8-twitter-96.png" alt="Twitter" width={20} height={20} />
<a
href="https://twitter.com/ShriKrishna"
target="_blank"
rel="noreferrer"
>
<Image
src="/icons8-twitter-96.png"
alt="Twitter"
width={20}
height={20}
/>
</a>
</Tooltip>
</div>
<div className="ml-1">
<Tooltip message={"Gita AI is open source. Come contribute."}>
<a href="https://github.com/gita" target="_blank" rel="noreferrer">
<Image src="/icons8-github-90.png" alt="Github" width={20} height={20} />
<Image
src="/icons8-github-90.png"
alt="Github"
width={20}
height={20}
/>
</a>
</Tooltip>
</div>
</div>

</header>
);
};
Expand Down
19 changes: 9 additions & 10 deletions components/Input/index.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import SupaAuthModal from '@/components/auth/SupaAuthModal'
import { useCookies } from 'react-cookie';
import SupaAuthModal from "@/components/auth/SupaAuthModal";
import { useCookies } from "react-cookie";

import React, { useState, SetStateAction, useEffect } from "react";
import SuggestionBox from "./SuggestionBox";
Expand Down Expand Up @@ -31,21 +31,20 @@ const Input = ({
const plausible = usePlausible();
const [loading, setLoading] = useState<boolean>(false);
const [chatHistory, setChatHistory] = useState<Array<string>>([]);
const [open,setOpen] = useState<boolean>(false);
const [cookies, setCookie, removeCookie] = useCookies(['Token']);
const [open, setOpen] = useState<boolean>(false);
const [cookies, setCookie, removeCookie] = useCookies(["Token"]);

useEffect(() => {
const token = cookies?.Token;
if (token) {
setOpen(false);
}
else{
} else {
setOpen(true);
}
}, [])
}, []);

const token = cookies?.Token;
console.log(token)
console.log(token);

const handleGenerate = async () => {
try {
Expand Down Expand Up @@ -161,7 +160,7 @@ const Input = ({
</div>
<SupaAuthModal open={open} setOpen={setOpen} />
</div>
)
}
);
};

export default Input;
20 changes: 11 additions & 9 deletions components/Tooltip.tsx
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
import React from 'react';
import React from "react";

interface TooltipProps {
message: string;
children: React.ReactNode;
message: string;
children: React.ReactNode;
}

export default function Tooltip({ message, children }: TooltipProps) {
return (
<div className="group relative flex">
{children}
<span className="absolute top-10 scale-0 transition-all rounded bg-gray-800 p-2 text-xs text-white group-hover:scale-100">{message}</span>
</div>
)
return (
<div className="group relative flex">
{children}
<span className="absolute top-10 scale-0 transition-all rounded bg-gray-800 p-2 text-xs text-white group-hover:scale-100">
{message}
</span>
</div>
);
}
181 changes: 96 additions & 85 deletions components/auth/SupaAuthModal.tsx
Original file line number Diff line number Diff line change
@@ -1,92 +1,103 @@
import { createClient } from '@supabase/supabase-js'
import { Auth, ThemeSupa } from '@supabase/auth-ui-react'
import { createClient } from "@supabase/supabase-js";
import { Auth, ThemeSupa } from "@supabase/auth-ui-react";

import { Fragment, SetStateAction, useState } from 'react'
import { Dialog, Transition } from '@headlessui/react'
import { CheckIcon } from '@heroicons/react/24/outline'
import { useCookies } from 'react-cookie';
import { Fragment, SetStateAction, useState } from "react";
import { Dialog, Transition } from "@headlessui/react";
import { CheckIcon } from "@heroicons/react/24/outline";
import { useCookies } from "react-cookie";

export default function AuthModal({
open,
setOpen,
}: {
open: boolean;
setOpen: React.Dispatch<SetStateAction<boolean>>;
}) {
const supabase = createClient(
process.env.NEXT_PUBLIC_SUPABASE_URL as string,
process.env.NEXT_PUBLIC_SUPABASE_ANON_KEY as string
);
const [cookies, setCookie, removeCookie] = useCookies(["Token"]);

supabase.auth.onAuthStateChange(async (event, session) => {
if (event === "SIGNED_IN") {
setCookie("Token", session?.access_token);
setOpen(false);
}
});

export default function AuthModal({ open, setOpen }: { open: boolean, setOpen: React.Dispatch<SetStateAction<boolean>> }) {
const supabase = createClient(process.env.NEXT_PUBLIC_SUPABASE_URL as string, process.env.NEXT_PUBLIC_SUPABASE_ANON_KEY as string)
const [cookies, setCookie, removeCookie] = useCookies(['Token']);
return (
<Transition.Root show={open} as={Fragment}>
<Dialog as="div" className="relative z-10" onClose={setOpen}>
<Transition.Child
as={Fragment}
enter="ease-out duration-300"
enterFrom="opacity-0"
enterTo="opacity-100"
leave="ease-in duration-200"
leaveFrom="opacity-100"
leaveTo="opacity-0"
>
<div className="fixed inset-0 bg-gray-500 bg-opacity-75 transition-opacity" />
</Transition.Child>

supabase.auth.onAuthStateChange(async (event,session) => {
if (event === 'SIGNED_IN') {
setCookie("Token", session?.access_token);
setOpen(false);
}
})

return (
<Transition.Root show={open} as={Fragment}>
<Dialog as="div" className="relative z-10" onClose={setOpen}>
<Transition.Child
as={Fragment}
enter="ease-out duration-300"
enterFrom="opacity-0"
enterTo="opacity-100"
leave="ease-in duration-200"
leaveFrom="opacity-100"
leaveTo="opacity-0"
>
<div className="fixed inset-0 bg-gray-500 bg-opacity-75 transition-opacity" />
</Transition.Child>

<div className="fixed inset-0 z-10 overflow-y-auto">
<div className="flex min-h-full items-end justify-center p-4 text-center sm:items-center sm:p-0">
<Transition.Child
as={Fragment}
enter="ease-out duration-300"
enterFrom="opacity-0 translate-y-4 sm:translate-y-0 sm:scale-95"
enterTo="opacity-100 translate-y-0 sm:scale-100"
leave="ease-in duration-200"
leaveFrom="opacity-100 translate-y-0 sm:scale-100"
leaveTo="opacity-0 translate-y-4 sm:translate-y-0 sm:scale-95"
>
<Dialog.Panel className="relative transform overflow-hidden rounded-lg bg-white px-4 pt-5 pb-4 text-left shadow-xl transition-all sm:my-8 sm:w-full sm:max-w-sm sm:p-6">
<div>
<div className="mx-auto flex h-12 w-12 items-center justify-center rounded-full bg-green-100">
<CheckIcon className="h-6 w-6 text-green-600" aria-hidden="true" />
</div>
<div className="mt-3 text-center sm:mt-5">
<Dialog.Title as="h3" className="text-lg font-medium leading-6 text-gray-900">
Login/Signup
</Dialog.Title>
<Auth
supabaseClient={supabase}
appearance={{
theme: ThemeSupa,
variables: {
default: {

colors: {
brand: '#F48B11',
brandAccent: 'darkred',
},
},
},
}}
providers={['google']}

/>
</div>
</div>
<div className="mt-5 sm:mt-6">
<button
type="button"
className="inline-flex w-full justify-center rounded-md border border-transparent bg-primary-500 px-4 py-2 text-base font-medium text-white shadow-sm hover:bg-indigo-700 focus:outline-none focus:ring-2 focus:ring-indigo-500 focus:ring-offset-2 sm:text-sm"
onClick={() => setOpen(false)}
>
Back
</button>
</div>
</Dialog.Panel>
</Transition.Child>
</div>
<div className="fixed inset-0 z-10 overflow-y-auto">
<div className="flex min-h-full items-end justify-center p-4 text-center sm:items-center sm:p-0">
<Transition.Child
as={Fragment}
enter="ease-out duration-300"
enterFrom="opacity-0 translate-y-4 sm:translate-y-0 sm:scale-95"
enterTo="opacity-100 translate-y-0 sm:scale-100"
leave="ease-in duration-200"
leaveFrom="opacity-100 translate-y-0 sm:scale-100"
leaveTo="opacity-0 translate-y-4 sm:translate-y-0 sm:scale-95"
>
<Dialog.Panel className="relative transform overflow-hidden rounded-lg bg-white px-4 pt-5 pb-4 text-left shadow-xl transition-all sm:my-8 sm:w-full sm:max-w-sm sm:p-6">
<div>
<div className="mx-auto flex h-12 w-12 items-center justify-center rounded-full bg-green-100">
<CheckIcon
className="h-6 w-6 text-green-600"
aria-hidden="true"
/>
</div>
<div className="mt-3 text-center sm:mt-5">
<Dialog.Title
as="h3"
className="text-lg font-medium leading-6 text-gray-900"
>
Login/Signup
</Dialog.Title>
<Auth
supabaseClient={supabase}
appearance={{
theme: ThemeSupa,
variables: {
default: {
colors: {
brand: "#F48B11",
brandAccent: "darkred",
},
},
},
}}
providers={["google"]}
/>
</div>
</div>
<div className="mt-5 sm:mt-6">
<button
type="button"
className="inline-flex w-full justify-center rounded-md border border-transparent bg-primary-500 px-4 py-2 text-base font-medium text-white shadow-sm hover:bg-indigo-700 focus:outline-none focus:ring-2 focus:ring-indigo-500 focus:ring-offset-2 sm:text-sm"
onClick={() => setOpen(false)}
>
Back
</button>
</div>
</Dialog>
</Transition.Root>
)
</Dialog.Panel>
</Transition.Child>
</div>
</div>
</Dialog>
</Transition.Root>
);
}
35 changes: 18 additions & 17 deletions pages/_app.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import '@/styles/globals.css'
import { createBrowserSupabaseClient } from '@supabase/auth-helpers-nextjs'
import { SessionContextProvider, Session } from '@supabase/auth-helpers-react'
import { useState } from 'react'
import { CookiesProvider } from 'react-cookie';
import "@/styles/globals.css";
import { createBrowserSupabaseClient } from "@supabase/auth-helpers-nextjs";
import { SessionContextProvider, Session } from "@supabase/auth-helpers-react";
import { useState } from "react";
import { CookiesProvider } from "react-cookie";
import "@/styles/globals.css";
import type { AppProps } from "next/app";
import PlausibleProvider from "next-plausible";
Expand All @@ -21,21 +21,22 @@ const GA_SCRIPT_TAG = `
});
`;


export default function App({ Component, pageProps }: AppProps<{
initialSession: Session
export default function App({
Component,
pageProps,
}: AppProps<{
initialSession: Session;
}>) {

const [supabaseClient] = useState(() => createBrowserSupabaseClient())
const [supabaseClient] = useState(() => createBrowserSupabaseClient());
return (
<PlausibleProvider domain="bhagavadgita.ai" trackOutboundLinks>
<CookiesProvider>
<SessionContextProvider
supabaseClient={supabaseClient}
initialSession={pageProps.initialSession}
>
<Component {...pageProps} />
</SessionContextProvider>
<CookiesProvider>
<SessionContextProvider
supabaseClient={supabaseClient}
initialSession={pageProps.initialSession}
>
<Component {...pageProps} />
</SessionContextProvider>
</CookiesProvider>
<Script
strategy="lazyOnload"
Expand Down
Loading

0 comments on commit c1d4cbe

Please sign in to comment.