From b3fab3cfef90478f8adb7777dab6c4df1ee69e00 Mon Sep 17 00:00:00 2001 From: InfiniteTF Date: Sun, 8 Mar 2020 02:55:42 +0100 Subject: [PATCH] Make mobile menu behavior more consistent, and stats styles responsive (#391) --- pkg/api/server.go | 1 + ui/v2.5/.stylelintrc | 1 - ui/v2.5/src/components/List/ListFilter.tsx | 32 ++++++++++--- ui/v2.5/src/components/MainNavbar.tsx | 40 +++++++++++++++-- ui/v2.5/src/components/Scenes/SceneCard.tsx | 3 +- .../components/Scenes/SceneDetails/Scene.tsx | 5 +-- .../Scenes/SceneDetails/SceneEditPanel.tsx | 4 +- .../SettingsTasksPanel/SettingsTasksPanel.tsx | 6 ++- ui/v2.5/src/components/Shared/Select.tsx | 6 ++- ui/v2.5/src/components/Stats.tsx | 10 ++--- ui/v2.5/src/core/StashService.ts | 4 +- ui/v2.5/src/hooks/LocalForage.ts | 3 +- ui/v2.5/src/index.scss | 45 ++++++++++++++----- ui/v2.5/src/index.tsx | 22 +++++---- ui/v2.5/src/styles/_theme.scss | 2 +- 15 files changed, 135 insertions(+), 49 deletions(-) diff --git a/pkg/api/server.go b/pkg/api/server.go index 27141c5bf..c18bfd2bc 100644 --- a/pkg/api/server.go +++ b/pkg/api/server.go @@ -111,6 +111,7 @@ func Start() { r.Mount("/studio", studioRoutes{}.Routes()) r.HandleFunc("/css", func(w http.ResponseWriter, r *http.Request) { + w.Header().Set("Content-Type", "text/css") if !config.GetCSSEnabled() { return } diff --git a/ui/v2.5/.stylelintrc b/ui/v2.5/.stylelintrc index f90195b09..77cd341f2 100644 --- a/ui/v2.5/.stylelintrc +++ b/ui/v2.5/.stylelintrc @@ -50,7 +50,6 @@ "length-zero-no-unit": true, "max-empty-lines": 1, "max-nesting-depth": 4, - "max-line-length": 100, "media-feature-colon-space-after": "always", "media-feature-colon-space-before": "never", "media-feature-range-operator-space-after": "always", diff --git a/ui/v2.5/src/components/List/ListFilter.tsx b/ui/v2.5/src/components/List/ListFilter.tsx index e842b2993..8e7759db5 100644 --- a/ui/v2.5/src/components/List/ListFilter.tsx +++ b/ui/v2.5/src/components/List/ListFilter.tsx @@ -107,7 +107,11 @@ export const ListFilter: React.FC = ( function renderSortByOptions() { return props.filter.sortByOptions.map(option => ( - + {option} )); @@ -186,7 +190,11 @@ export const ListFilter: React.FC = ( function renderSelectAll() { if (props.onSelectAll) { return ( - onSelectAll()}> + onSelectAll()} + > Select All ); @@ -196,7 +204,11 @@ export const ListFilter: React.FC = ( function renderSelectNone() { if (props.onSelectNone) { return ( - onSelectNone()}> + onSelectNone()} + > Select None ); @@ -209,7 +221,11 @@ export const ListFilter: React.FC = ( if (props.otherOperations) { props.otherOperations.forEach(o => { options.push( - + {o.text} ); @@ -222,7 +238,9 @@ export const ListFilter: React.FC = ( - {options} + + {options} + ); } @@ -278,7 +296,9 @@ export const ListFilter: React.FC = ( {props.filter.sortBy} - {renderSortByOptions()} + + {renderSortByOptions()} + diff --git a/ui/v2.5/src/components/MainNavbar.tsx b/ui/v2.5/src/components/MainNavbar.tsx index e8fe16155..556d88622 100644 --- a/ui/v2.5/src/components/MainNavbar.tsx +++ b/ui/v2.5/src/components/MainNavbar.tsx @@ -1,4 +1,4 @@ -import React from "react"; +import React, { useEffect, useRef, useState } from "react"; import { FormattedMessage } from "react-intl"; import { Nav, Navbar, Button } from "react-bootstrap"; import { IconName } from "@fortawesome/fontawesome-svg-core"; @@ -48,6 +48,31 @@ const menuItems: IMenuItem[] = [ export const MainNavbar: React.FC = () => { const location = useLocation(); + const [expanded, setExpanded] = useState(false); + // react-bootstrap typing bug + // eslint-disable-next-line @typescript-eslint/no-explicit-any + const navbarRef = useRef(); + + const maybeCollapse = (event: Event) => { + if ( + navbarRef.current && + event.target instanceof Node && + !navbarRef.current.contains(event.target) + ) { + setExpanded(false); + } + }; + + useEffect(() => { + if (expanded) { + document.addEventListener("click", maybeCollapse); + document.addEventListener("touchstart", maybeCollapse); + } + return () => { + document.removeEventListener("click", maybeCollapse); + document.removeEventListener("touchstart", maybeCollapse); + }; + }, [expanded]); const path = location.pathname === "/performers" @@ -74,8 +99,15 @@ export const MainNavbar: React.FC = () => { bg="dark" className="top-nav" expand="md" + expanded={expanded} + onToggle={setExpanded} + ref={navbarRef} > - + setExpanded(false)} + > diff --git a/ui/v2.5/src/components/Scenes/SceneCard.tsx b/ui/v2.5/src/components/Scenes/SceneCard.tsx index 5309d7549..eb36bfeea 100644 --- a/ui/v2.5/src/components/Scenes/SceneCard.tsx +++ b/ui/v2.5/src/components/Scenes/SceneCard.tsx @@ -236,7 +236,8 @@ export const SceneCard: React.FC = ( {props.scene.date}

- {props.scene.details && TextUtils.truncate(props.scene.details, 100, "... (continued)")} + {props.scene.details && + TextUtils.truncate(props.scene.details, 100, "... (continued)")}

diff --git a/ui/v2.5/src/components/Scenes/SceneDetails/Scene.tsx b/ui/v2.5/src/components/Scenes/SceneDetails/Scene.tsx index 45de48ab6..ceda00397 100644 --- a/ui/v2.5/src/components/Scenes/SceneDetails/Scene.tsx +++ b/ui/v2.5/src/components/Scenes/SceneDetails/Scene.tsx @@ -137,10 +137,7 @@ export const Scene: React.FC = () => { > - + setScene(newScene)} diff --git a/ui/v2.5/src/components/Scenes/SceneDetails/SceneEditPanel.tsx b/ui/v2.5/src/components/Scenes/SceneDetails/SceneEditPanel.tsx index 7d1cb6ef8..b65b3d30b 100644 --- a/ui/v2.5/src/components/Scenes/SceneDetails/SceneEditPanel.tsx +++ b/ui/v2.5/src/components/Scenes/SceneDetails/SceneEditPanel.tsx @@ -344,7 +344,9 @@ export const SceneEditPanel: React.FC = (props: IProps) => { Studio setStudioId(items.length > 0 ? items[0]?.id : undefined)} + onSelect={items => + setStudioId(items.length > 0 ? items[0]?.id : undefined) + } ids={studioId ? [studioId] : []} /> diff --git a/ui/v2.5/src/components/Settings/SettingsTasksPanel/SettingsTasksPanel.tsx b/ui/v2.5/src/components/Settings/SettingsTasksPanel/SettingsTasksPanel.tsx index 2604e4bb0..357808ff4 100644 --- a/ui/v2.5/src/components/Settings/SettingsTasksPanel/SettingsTasksPanel.tsx +++ b/ui/v2.5/src/components/Settings/SettingsTasksPanel/SettingsTasksPanel.tsx @@ -168,7 +168,11 @@ export const SettingsTasksPanel: React.FC = () => {
Status: {status}
{!!status && status !== "Idle" ? ( - + ) : ( "" )} diff --git a/ui/v2.5/src/components/Shared/Select.tsx b/ui/v2.5/src/components/Shared/Select.tsx index ffecb9aac..8d72b094a 100644 --- a/ui/v2.5/src/components/Shared/Select.tsx +++ b/ui/v2.5/src/components/Shared/Select.tsx @@ -73,7 +73,9 @@ export const SceneGallerySelect: React.FC = props => { const onChange = (selectedItems: ValueType