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

Added preloader. #436

Closed
wants to merge 1 commit into from
Closed
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
Binary file added frontend/bun.lockb
Binary file not shown.
13 changes: 13 additions & 0 deletions frontend/src/App.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import "./App.css";
import { BrowserRouter, Route, Routes } from "react-router-dom";
import { useState,useEffect } from "react";
import Navbar from "./components/Navbar";
import Footer from "./components/Footer";
import Home from "./pages/Home";
Expand Down Expand Up @@ -32,12 +33,20 @@ import CodeEditor from "./pages/CodeEditor";
import Contributors from "./pages/Contributors";
import userBlock from "./hooks/userBlock";
import Blocked from "./pages/Blocked";
import PreLoader from "./components/Loader/Loader";
// import axios from "axios";
// axios.defaults.baseURL = "http://localhost:3001/";

function App() {
const { theme, toggleTheme } = useTheme();
const { loading, isBlocked } = userBlock(5);
const [Preloading,setLoading]= useState(true);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
const [Preloading,setLoading]= useState(true);
const [preLoading,setPreLoading]= useState(true);

Variable is not in react naming convention
Similar to https://react.dev/reference/react/useState#setstate

useEffect(()=>{
const timer = setTimeout(() => {
setLoading(false)
}, 3000);
return()=> clearTimeout(timer);
},[])

if (loading) {
return <Loader />;
Expand All @@ -46,8 +55,12 @@ function App() {
if (isBlocked) {
return <Blocked />;
}
if(Preloading){
return <PreLoader />
}
return (
<BrowserRouter>

<React.Suspense fallback={<Loader />}>
<GoTop/>
<div style={{ backgroundColor: theme === 'light' ? '#fff' : '#000435', color: theme === 'light' ? '#000435' : '#fff'}}>
Expand Down
36 changes: 36 additions & 0 deletions frontend/src/components/Loader/Loader.tsx
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks great, just have one suggestion: instead of alternating between white and black colors in the preloader we can first show white then show black bg, and stop there.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As animation have also been added to the incoming text so that would not look good ,i tried it out. It just looks like a glitch.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok then we can go ahead with this

Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import React, { useState, useEffect } from 'react';
import { motion } from 'framer-motion';

const PreLoader: React.FC = () => {
const [isWhite, setIsWhite] = useState<boolean>(true);

useEffect(() => {
const interval = setInterval(() => {
setIsWhite((prev) => !prev);
}, 500);

return () => clearInterval(interval);
}, []);

return (
<motion.div
animate={{
color: isWhite ? 'black' : 'white',
backgroundColor: isWhite ? 'white' : 'black',
}}
transition={{ type: 'spring', stiffness: 15 }}
className="w-full h-svh overflow-hidden flex justify-center items-center transition ease-out duration-500"
>
<motion.div
initial={{ scale: 3 }}
animate={{ scale: 1 }}
transition={{ duration: 1.8, delay: 0.1, type: 'spring', stiffness: 30 }}
className="xl:text-5xl text-xl sm:text-2xl md:text-3xl lg:text-6xl uppercase font-extrabold font-sans"
>
<p>Welcome to StyleShare</p>
</motion.div>
</motion.div>
);
};

export default PreLoader;
3 changes: 3 additions & 0 deletions frontend/src/main.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,13 @@ import ReactDOM from 'react-dom/client'
import App from './App.tsx'
import { RecoilRoot } from "recoil";
import './index.css'
// import PreLoader from './components/Loader/Loader';
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove commented code


ReactDOM.createRoot(document.getElementById('root')!).render(
<React.StrictMode>
{/* <PreLoader /> */}
<RecoilRoot>

<App />
</RecoilRoot>
</React.StrictMode>,
Expand Down
Loading