Skip to content

enhanced the app bar collapse feature #1840

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

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
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
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@
"eslint": "^8.56.0",
"jsdom": "^24.0.0",
"prettier": "^3.2.4",
"prettier-plugin-tailwindcss": "^0.6.11",
"prisma": "^5.18.0",
"tailwindcss": "^3.3.0",
"ts-node": "^10.9.2",
Expand Down
16 changes: 13 additions & 3 deletions src/app/(main)/layout.tsx
Original file line number Diff line number Diff line change
@@ -1,15 +1,25 @@
"use client";
import { Appbar } from '@/components/Appbar';
import { useRecoilValue } from 'recoil';
import { isSideBarCollapsed } from '@/store/atoms/isSideBarCollabsed';
import React from 'react';

interface Props {
children: React.ReactNode;
}

export default (props: Props) => {
export default function Layout({children}: Props) {
const isCollapsed=useRecoilValue(isSideBarCollapsed);
return (
<div className="flex min-h-screen w-full">
<Appbar />
<div className="wrapper w-full">{props.children}</div>
<main
className={`flex-1 transition-all duration-300 ${
isCollapsed ? 'ml-[5vw]' : 'ml-[21vw]'
}`}
>
{children}
</main>
</div>
);
};
}
10 changes: 9 additions & 1 deletion src/app/courses/layout.tsx
Original file line number Diff line number Diff line change
@@ -1,15 +1,23 @@
'use client';
import { Appbar } from '@/components/Appbar';
import { isSideBarCollapsed } from '@/store/atoms/isSideBarCollabsed';
import React from 'react';
import { useRecoilValue } from 'recoil';

interface Props {
children: React.ReactNode;
}

const CourseLayout = (props: Props) => {
const isCollapsed=useRecoilValue(isSideBarCollapsed);
return (
<div className="flex min-h-screen">
<Appbar />
<div className="wrapper w-full">{props.children}</div>
<div className={`flex-1 transition-all duration-300 ${
isCollapsed ? 'ml-[5vw]' : 'ml-[21vw]'
}`}
>
{props.children}</div>
</div>
);
};
Expand Down
12 changes: 10 additions & 2 deletions src/components/Appbar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ import {
import { SidebarItems } from './ui/sidebar-items';
import { useState, useEffect, useRef } from 'react';
import { motion } from 'framer-motion';
import { isSideBarCollapsed } from '@/store/atoms/isSideBarCollabsed';
import { useRecoilState } from 'recoil';

export const menuOptions = [
{ id: 1, name: 'Home', Component: Home, href: '/home' },
Expand Down Expand Up @@ -45,6 +47,8 @@ export default useMediaQuery;

export const Appbar = () => {
const [isCollapsed, setIsCollapsed] = useState(true);
const [isSidebarCollapsed,setIsSidebarCollapsed] = useRecoilState(isSideBarCollapsed);
setIsSidebarCollapsed(isCollapsed);
const [isMounted, setIsMounted] = useState(false);
const isMediumToXL = useMediaQuery(
'(min-width: 768px) and (max-width: 1535px)',
Expand All @@ -56,6 +60,7 @@ export const Appbar = () => {
const handleClickOutside = (event: MouseEvent) => {
if (sidebarRef.current && !sidebarRef.current.contains(event.target as Node)) {
setIsCollapsed(true);
setIsSidebarCollapsed(true);
}
};
document.addEventListener('mousedown', handleClickOutside);
Expand All @@ -64,7 +69,10 @@ export const Appbar = () => {
};
}, []);

const toggleCollapse = () => setIsCollapsed(!isCollapsed);
const toggleCollapse = () => {
setIsCollapsed(!isCollapsed);
setIsSidebarCollapsed(!isSidebarCollapsed);
};

const sidebarVariants = {
expanded: { width: '20vw' },
Expand All @@ -88,7 +96,7 @@ export const Appbar = () => {
className="fixed left-0 top-0 z-[999] hidden h-full flex-col border-r border-primary/10 bg-background dark:bg-background lg:flex min-w-16"
>
<div className="flex h-full flex-col gap-4">
<div className="flex w-full items-center border-b border-primary/10 px-2 py-4">
<div className="flex w-full items-center border-b border-primary/10 px-2 py-3">
<div>
<motion.button
onClick={toggleCollapse}
Expand Down
2 changes: 0 additions & 2 deletions src/components/VideoPlayer2.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -111,9 +111,7 @@ export const VideoPlayer: FunctionComponent<VideoPlayerProps> = ({
};

const setupZoomFeatures = (player: any) => {

if (typeof window === 'undefined' || typeof document === 'undefined') return;

const videoEl = player.el().querySelector('video');
const container = player.el();

Expand Down
1 change: 0 additions & 1 deletion src/components/posts/form/form-vote.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@ const VoteForm: React.FC<IVoteFormProps> = ({
);
};


const userVoted = Boolean(votesArr.length);
const userVoteVal = votesArr[0];

Expand Down
6 changes: 6 additions & 0 deletions src/store/atoms/isSideBarCollabsed.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import { atom } from 'recoil';

export const isSideBarCollapsed = atom({
key: 'isSideBarCollapsed',
default: false,
});