Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dark light mode cached #47

Merged
merged 4 commits into from
Aug 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"editor.acceptSuggestionOnEnter": "on"
}
15 changes: 13 additions & 2 deletions app/context/store.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
"use client";
import { createContext, useContext, useState, ReactNode } from "react";
import { createContext, useContext, useState, ReactNode, useEffect } from "react";
import { AllPropsFromLayout, Theme, themeContext } from "@/types";

const ThemeContext = createContext<themeContext>({
Expand All @@ -10,8 +10,19 @@ const ThemeContext = createContext<themeContext>({
export const ThemeContextProvider = ({ children }: AllPropsFromLayout) => {
const [theme, setTheme] = useState("dark");

useEffect(() => {
// get the theme from localStorage on initial render
const storedTheme = localStorage.getItem("theme");
if (storedTheme) {
setTheme(storedTheme);
}
}, []);

const handleThemeSwitch = () => {
setTheme(theme === "dark" ? "light" : "dark");
// toggle the theme and store it in localStorage
const newTheme = theme === "dark" ? "light" : "dark";
setTheme(newTheme);
localStorage.setItem("theme", newTheme);
};

return (
Expand Down
18 changes: 14 additions & 4 deletions app/layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ import Navbar from "@/components/Navbar";
import { ThemeContextProvider } from "./context/store";
import NavigationLinks from "@/components/NavigationLinks";
import Footer from "@/components/Footer";
import Announcement from "@/components/Announcement";



const inter = Inter({ subsets: ["latin"] });

Expand All @@ -13,11 +16,13 @@ export const metadata = {
"A website where essential tools, prompts, and datasets are thoughtfully curated and combined in one place for your convenience.",
};


export default function RootLayout({
children,
}: {
children: React.ReactNode;
}) {

return (
<html lang="en">
<head>
Expand Down Expand Up @@ -54,16 +59,21 @@ export default function RootLayout({
<body
className={
inter.className +
"m-10 bg-[--light-bg] dark:bg-[--dark-bg] min-h-screen space-y-auto md:mx-10"
"m-10 bg-[--light-bg] dark:bg-[--dark-bg] min-h-screen space-y-auto"
}
>
<ThemeContextProvider>
<Navbar />
<NavigationLinks />
{children}
<Announcement />
<div className="md:mx-10">
<Navbar />
<NavigationLinks />
{children}
</div>

</ThemeContextProvider>
<Footer />
</body>
</html>
);
}

3 changes: 2 additions & 1 deletion app/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { useEffect } from "react";
import { useThemeContext } from "./context/store";
import Image from "next/image";
import PoweredByVercel from "../public/powered-by-vercel.svg";
import Undraw from "../public/undraw.svg";

export default function Home() {
const { theme } = useThemeContext();
Expand All @@ -29,7 +30,7 @@ export default function Home() {
</p>
</div>
<div className="h-72 w-72 md:h-96 md:w-auto lg:max-w-full">
<Image src={"/undraw.png"} width={500} height={500} alt={""} />
<Image src={Undraw} width={500} height={500} alt={""} />
</div>
</div>
<div className="mt-3 md:mt-8 flex flex-col items-center space-y-10 lg:space-y-12">
Expand Down
37 changes: 37 additions & 0 deletions components/Announcement.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
"use client";
import { useState } from "react";
import { RxCross2 } from "react-icons/rx";


async function getCurrentVersion() {
const response = await fetch(
"https://api.github.com/repos/PriyansuMaurya/AI-Fusion/releases/latest"
);
const data = await response.json();
return data.tag_name;
// return v1.2.4-beta
}


export default function Announcement() {
const [announcement, setAnnouncement] = useState(true);

return (
announcement &&
<div className="flex items-center justify-between bg-[--primary-color] text-[--light-bg] ease-out duration-300 undefined">
<div className="mx-3 md:mx-5" />
<div className=" px-4 py-2 text-center text-sm "> {
[
<>Check what has changed in the <strong className="underline underline-offset-1"><a href="https://github.com/PriyansuMaurya/AI-Fusion/releases/latest" rel="external noopener noreferrer" target="_blank">{getCurrentVersion()}</a></strong></>,
<>⭐️ If you like AI Fusion, give it a star on <a className="underline underline-offset-1" href="https://github.com/PriyansuMaurya/AI-Fusion/" rel="external noopener noreferrer" target="_blank">GitHub</a></>
][Math.floor(Math.random() * 2)]
}
</div>
{/* <div className="mx-3 md:mx-5" /> */}

<button onClick={() => setAnnouncement(false)}><RxCross2 className="mx-3 md:mx-5 hover:text-[--dark-bg] ease-out duration-300" size={20} /></button>

</div>
)
}

Binary file removed public/undraw.png
Binary file not shown.
Loading
Loading