Skip to content

Commit fa87856

Browse files
authored
Merge pull request #18 from wajeshubham/dev
Code refactoring:
2 parents c3ae612 + dbfcd61 commit fa87856

File tree

12 files changed

+70
-33
lines changed

12 files changed

+70
-33
lines changed

components/Logo.tsx

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { clsx } from "@/utils";
22
import { CommandLineIcon } from "@heroicons/react/24/outline";
33
import React from "react";
44

5-
const isBeta = true;
5+
const isBeta = false;
66

77
const Logo: React.FC<{ size?: "xs" | "sm" | "xl" | "2xl" }> = ({
88
size = "xl",
@@ -47,14 +47,14 @@ const Logo: React.FC<{ size?: "xs" | "sm" | "xl" | "2xl" }> = ({
4747
<CommandLineIcon
4848
className={clsx("inset-0 mr-2", getIconClassesBySize() || "")}
4949
/>
50-
{isBeta ? (
51-
<span className="inline-flex items-center">
52-
Snippng
50+
<span className="inline-flex items-center">
51+
Snippng
52+
{isBeta ? (
5353
<span className="inline-flex items-center ml-1.5 rounded-sm dark:bg-indigo-600 bg-indigo-100 h-[15px] py-1.5 px-1 text-[10px] dark:text-indigo-100 text-indigo-600 border-[1px] border-indigo-600">
5454
Beta
5555
</span>
56-
</span>
57-
) : null}
56+
) : null}
57+
</span>
5858
</h1>
5959
);
6060
};

components/SigninButton.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ const SigninButton = () => {
1010
<>
1111
<Button data-testid="signin-btn" onClick={loginWithGoogle}>
1212
<GoogleIcon className="inline-flex mr-2" />
13-
Signin
13+
Sign in/up
1414
</Button>
1515
</>
1616
);

components/editor/SnippngCodeArea.tsx

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -242,14 +242,14 @@ const SnippngCodeArea = () => {
242242
{uid ? (
243243
<small className="dark:text-zinc-300 text-left text-zinc-600 py-2 inline-block">
244244
<InformationCircleIcon className="w-4 h-4 inline-block mr-1 mb-1" />{" "}
245-
<strong>Note:</strong> clicking{" "}
246-
<em>
247-
<strong>Fork snippet</strong>
248-
</em>{" "}
249-
button will create a copy of the current snippet in your profile
250-
with exact same configuration of{" "}
251-
<strong>theme, language, code and other settings</strong> that are
252-
visible to you right now
245+
<strong>Note:</strong> When you click the{" "}
246+
<strong>
247+
<em>Fork snippet</em>
248+
</strong>{" "}
249+
button, a copy of the current snippet will be created in your
250+
profile <strong>with the same settings</strong>. As a result, if
251+
you change something and then forked, the snippet will include the
252+
changes you made.
253253
</small>
254254
) : null}
255255
</NoSSRWrapper>

components/editor/SnippngControlHeader.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import {
1414
SparklesIcon,
1515
} from "@heroicons/react/24/outline";
1616
import * as htmlToImage from "html-to-image";
17-
import { Fragment, useState } from "react";
17+
import { Fragment } from "react";
1818
import Button from "../form/Button";
1919
import Checkbox from "../form/Checkbox";
2020
import Range from "../form/Range";

context/AuthContext.tsx

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ import {
99
} from "firebase/auth";
1010
import { auth } from "@/config/firebase";
1111
import { useToast } from "./ToastContext";
12+
import Layout from "@/layout/Layout";
13+
import { Loader } from "@/components";
1214

1315
const GithubProvider = new GithubAuthProvider();
1416
const GoogleProvider = new GoogleAuthProvider();
@@ -40,6 +42,7 @@ const AuthProvider: React.FC<{ children: React.ReactNode }> = ({
4042
children,
4143
}) => {
4244
const { addToast } = useToast();
45+
const [signingIn, setSigningIn] = useState(false);
4346
const [user, setUser] = useState<User | null>(null);
4447

4548
/**
@@ -66,6 +69,7 @@ const AuthProvider: React.FC<{ children: React.ReactNode }> = ({
6669

6770
const loginWithGoogle = async () => {
6871
if (!auth) return console.log(Error("Firebase is not configured")); // This is to handle error when there is no `.env` file. So, that app doesn't crash while developing without `.env` file.
72+
setSigningIn(true);
6973
try {
7074
await signInWithPopup(auth, GoogleProvider);
7175
addToast({
@@ -74,6 +78,12 @@ const AuthProvider: React.FC<{ children: React.ReactNode }> = ({
7478
});
7579
} catch (error) {
7680
console.log("Error while logging in", error);
81+
addToast({
82+
message: "Error occurred while signing in!",
83+
type: "error",
84+
});
85+
} finally {
86+
setSigningIn(false);
7787
}
7888
};
7989

@@ -100,7 +110,13 @@ const AuthProvider: React.FC<{ children: React.ReactNode }> = ({
100110
<AuthContext.Provider
101111
value={{ user, loginWithGithub, loginWithGoogle, logout }}
102112
>
103-
{children}
113+
{signingIn ? (
114+
<Layout>
115+
<Loader />
116+
</Layout>
117+
) : (
118+
children
119+
)}
104120
</AuthContext.Provider>
105121
);
106122
};

layout/Layout.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ interface Props extends React.HTMLAttributes<HTMLDivElement> {
1111
}
1212

1313
const Layout: React.FC<Props> = ({
14-
title = "Snippng | snippets to png",
15-
description = "Create and share beautiful images of your source code.",
14+
title = "Snippng | code snippets to image",
15+
description = "Write, customize and download gorgeous images of your code snippet.",
1616
className,
1717
...props
1818
}) => {

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "snippng",
3-
"version": "1.0.0-beta",
3+
"version": "1.0.0",
44
"private": true,
55
"scripts": {
66
"dev": "next dev",

pages/_document.tsx

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
1-
import { Html, Head, Main, NextScript } from "next/document";
2-
import Script from "next/script";
1+
import { Head, Html, Main, NextScript } from "next/document";
32

43
const modeScript = `
54
let darkModeMediaQuery = window.matchMedia('(prefers-color-scheme: dark)')
65
76
updateMode()
87
darkModeMediaQuery.addEventListener('change', updateModeWithoutTransitions)
9-
window.addEventListener('storage', updateModeWithoutTransitions)
8+
window.addEventListener('storage̦', updateModeWithoutTransitions)
109
1110
function updateMode() {
1211
let isDarkMode = window.localStorage.isDarkMode === 'true'

pages/_offline.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ import { ErrorText } from "@/components";
22
import Layout from "@/layout/Layout";
33
import { ExclamationTriangleIcon } from "@heroicons/react/24/outline";
44
import { useRouter } from "next/router";
5-
import React from "react";
65

76
const OfflinePage = () => {
87
const router = useRouter();

pages/index.tsx

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,12 @@ import GithubIcon from "@/components/icons/GithubIcon";
33
import Layout from "@/layout/Layout";
44
import { LANGUAGES, THEMES } from "@/lib/constants";
55
import { PlusCircleIcon } from "@heroicons/react/24/outline";
6+
import { useRouter } from "next/router";
7+
import { useEffect } from "react";
68

79
export default function Home() {
10+
const router = useRouter();
11+
812
const focusOnGenerate = () => {
913
let codeArea = document.getElementById("snippng-code-area");
1014
if (codeArea) {
@@ -13,6 +17,21 @@ export default function Home() {
1317
});
1418
}
1519
};
20+
21+
useEffect(() => {
22+
if (!router.isReady) return;
23+
let timer: NodeJS.Timeout;
24+
let goToEditor = router.asPath.split("#").includes("snippng-code-area");
25+
if (goToEditor) {
26+
timer = setTimeout(() => {
27+
focusOnGenerate();
28+
}, 200);
29+
}
30+
return () => {
31+
clearTimeout(timer);
32+
};
33+
}, [router.isReady]);
34+
1635
return (
1736
<Layout>
1837
<div data-testid="landing-container" className="bg-transparent">
@@ -43,7 +62,7 @@ export default function Home() {
4362
</svg>
4463
</div>
4564
<div className="relative isolate overflow-hidden">
46-
<div className="mx-auto max-w-7xl pt-10 pb-24 sm:pb-32 lg:grid lg:grid-cols-2 lg:gap-x-8 lg:py-20">
65+
<div className="mx-auto max-w-7xl pt-10 pb-24 sm:pb-32 lg:grid lg:grid-cols-2 lg:gap-x-8 lg:py-12">
4766
<div className="lg:pt-4">
4867
<div className="mx-auto max-w-2xl">
4968
<div className="max-w-lg">
@@ -81,9 +100,10 @@ export default function Home() {
81100
Snippng
82101
</h1>
83102
<p className="mt-6 md:text-lg text-sm dark:text-zinc-300 text-zinc-600">
84-
Create and share beautiful images of your source code. Start
85-
typing or paste a code snippet into the text area to get
86-
started.
103+
Write, customize and download gorgeous images of your code
104+
snippet. Beautifully designed application that helps you
105+
generate beautiful and customizable images of your code
106+
snippets.
87107
</p>
88108
<div className="mt-10 flex md:flex-row flex-col md:items-center items-start gap-6 ml-1">
89109
<Button

0 commit comments

Comments
 (0)