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

fix(sidebar): 13451 - also define app name by app id and change icon in tab #285

Merged
merged 6 commits into from
Dec 14, 2022
Merged
Show file tree
Hide file tree
Changes from 2 commits
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
18 changes: 0 additions & 18 deletions src/features/side_bar/components/AppIcon/AppIcon.tsx

This file was deleted.

50 changes: 50 additions & 0 deletions src/features/side_bar/components/AppNameAndIcon/AppNameAndIcon.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
import { ActionsBarBTN } from '@konturio/ui-kit';
import { useAtom } from '@reatom/react';
import { useEffect } from 'react';
import app_config from '~core/app_config';
import { i18n } from '~core/localization';
import { currentAppPropertiesResourceAtom } from '~core/shared_state/currentApplication';

type AppNameAndIconProps = {
wrapClassName?: string;
appNameClassName?: string;
isOpen: boolean;
};

export function AppNameAndIcon({
isOpen,
appNameClassName,
wrapClassName,
}: AppNameAndIconProps) {
const [{ data: appParams }] = useAtom(currentAppPropertiesResourceAtom);
let iconPath = appParams?.sidebarIconUrl;

// trim beginning of url designed for builded apps that serve static files via '/active/static'
if (app_config.isDevBuild && iconPath?.startsWith('/active/static')) {
iconPath = iconPath.substring(14);
IlyaIzr marked this conversation as resolved.
Show resolved Hide resolved
}

const appIcon = iconPath ? (
<img src={iconPath} width={24} height={24} alt={i18n.t('sidebar.icon_alt')} />
) : null;

// change tab icon (not expected to work in Safari https://stackoverflow.com/questions/63781987/cant-change-favicon-with-javascript-in-safari)
useEffect(() => {
propakov marked this conversation as resolved.
Show resolved Hide resolved
if (!iconPath) return;
const linkElements = document.querySelectorAll(
IlyaIzr marked this conversation as resolved.
Show resolved Hide resolved
"link[rel~='icon']",
) as NodeListOf<HTMLLinkElement>;
linkElements.forEach((linkEl) => {
// keep url icons versions
const linkUrl = new URL(linkEl.href);
linkUrl.pathname = iconPath!;
linkEl.href = linkUrl.pathname + linkUrl.search;
});
}, [iconPath]);

return (
<ActionsBarBTN active={false} iconBefore={appIcon} className={wrapClassName}>
{isOpen ? <span className={appNameClassName}>{appParams?.name}</span> : null}
</ActionsBarBTN>
);
}
8 changes: 5 additions & 3 deletions src/features/side_bar/components/SideBar/SideBar.module.css
Original file line number Diff line number Diff line change
Expand Up @@ -95,15 +95,17 @@
display: flex;
}

.toggler {
.togglerButton {
margin-top: auto;
width: 100%;
padding: 0 var(--unit);
}

.toggler button:focus {
.togglerButton button:focus {
box-shadow: none;
}

.toggler button:focus-visible {
.togglerButton button:focus-visible {
box-shadow: var(--button-box-shadow);
}

Expand Down
72 changes: 34 additions & 38 deletions src/features/side_bar/components/SideBar/SideBar.tsx
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import { useAction, useAtom } from '@reatom/react';
import { ActionsBar, ActionsBarBTN, Logo } from '@konturio/ui-kit';
import cn from 'clsx';
import cn, { clsx } from 'clsx';
IlyaIzr marked this conversation as resolved.
Show resolved Hide resolved
import { Link } from 'react-router-dom';
import { useCallback, useEffect, useMemo, useState } from 'react';
import { DoubleChevronLeft24, DoubleChevronRight24 } from '@konturio/default-icons';
import { IS_MOBILE_QUERY, useMediaQuery } from '~utils/hooks/useMediaQuery';
import { i18n } from '~core/localization';
import { currentTooltipAtom } from '~core/shared_state/currentTooltip';
import { searchStringAtom } from '~core/url_store/atoms/urlStore';
import { SidebarAppIcon } from '../AppIcon/AppIcon';
import { AppNameAndIcon } from '../AppNameAndIcon/AppNameAndIcon';
import { SmallIconSlot } from '../SmallIconSlot/SmallIconSlot';
import { routeVisibilityChecker } from './routeVisibilityChecker';
import s from './SideBar.module.css';
Expand Down Expand Up @@ -82,17 +82,11 @@ export function SideBar({
<ActionsBar>
<div className={cn(s.logoWrap, s.sidebarItemContainer)} tabIndex={-1}>
<div className={s.buttonWrap}>
<ActionsBarBTN
active={false}
iconBefore={<SidebarAppIcon />}
className={cn(s.controlButton, s.logoButton)}
>
{isOpen ? (
<span className={s.modeName}>
Disaster <br /> Ninja
</span>
) : null}
</ActionsBarBTN>
<AppNameAndIcon
isOpen={isOpen}
wrapClassName={cn(s.controlButton, s.logoButton)}
appNameClassName={s.modeName}
/>
</div>
</div>
{availableRoutes.routes.map((route) => {
Expand Down Expand Up @@ -138,32 +132,34 @@ export function SideBar({
})}

<div className={s.togglerContainer}>
<div className={s.toggler}>
{isOpen ? (
<div className={s.buttonWrap} onClick={toggleIsOpen} tabIndex={-1}>
<ActionsBarBTN
iconBefore={<DoubleChevronLeft24 />}
className={s.controlButton}
>
<span className={s.modeName}>{i18n.t('sidebar.collapse')}</span>
</ActionsBarBTN>
</div>
) : (
<div
className={s.buttonWrap}
onClick={toggleIsOpen}
onPointerLeave={onMouseLeave}
onPointerEnter={(e) =>
onMouseEnter(e.target as HTMLDivElement, i18n.t('sidebar.expand'))
}
{isOpen ? (
<div
className={clsx(s.buttonWrap, s.togglerButton)}
onClick={toggleIsOpen}
tabIndex={-1}
>
<ActionsBarBTN
iconBefore={<DoubleChevronLeft24 />}
className={s.controlButton}
>
<ActionsBarBTN
iconBefore={<DoubleChevronRight24 />}
className={s.controlButton}
/>
</div>
)}
</div>
<span className={s.modeName}>{i18n.t('sidebar.collapse')}</span>
</ActionsBarBTN>
</div>
) : (
<div
className={clsx(s.buttonWrap, s.togglerButton)}
onClick={toggleIsOpen}
onPointerLeave={onMouseLeave}
onPointerEnter={(e) =>
onMouseEnter(e.target as HTMLDivElement, i18n.t('sidebar.expand'))
IlyaIzr marked this conversation as resolved.
Show resolved Hide resolved
}
>
<ActionsBarBTN
iconBefore={<DoubleChevronRight24 />}
className={s.controlButton}
/>
</div>
)}
</div>

<div className={s.konturLogo}>
Expand Down