Skip to content

Commit

Permalink
fix: Fix LCP of app (#30)
Browse files Browse the repository at this point in the history
* Issue-29: Fix LCP of app

Relates to #29
- It fixes accessibility
- Fixes LCP, performance increase from 50 to 70%

* Fix Text: follow -> share
  • Loading branch information
RaiVaibhav authored Apr 10, 2024
1 parent 81757f9 commit c02cb1c
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 21 deletions.
14 changes: 1 addition & 13 deletions app/components/Conversation.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -416,18 +416,6 @@ export default function Conversation(): JSX.Element {
}
}, [chatMessages]);

/**
* loading message (api key)
*/
if (!connection) {
return (
<div className="w-auto h-full items-center flex justify-center">
<Spinner size={"sm"} className="-mt-1 mr-2" />
Connecting...
</div>
);
}

return (
<>
<NextUIProvider className="h-full">
Expand All @@ -442,7 +430,7 @@ export default function Conversation(): JSX.Element {
>
<div className="grid grid-cols-12 overflow-x-auto gap-y-2">
{initialLoad ? (
<InitialLoad fn={startConversation} />
<InitialLoad fn={startConversation} connecting={!connection} />
) : (
<>
{chatMessages.length > 0 &&
Expand Down
17 changes: 13 additions & 4 deletions app/components/InitialLoad.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,15 @@ import { ExclamationIcon } from "./icons/ExclamationIcon";
import { Headphones } from "./Headphones";
import { isBrowser, isIOS } from "react-device-detect";
import Image from "next/image";
import { Spinner } from "@nextui-org/react";

export const InitialLoad = ({ fn }: { fn: () => void }) => {
export const InitialLoad = ({ fn, connecting = true }: { fn: () => void, connecting: boolean }) => {
return (
<>
<div className="col-start-1 col-end-13 sm:col-start-2 sm:col-end-12 md:col-start-3 md:col-end-11 lg:col-start-4 lg:col-end-10 p-3 mb-1/2">
<button
onClick={() => fn()}
disabled={connecting}
onClick={() => !connecting && fn()}
type="button"
className="relative block w-full glass p-6 sm:p-8 lg:p-12 rounded-xl"
>
Expand All @@ -25,8 +27,15 @@ export const InitialLoad = ({ fn }: { fn: () => void }) => {
</ul>
</div>
<span className="mt-4 block font-semibold">
<div className="bg-white text-black rounded px-10 py-3 font-semibold sm:w-fit sm:mx-auto">
{isBrowser ? "Click" : "Tap"} here to start
<div className="bg-white text-black rounded px-10 py-3 font-semibold sm:w-fit sm:mx-auto opacity-90">
{connecting ? (
<div className="w-auto h-full items-center flex justify-center opacity-40 cursor-not-allowed">
<Spinner size={"sm"} className="-mt-1 mr-2" />
Connecting...
</div>
) : (
<>{isBrowser ? "Click" : "Tap"} here to start</>
)}
</div>
</span>
<span className="mt-4 block text-sm text-gray-100/70">
Expand Down
2 changes: 1 addition & 1 deletion app/layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export const viewport: Viewport = {
themeColor: "#000000",
initialScale: 1,
width: "device-width",
maximumScale: 1,
// maximumScale: 1, hitting accessability
};

export const metadata: Metadata = {
Expand Down
9 changes: 6 additions & 3 deletions app/page.tsx
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
"use client";

import Conversation from "./components/Conversation";
import Image from "next/image";
import GitHubButton from "react-github-btn";

export const runtime = "edge";
import * as FullStory from "@fullstory/browser";
import { init } from "@fullstory/browser";
import { useEffect } from "react";
import { XIcon } from "./components/icons/XIcon";
import { FacebookIcon } from "./components/icons/FacebookIcon";
import { LinkedInIcon } from "./components/icons/LinkedInIcon";
import Conversation from "./components/Conversation";

export default function Home() {
useEffect(() => {
FullStory.init({ orgId: "5HWAN" });
init({ orgId: "5HWAN" });
}, []);

return (
Expand Down Expand Up @@ -80,6 +80,7 @@ export default function Home() {

return e.preventDefault();
}}
aria-label="share on twitter"
target="_blank"
>
<XIcon className="mb-1" />
Expand All @@ -95,6 +96,7 @@ export default function Home() {

return e.preventDefault();
}}
aria-label="share on Linkedin"
>
<LinkedInIcon className="mb-1" />
</a>
Expand All @@ -110,6 +112,7 @@ export default function Home() {
return e.preventDefault();
}}
target="_blank"
aria-label="share on Facebook"
>
<FacebookIcon className="mb-1" />
</a>
Expand Down

0 comments on commit c02cb1c

Please sign in to comment.