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

Patch reliance on isMobile for mobile device UI detection #2072

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
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
Next Next commit
Patch reliance on isMobile for mobile device UI detection
  • Loading branch information
timothycarambat committed Aug 8, 2024
commit 2a0828f4e6462c8a803abd58654ab87ec7f250f7
3 changes: 3 additions & 0 deletions frontend/src/App.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ import i18n from "./i18n";
import { PfpProvider } from "./PfpContext";
import { LogoProvider } from "./LogoContext";
import { FullScreenLoader } from "./components/Preloader";
import { listenForWindowResize } from "./utils/mobile";
import { isMobile } from "react-device-detect";

const Main = lazy(() => import("@/pages/Main"));
const InvitePage = lazy(() => import("@/pages/Invite"));
Expand Down Expand Up @@ -66,6 +68,7 @@ const LiveDocumentSyncManage = lazy(
const FineTuningWalkthrough = lazy(() => import("@/pages/FineTuning"));

export default function App() {
listenForWindowResize();
return (
<Suspense fallback={<FullScreenLoader />}>
<ContextWrapper>
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/components/DefaultChat/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import NewWorkspaceModal, {
useNewWorkspaceModal,
} from "../Modals/NewWorkspace";
import paths from "@/utils/paths";
import { isMobile } from "react-device-detect";
import { isMobile } from "@/utils/mobile";
import { SidebarMobileHeader } from "../Sidebar";
import ChatBubble from "../ChatBubble";
import System from "@/models/system";
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/components/Footer/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import {
} from "@phosphor-icons/react";
import React, { useEffect, useState } from "react";
import SettingsButton from "../SettingsButton";
import { isMobile } from "react-device-detect";
import { isMobile } from "@/utils/mobile";
import { Tooltip } from "react-tooltip";
import { v4 } from "uuid";

Expand Down
2 changes: 1 addition & 1 deletion frontend/src/components/Modals/ManageWorkspace/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { X } from "@phosphor-icons/react";
import { useParams } from "react-router-dom";
import Workspace from "../../../models/workspace";
import System from "../../../models/system";
import { isMobile } from "react-device-detect";
import { isMobile } from "@/utils/mobile";
import useUser from "../../../hooks/useUser";
import DocumentSettings from "./Documents";
import DataConnectors from "./DataConnectors";
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/components/SettingsSidebar/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import {
} from "@phosphor-icons/react";
import useUser from "@/hooks/useUser";
import { USER_BACKGROUND_COLOR } from "@/utils/constants";
import { isMobile } from "react-device-detect";
import { isMobile } from "@/utils/mobile";
import Footer from "../Footer";
import { Link } from "react-router-dom";
import { useTranslation } from "react-i18next";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { CLEAR_ATTACHMENTS_EVENT, DndUploaderContext } from "./DnDWrapper";
import PromptInput, { PROMPT_INPUT_EVENT } from "./PromptInput";
import Workspace from "@/models/workspace";
import handleChat, { ABORT_STREAM_EVENT } from "@/utils/chat";
import { isMobile } from "react-device-detect";
import { isMobile } from "@/utils/mobile";
import { SidebarMobileHeader } from "../../Sidebar";
import { useParams } from "react-router-dom";
import { v4 } from "uuid";
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { isMobile } from "react-device-detect";
import { isMobile } from "@/utils/mobile";
import * as Skeleton from "react-loading-skeleton";
import "react-loading-skeleton/dist/skeleton.css";

Expand Down
2 changes: 1 addition & 1 deletion frontend/src/pages/Admin/Agents/index.jsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { useEffect, useRef, useState } from "react";
import Sidebar from "@/components/SettingsSidebar";
import { isMobile } from "react-device-detect";
import { isMobile } from "@/utils/mobile";
import Admin from "@/models/admin";
import System from "@/models/system";
import showToast from "@/utils/toast";
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { useEffect, useState } from "react";
import Sidebar from "@/components/Sidebar";
import { isMobile } from "react-device-detect";
import { isMobile } from "@/utils/mobile";
import * as Skeleton from "react-loading-skeleton";
import "react-loading-skeleton/dist/skeleton.css";
import System from "@/models/system";
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/pages/Admin/ExperimentalFeatures/index.jsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { useEffect, useState } from "react";
import Sidebar from "@/components/SettingsSidebar";
import { isMobile } from "react-device-detect";
import { isMobile } from "@/utils/mobile";
import Admin from "@/models/admin";
import { FullScreenLoader } from "@/components/Preloader";
import { CaretRight, Flask } from "@phosphor-icons/react";
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/pages/Admin/Invitations/index.jsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { useEffect, useState } from "react";
import Sidebar from "@/components/SettingsSidebar";
import { isMobile } from "react-device-detect";
import { isMobile } from "@/utils/mobile";
import * as Skeleton from "react-loading-skeleton";
import "react-loading-skeleton/dist/skeleton.css";
import { EnvelopeSimple } from "@phosphor-icons/react";
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/pages/Admin/Logging/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import Sidebar from "@/components/SettingsSidebar";
import useQuery from "@/hooks/useQuery";
import System from "@/models/system";
import { useEffect, useState } from "react";
import { isMobile } from "react-device-detect";
import { isMobile } from "@/utils/mobile";
import * as Skeleton from "react-loading-skeleton";
import LogRow from "./LogRow";
import showToast from "@/utils/toast";
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/pages/Admin/System/index.jsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { useEffect, useState } from "react";
import Sidebar from "@/components/SettingsSidebar";
import { isMobile } from "react-device-detect";
import { isMobile } from "@/utils/mobile";
import Admin from "@/models/admin";
import showToast from "@/utils/toast";
import CTAButton from "@/components/lib/CTAButton";
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/pages/Admin/Users/index.jsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { useEffect, useState } from "react";
import Sidebar from "@/components/SettingsSidebar";
import { isMobile } from "react-device-detect";
import { isMobile } from "@/utils/mobile";
import * as Skeleton from "react-loading-skeleton";
import "react-loading-skeleton/dist/skeleton.css";
import { UserPlus } from "@phosphor-icons/react";
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/pages/Admin/Workspaces/index.jsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { useEffect, useState } from "react";
import Sidebar from "@/components/SettingsSidebar";
import { isMobile } from "react-device-detect";
import { isMobile } from "@/utils/mobile";
import * as Skeleton from "react-loading-skeleton";
import "react-loading-skeleton/dist/skeleton.css";
import { BookOpen } from "@phosphor-icons/react";
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/pages/FineTuning/Steps/index.jsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { isMobile } from "react-device-detect";
import { isMobile } from "@/utils/mobile";
import { useState } from "react";
import Sidebar from "@/components/Sidebar";
import Introduction from "./Introduction";
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/pages/FineTuning/index.jsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React, { useState } from "react";
import FineTuningSteps, { FineTuningCreationLayout } from "./Steps";
import { CheckCircle, Circle, Sparkle } from "@phosphor-icons/react";
import { isMobile } from "react-device-detect";
import { isMobile } from "@/utils/mobile";

function SideBarSelection({ setStep, currentStep }) {
const currentIndex = Object.keys(FineTuningSteps).indexOf(currentStep);
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/pages/GeneralSettings/ApiKeys/index.jsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { useEffect, useState } from "react";
import Sidebar from "@/components/SettingsSidebar";
import { isMobile } from "react-device-detect";
import { isMobile } from "@/utils/mobile";
import * as Skeleton from "react-loading-skeleton";
import "react-loading-skeleton/dist/skeleton.css";
import { PlusCircle } from "@phosphor-icons/react";
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/pages/GeneralSettings/Appearance/index.jsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import Sidebar from "@/components/SettingsSidebar";
import { isMobile } from "react-device-detect";
import { isMobile } from "@/utils/mobile";
import FooterCustomization from "./FooterCustomization";
import SupportEmail from "./SupportEmail";
import CustomLogo from "./CustomLogo";
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React, { useEffect, useState, useRef } from "react";
import { isMobile } from "react-device-detect";
import { isMobile } from "@/utils/mobile";
import Sidebar from "@/components/SettingsSidebar";
import System from "@/models/system";
import PreLoader from "@/components/Preloader";
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/pages/GeneralSettings/Chats/index.jsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { useEffect, useRef, useState } from "react";
import Sidebar from "@/components/SettingsSidebar";
import { isMobile } from "react-device-detect";
import { isMobile } from "@/utils/mobile";
import * as Skeleton from "react-loading-skeleton";
import "react-loading-skeleton/dist/skeleton.css";
import useQuery from "@/hooks/useQuery";
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/pages/GeneralSettings/EmbedChats/index.jsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { useEffect, useState } from "react";
import Sidebar from "@/components/SettingsSidebar";
import { isMobile } from "react-device-detect";
import { isMobile } from "@/utils/mobile";
import * as Skeleton from "react-loading-skeleton";
import "react-loading-skeleton/dist/skeleton.css";
import useQuery from "@/hooks/useQuery";
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/pages/GeneralSettings/EmbedConfigs/index.jsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { useEffect, useState } from "react";
import { useTranslation } from "react-i18next";
import Sidebar from "@/components/SettingsSidebar";
import { isMobile } from "react-device-detect";
import { isMobile } from "@/utils/mobile";
import * as Skeleton from "react-loading-skeleton";
import "react-loading-skeleton/dist/skeleton.css";
import { CodeBlock } from "@phosphor-icons/react";
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React, { useEffect, useState, useRef } from "react";
import Sidebar from "@/components/SettingsSidebar";
import { isMobile } from "react-device-detect";
import { isMobile } from "@/utils/mobile";
import System from "@/models/system";
import showToast from "@/utils/toast";
import AnythingLLMIcon from "@/media/logo/anything-llm-icon.png";
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React, { useEffect, useState } from "react";
import Sidebar from "@/components/SettingsSidebar";
import { isMobile } from "react-device-detect";
import { isMobile } from "@/utils/mobile";
import PreLoader from "@/components/Preloader";
import CTAButton from "@/components/lib/CTAButton";
import Admin from "@/models/admin";
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/pages/GeneralSettings/LLMPreference/index.jsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React, { useEffect, useRef, useState } from "react";
import { useTranslation } from "react-i18next";
import Sidebar from "@/components/SettingsSidebar";
import { isMobile } from "react-device-detect";
import { isMobile } from "@/utils/mobile";
import System from "@/models/system";
import showToast from "@/utils/toast";
import AnythingLLMIcon from "@/media/logo/anything-llm-icon.png";
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { useEffect, useState } from "react";
import Sidebar from "@/components/SettingsSidebar";
import { isMobile } from "react-device-detect";
import { isMobile } from "@/utils/mobile";
import showToast from "@/utils/toast";
import System from "@/models/system";
import PreLoader from "@/components/Preloader";
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/pages/GeneralSettings/Security/index.jsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { useEffect, useState } from "react";
import Sidebar from "@/components/SettingsSidebar";
import { isMobile } from "react-device-detect";
import { isMobile } from "@/utils/mobile";
import showToast from "@/utils/toast";
import System from "@/models/system";
import paths from "@/utils/paths";
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React, { useEffect, useState, useRef } from "react";
import { isMobile } from "react-device-detect";
import { isMobile } from "@/utils/mobile";
import Sidebar from "@/components/SettingsSidebar";
import System from "@/models/system";
import showToast from "@/utils/toast";
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React, { useState, useEffect, useRef } from "react";
import Sidebar from "@/components/SettingsSidebar";
import { isMobile } from "react-device-detect";
import { isMobile } from "@/utils/mobile";
import System from "@/models/system";
import showToast from "@/utils/toast";
import ChromaLogo from "@/media/vectordbs/chroma.png";
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/pages/Main/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import React from "react";
import DefaultChatContainer from "@/components/DefaultChat";
import Sidebar from "@/components/Sidebar";
import PasswordModal, { usePasswordModal } from "@/components/Modals/Password";
import { isMobile } from "react-device-detect";
import { isMobile } from "@/utils/mobile";
import { FullScreenLoader } from "@/components/Preloader";
import UserMenu from "@/components/UserMenu";
import { FineTuningAlert } from "../FineTuning/Banner";
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/pages/OnboardingFlow/Steps/index.jsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { ArrowLeft, ArrowRight } from "@phosphor-icons/react";
import { useState } from "react";
import { isMobile } from "react-device-detect";
import { isMobile } from "@/utils/mobile";
import Home from "./Home";
import LLMPreference from "./LLMPreference";
import UserSetup from "./UserSetup";
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/pages/WorkspaceChat/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import Sidebar from "@/components/Sidebar";
import { useParams } from "react-router-dom";
import Workspace from "@/models/workspace";
import PasswordModal, { usePasswordModal } from "@/components/Modals/Password";
import { isMobile } from "react-device-detect";
import { isMobile } from "@/utils/mobile";
import { FullScreenLoader } from "@/components/Preloader";
import { FineTuningAlert } from "../FineTuning/Banner";

Expand Down
2 changes: 1 addition & 1 deletion frontend/src/pages/WorkspaceSettings/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { useParams } from "react-router-dom";
import Sidebar from "@/components/Sidebar";
import Workspace from "@/models/workspace";
import PasswordModal, { usePasswordModal } from "@/components/Modals/Password";
import { isMobile } from "react-device-detect";
import { isMobile } from "@/utils/mobile";
import { FullScreenLoader } from "@/components/Preloader";
import {
ArrowUUpLeft,
Expand Down
24 changes: 24 additions & 0 deletions frontend/src/utils/mobile.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
// This helper util is for forcing more mobile styling at a higher breakpoint
// since we relied previously on the isMobile from 'react-device-detect' which works
// fine for mobile but in contexts which the screen is simply smaller or a viewport cannot be determined
// we should simply rely on the window innerWidth as isMobile will not render and the mobile UI does enable
// a better experience for smaller screens.
import debounce from "lodash.debounce";
import { isMobile as deviceMobile } from "react-device-detect";

export var isMobile = calculateIsMobile();
function calculateIsMobile(breakpoint = 960) {
const _isMobile = deviceMobile || window.innerWidth <= breakpoint;
if (window.hasOwnProperty("isMobile") && window.isMobile !== _isMobile)
return window.location.reload();
isMobile = _isMobile;
window.isMobile = _isMobile;
return _isMobile;
}

const debounceResize = debounce(() => calculateIsMobile(), 800);
export function listenForWindowResize() {
if (!window) return;
window.removeEventListener("resize", debounceResize);
window.addEventListener("resize", debounceResize);
}