From ba809c114196aa7de09b6666add69f1807a68747 Mon Sep 17 00:00:00 2001 From: Patrik Oldsberg Date: Thu, 28 May 2020 18:42:50 +0200 Subject: [PATCH] packages/core: move sidebar things closer to the sidebar --- packages/core/src/hooks/useSidebarPinState.ts | 28 ------------------- packages/core/src/layout/Sidebar/Bar.tsx | 6 ++-- packages/core/src/layout/Sidebar/Page.tsx | 2 +- .../Sidebar}/localStorage.test.ts | 0 .../{data => layout/Sidebar}/localStorage.ts | 0 5 files changed, 4 insertions(+), 32 deletions(-) delete mode 100644 packages/core/src/hooks/useSidebarPinState.ts rename packages/core/src/{data => layout/Sidebar}/localStorage.test.ts (100%) rename packages/core/src/{data => layout/Sidebar}/localStorage.ts (100%) diff --git a/packages/core/src/hooks/useSidebarPinState.ts b/packages/core/src/hooks/useSidebarPinState.ts deleted file mode 100644 index bbe548c699..0000000000 --- a/packages/core/src/hooks/useSidebarPinState.ts +++ /dev/null @@ -1,28 +0,0 @@ -/* - * Copyright 2020 Spotify AB - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -import { useContext } from 'react'; -import { SidebarPinStateContext } from '../layout/Sidebar'; - -export function useSidebarPinState() { - const { isPinned, toggleSidebarPinState } = useContext( - SidebarPinStateContext, - ); - - return { - isPinned, - toggleSidebarPinState, - }; -} diff --git a/packages/core/src/layout/Sidebar/Bar.tsx b/packages/core/src/layout/Sidebar/Bar.tsx index c5a8ae5669..1aadf9fd3e 100644 --- a/packages/core/src/layout/Sidebar/Bar.tsx +++ b/packages/core/src/layout/Sidebar/Bar.tsx @@ -16,10 +16,10 @@ import { makeStyles } from '@material-ui/core'; import clsx from 'clsx'; -import React, { FC, useRef, useState } from 'react'; +import React, { FC, useRef, useState, useContext } from 'react'; import { sidebarConfig, SidebarContext } from './config'; import { BackstageTheme } from '@backstage/theme'; -import { useSidebarPinState } from '../../hooks/useSidebarPinState'; +import { SidebarPinStateContext } from './Page'; const useStyles = makeStyles(theme => ({ root: { @@ -76,7 +76,7 @@ export const Sidebar: FC = ({ const classes = useStyles(); const [state, setState] = useState(State.Closed); const hoverTimerRef = useRef(); - const { isPinned } = useSidebarPinState(); + const { isPinned } = useContext(SidebarPinStateContext); const handleOpen = () => { if (isPinned) { diff --git a/packages/core/src/layout/Sidebar/Page.tsx b/packages/core/src/layout/Sidebar/Page.tsx index 750f764c2d..2a4cf0fbb2 100644 --- a/packages/core/src/layout/Sidebar/Page.tsx +++ b/packages/core/src/layout/Sidebar/Page.tsx @@ -18,7 +18,7 @@ import { makeStyles } from '@material-ui/core'; import React, { createContext, FC, useEffect, useState } from 'react'; import { sidebarConfig } from './config'; import { BackstageTheme } from '@backstage/theme'; -import { LocalStorage } from '../../data/localStorage'; +import { LocalStorage } from './localStorage'; const useStyles = makeStyles({ root: { diff --git a/packages/core/src/data/localStorage.test.ts b/packages/core/src/layout/Sidebar/localStorage.test.ts similarity index 100% rename from packages/core/src/data/localStorage.test.ts rename to packages/core/src/layout/Sidebar/localStorage.test.ts diff --git a/packages/core/src/data/localStorage.ts b/packages/core/src/layout/Sidebar/localStorage.ts similarity index 100% rename from packages/core/src/data/localStorage.ts rename to packages/core/src/layout/Sidebar/localStorage.ts