Renamed sidebar actions as they make more sense

This commit is contained in:
Alejandro Celaya 2022-03-11 16:07:17 +01:00
parent 73d4707420
commit c949359d6f
4 changed files with 17 additions and 17 deletions

View file

@ -12,8 +12,8 @@ import { AsideMenuProps } from './AsideMenu';
import './MenuLayout.scss';
interface MenuLayoutProps {
sidebarRendered: Function;
sidebarNotRendered: Function;
sidebarPresent: Function;
sidebarNotPresent: Function;
}
const MenuLayout = (
@ -29,16 +29,16 @@ const MenuLayout = (
Overview: FC,
EditShortUrl: FC,
ManageDomains: FC,
) => withSelectedServer<MenuLayoutProps>(({ selectedServer, sidebarNotRendered, sidebarRendered }) => {
) => withSelectedServer<MenuLayoutProps>(({ selectedServer, sidebarNotPresent, sidebarPresent }) => {
const location = useLocation();
const [ sidebarVisible, toggleSidebar, showSidebar, hideSidebar ] = useToggle();
const showContent = isReachableServer(selectedServer);
useEffect(() => hideSidebar(), [ location ]);
useEffect(() => {
showContent && sidebarRendered();
showContent && sidebarPresent();
return () => sidebarNotRendered();
return () => sidebarNotPresent();
}, []);
if (!showContent) {

View file

@ -2,8 +2,8 @@ import { Action } from 'redux';
import { buildActionCreator, buildReducer } from '../../utils/helpers/redux';
/* eslint-disable padding-line-between-statements */
export const SIDEBAR_RENDERED = 'shlink/common/SIDEBAR_RENDERED';
export const SIDEBAR_NOT_RENDERED = 'shlink/common/SIDEBAR_NOT_RENDERED';
export const SIDEBAR_PRESENT = 'shlink/common/SIDEBAR_PRESENT';
export const SIDEBAR_NOT_PRESENT = 'shlink/common/SIDEBAR_NOT_PRESENT';
/* eslint-enable padding-line-between-statements */
export interface Sidebar {
@ -18,10 +18,10 @@ const initialState: Sidebar = {
};
export default buildReducer<Sidebar, SidebarRenderedAction & SidebarNotRenderedAction>({
[SIDEBAR_RENDERED]: () => ({ hasSidebar: true }),
[SIDEBAR_NOT_RENDERED]: () => ({ hasSidebar: false }),
[SIDEBAR_PRESENT]: () => ({ hasSidebar: true }),
[SIDEBAR_NOT_PRESENT]: () => ({ hasSidebar: false }),
}, initialState);
export const sidebarRendered = buildActionCreator(SIDEBAR_RENDERED);
export const sidebarPresent = buildActionCreator(SIDEBAR_PRESENT);
export const sidebarNotRendered = buildActionCreator(SIDEBAR_NOT_RENDERED);
export const sidebarNotPresent = buildActionCreator(SIDEBAR_NOT_PRESENT);

View file

@ -9,7 +9,7 @@ import ErrorHandler from '../ErrorHandler';
import ShlinkVersionsContainer from '../ShlinkVersionsContainer';
import { ConnectDecorator } from '../../container/types';
import { withoutSelectedServer } from '../../servers/helpers/withoutSelectedServer';
import { sidebarNotRendered, sidebarRendered } from '../reducers/sidebar';
import { sidebarNotPresent, sidebarPresent } from '../reducers/sidebar';
import { ImageDownloader } from './ImageDownloader';
const provideServices = (bottle: Bottle, connect: ConnectDecorator) => {
@ -45,7 +45,7 @@ const provideServices = (bottle: Bottle, connect: ConnectDecorator) => {
'EditShortUrl',
'ManageDomains',
);
bottle.decorator('MenuLayout', connect([ 'selectedServer' ], [ 'selectServer', 'sidebarRendered', 'sidebarNotRendered' ]));
bottle.decorator('MenuLayout', connect([ 'selectedServer' ], [ 'selectServer', 'sidebarPresent', 'sidebarNotPresent' ]));
bottle.serviceFactory('AsideMenu', AsideMenu, 'DeleteServerButton');
@ -55,8 +55,8 @@ const provideServices = (bottle: Bottle, connect: ConnectDecorator) => {
bottle.serviceFactory('ErrorHandler', ErrorHandler, 'window', 'console');
// Actions
bottle.serviceFactory('sidebarRendered', () => sidebarRendered);
bottle.serviceFactory('sidebarNotRendered', () => sidebarNotRendered);
bottle.serviceFactory('sidebarPresent', () => sidebarPresent);
bottle.serviceFactory('sidebarNotPresent', () => sidebarNotPresent);
};
export default provideServices;

View file

@ -22,8 +22,8 @@ describe('<MenuLayout />', () => {
wrapper = shallow(
<MenuLayout
sidebarNotRendered={jest.fn()}
sidebarRendered={jest.fn}
sidebarNotPresent={jest.fn()}
sidebarPresent={jest.fn}
selectServer={jest.fn()}
selectedServer={selectedServer}
/>,