quivr/frontend/lib/hooks/useDevice.ts
Matthieu Jacq c140b9c517
feat: responsive sidebar (#1279)
* 💄 The chat sidebar takes the full height

* 💄 redesign of the action section and buttons in the sidebar

*  Sidebar header

* ♻️  Refact sidebar filesystem structure

* ♻️  Create a separate reusable sidebar component

* 🐛 Fix sidebar quick open/close on mobile

* 💄 New open/close sidebar button

* fix: error message + sidebar height issue + mobile width incoherence

* ♻️  Rename and move the sidebar footer

* 💄 sidebar toggle: color on hover

* apply sidebar to brains-management

* 💄 Larger sidebar

* 🚨Pass existing tests

*  Test the sidebar

*  Test the open and close buttons in the sidebar
2023-10-02 14:42:23 +02:00

30 lines
737 B
TypeScript

import { useEffect, useState } from "react";
// Max width for mobile device: 640px
// Match small min-width media query in tailwind
const MOBILE_MAX_WIDTH = 640;
export const useDevice = (): { isMobile: boolean } => {
const [isMobile, setIsMobile] = useState(true);
useEffect(() => {
const handleResize = () => {
const screenWidth = window.innerWidth;
setIsMobile(screenWidth < MOBILE_MAX_WIDTH);
};
// Initial check
handleResize();
// Event listener for screen resize
window.addEventListener("resize", handleResize);
// Clean up event listener on component unmount
return () => {
window.removeEventListener("resize", handleResize);
};
}, []);
return { isMobile };
};