Skip to content

Commit

Permalink
modified card ui
Browse files Browse the repository at this point in the history
  • Loading branch information
Shubham-Lal authored Aug 4, 2024
2 parents 1117ed6 + 2c136ba commit cbd98fd
Show file tree
Hide file tree
Showing 47 changed files with 551 additions and 608 deletions.
1 change: 0 additions & 1 deletion client/src/App.css
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,6 @@
display: flex;
flex-direction: column;
gap: 30px;
user-select: none;
}

.column-debates {
Expand Down
30 changes: 15 additions & 15 deletions client/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,29 +19,29 @@ import NotificationPage from "./pages/notifications"
import { FaChevronLeft, FaChevronRight } from "react-icons/fa"

export default function App() {
const { setRoute, setUser, setIsAuthenticated, authTab, setAuthTab } = useAuthStore();
const { expand, sidebar, setSidebar } = useNavStore();
const { setRoute, setUser, setIsAuthenticated, authTab, setAuthTab } = useAuthStore()
const { expand, sidebar, setSidebar } = useNavStore()

const mainRef = useRef<HTMLDivElement>(null);
const lastScrollTop = useRef<number>(0);
const [isScrollingUp, setIsScrollingUp] = useState<boolean>(true);
const mainRef = useRef<HTMLDivElement>(null)
const lastScrollTop = useRef<number>(0)
const [isScrollingUp, setIsScrollingUp] = useState<boolean>(true)

useEffect(() => {
document.body.setAttribute('data-theme', localStorage.getItem('theme') === Theme.Light ? Theme.Light : Theme.Dark);
document.body.setAttribute('data-theme', localStorage.getItem('theme') === Theme.Light ? Theme.Light : Theme.Dark)

handleAutoLogin(setRoute, setUser, setIsAuthenticated, setAuthTab);
handleAutoLogin(setRoute, setUser, setIsAuthenticated, setAuthTab)

const handleScroll = () => {
const st = mainRef.current?.scrollTop ?? 0;
setIsScrollingUp(st <= lastScrollTop.current);
lastScrollTop.current = Math.max(st, 0);
};
const st = mainRef.current?.scrollTop ?? 0
setIsScrollingUp(st <= lastScrollTop.current)
lastScrollTop.current = Math.max(st, 0)
}

const mainElement = mainRef.current;
mainElement?.addEventListener('scroll', handleScroll, { passive: true });
return () => mainElement?.removeEventListener('scroll', handleScroll);
const mainElement = mainRef.current
mainElement?.addEventListener('scroll', handleScroll, { passive: true })
return () => mainElement?.removeEventListener('scroll', handleScroll)
// eslint-disable-next-line react-hooks/exhaustive-deps
}, []);
}, [])

return (
<div id='app'>
Expand Down
8 changes: 4 additions & 4 deletions client/src/ProtectedRoute.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@ interface ProtectedRouteProps {
}

export const ProtectedRoute: React.FC<ProtectedRouteProps> = ({ children }) => {
const { isAuthenticated } = useAuthStore();
const { isAuthenticated } = useAuthStore()

if (isAuthenticated === AuthStatus.Authenticating) {
return <LoadingComponent />
}
else if (isAuthenticated === AuthStatus.Failed) {
return <Navigate to='/auth' replace />;
return <Navigate to='/auth' replace />
}

return <>{children}</>;
};
return <>{children}</>
}
8 changes: 4 additions & 4 deletions client/src/components/button/toggle-theme.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@ import "./toggle-theme.css"
import { Theme, useNavStore } from "../../store/useNavStore"

const ToggleTheme = () => {
const { theme, setTheme } = useNavStore();
const { theme, setTheme } = useNavStore()

const handleToggleTheme = () => {
const newTheme = theme === Theme.Light ? Theme.Dark : Theme.Light;
document.querySelector("body")?.setAttribute('data-theme', newTheme);
setTheme(newTheme);
const newTheme = theme === Theme.Light ? Theme.Dark : Theme.Light
document.querySelector("body")?.setAttribute('data-theme', newTheme)
setTheme(newTheme)
}

return (
Expand Down
51 changes: 25 additions & 26 deletions client/src/components/card/claim-username.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,38 +8,36 @@ import { useNavStore } from "../../store/useNavStore"
import { usernameRegex } from "../../data/regex"

const ClaimUsername = () => {
const { setAuthTab } = useAuthStore();
const { sidebar } = useNavStore();
const { setAuthTab } = useAuthStore()
const { sidebar } = useNavStore()

const [isSubmitted, setIsSubmitted] = useState(false);
const [username, setUsername] = useState(localStorage.getItem("username") || "");
const [loading, setLoading] = useState(false);
const [message, setMessage] = useState({ type: '', content: '' });
const [isSubmitted, setIsSubmitted] = useState(false)
const [username, setUsername] = useState(localStorage.getItem("username") || "")
const [loading, setLoading] = useState(false)
const [message, setMessage] = useState({ type: '', content: '' })

const handleKeyPress = useCallback((e: React.KeyboardEvent<HTMLInputElement>) => {
if (e.key === ' ') e.preventDefault();
}, []);
if (e.key === ' ') e.preventDefault()
}, [])

const handleUsernameChange = (e: React.ChangeEvent<HTMLInputElement>) => {
const inputUsername = e.target.value;
setUsername(inputUsername);
const inputUsername = e.target.value
setUsername(inputUsername)

if (inputUsername) {
if (!usernameRegex.test(inputUsername)) {
setMessage({ type: 'error', content: 'Username can only contain alphanumeric characters, underscores (_) and hyphens (-). No spaces or other special characters are allowed.' });
} else setMessage({ type: '', content: '' });
setMessage({ type: 'error', content: 'Username can only contain alphanumeric characters, underscores (_) and hyphens (-). No spaces or other special characters are allowed.' })
} else setMessage({ type: '', content: '' })
}
};
}

const handleUsernameSubmit = async (e: React.FormEvent<HTMLFormElement>) => {
e.preventDefault();
setIsSubmitted(true);
setTimeout(() => setIsSubmitted(false), 500);
e.preventDefault()
setIsSubmitted(true)
setTimeout(() => setIsSubmitted(false), 500)

if (username && message.type !== 'error') {
setLoading(true);

localStorage.setItem("username", username);
setLoading(true)

await fetch(`${import.meta.env.VITE_SERVER_URL}/api/auth/check-username`, {
method: 'POST',
Expand All @@ -49,15 +47,16 @@ const ClaimUsername = () => {
.then(res => res.json())
.then(response => {
if (response.success) {
setAuthTab(AuthTab.Signup);
setMessage({ type: 'success', content: response.message });
toast.success(`${response.message} Register your account to claim username`);
} else setMessage({ type: 'error', content: response.message });
localStorage.setItem('username', username)
setAuthTab(AuthTab.Signup)
setMessage({ type: 'success', content: response.message })
toast.success('Register your account to claim username')
} else setMessage({ type: 'error', content: response.message })
})
.catch(() => setMessage({ type: 'error', content: 'Something went wrong. Try again later!' }))
.finally(() => setLoading(false));
.finally(() => setLoading(false))
}
};
}

return (
<form id='claim-username' className={sidebar ? 'hide' : ''} onSubmit={handleUsernameSubmit}>
Expand All @@ -76,7 +75,7 @@ const ClaimUsername = () => {
/>
</div>
<button className='submit-btn' disabled={loading}>
<span>CLAIM USERNAME</span>
<span>CLAIM PROFILE</span>
{!loading ? (
<PiArrowUpRightBold size={20} />
) : (
Expand Down
27 changes: 7 additions & 20 deletions client/src/components/card/closed-debate-card.css
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,12 @@
}

#closed-card .left h2 {
font-size: 20px;
font-size: 22px;
font-weight: 600;
overflow: hidden;
display: -webkit-box;
-webkit-line-clamp: 2;
line-clamp: 2;
-webkit-box-orient: vertical;
cursor: pointer;
}
Expand All @@ -45,7 +46,7 @@

#closed-card-loading .left .topic .loading-skeleton {
max-width: 300px;
height: 25px;
height: 28px;
border-radius: 30px;
}

Expand All @@ -58,17 +59,18 @@

#closed-card-loading .left .description .loading-skeleton {
width: 100%;
height: 17px;
height: 18px;
border-radius: 30px;
}

#closed-card .left p {
overflow: hidden;
display: -webkit-box;
-webkit-line-clamp: 5;
line-clamp: 5;
-webkit-box-orient: vertical;
padding-top: 10px;
font-size: 16px;
font-size: 17px;
color: var(--card_color_secondary);
}

Expand Down Expand Up @@ -183,6 +185,7 @@

#closed-card-loading .right .debate-bar {
margin-top: 10px;
gap: 2.5px;
}

#closed-card-loading .right .debate-bar .loading-skeleton {
Expand Down Expand Up @@ -234,14 +237,6 @@
padding-top: 10px;
}

#closed-card .left p {
font-size: 15px;
}

#closed-card-loading .left .description .loading-skeleton {
height: 16px;
}

#closed-card .left a,
#closed-card-loading .left .view .loading-skeleton {
display: none;
Expand All @@ -265,14 +260,6 @@
}

@media screen and (max-width: 480px) {
#closed-card .left h2 {
font-size: 18px;
}

#closed-card-loading .left .topic .loading-skeleton {
height: 23px;
}

#closed-card .divider,
#closed-card-loading .divider {
margin-top: 20px;
Expand Down
9 changes: 5 additions & 4 deletions client/src/components/card/closed-debate-card.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@ import useFormatNumber from "../../hooks/useFormatNumber"
import LoadingSkeleton from "../loading/skeleton"

const ClosedDebateCard = () => {
const navigate = useNavigate();
const { sidebar } = useNavStore();
const navigate = useNavigate()
const { sidebar } = useNavStore()

const handleProfileClick = (username: string) => {
navigate(`/${username}`);
navigate(`/${username}`)
}

return (
Expand Down Expand Up @@ -56,7 +56,7 @@ const ClosedDebateCard = () => {
}

const ClosedDebateLoadingCard = () => {
const { sidebar } = useNavStore();
const { sidebar } = useNavStore()

return (
<div id='closed-card-loading' className={sidebar ? 'card-break' : ''}>
Expand Down Expand Up @@ -87,6 +87,7 @@ const ClosedDebateLoadingCard = () => {
</div>
<div className='debate-bar'>
<LoadingSkeleton />
<LoadingSkeleton />
</div>
<div className='debate-info'>
<LoadingSkeleton />
Expand Down
6 changes: 3 additions & 3 deletions client/src/components/card/debate-bar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ interface BarProps {
}

const DebateBar: React.FC<BarProps> = ({ debateFrom, debateBy }) => {
const totalVotes = debateFrom + debateBy;
const leftPercentage = (debateFrom / totalVotes) * 100;
const rightPercentage = (debateBy / totalVotes) * 100;
const totalVotes = debateFrom + debateBy
const leftPercentage = (debateFrom / totalVotes) * 100
const rightPercentage = (debateBy / totalVotes) * 100

return (
<div className='debate-bar'>
Expand Down
Loading

0 comments on commit cbd98fd

Please sign in to comment.