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 3 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
2 changes: 0 additions & 2 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@

<!-- Favicons display -->
<link rel="apple-touch-icon" sizes="180x180" href="/favicon/apple-touch-icon.png?v=2.0.22">
<link rel="icon" type="image/png" sizes="32x32" href="/favicon/favicon-32x32.png?v=2.0.22">
<link rel="icon" type="image/png" sizes="16x16" href="/favicon/favicon-16x16.png?v=2.0.22">
<link rel="icon" type="image/svg+xml" href="/favicon/favicon.svg">
<link rel="mask-icon" href="/favicon/safari-pinned-tab.svg?v=2.0.22" color="#444444">
<link rel="shortcut icon" href="/favicon/favicon.ico?v=2.0.22">
IlyaIzr marked this conversation as resolved.
Show resolved Hide resolved
Expand Down
Binary file removed public/favicon/favicon-16x16.png
Binary file not shown.
Binary file removed public/favicon/favicon-32x32.png
Binary file not shown.
18 changes: 0 additions & 18 deletions src/features/side_bar/components/AppIcon/AppIcon.tsx

This file was deleted.

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

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

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

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

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
70 changes: 33 additions & 37 deletions src/features/side_bar/components/SideBar/SideBar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ 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={cn(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={cn(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
9 changes: 8 additions & 1 deletion src/utils/common/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ export const isErrorWithMessage = (
return e !== null && typeof e === 'object' && 'message' in e;
};


type flatObject = Record<string, string | boolean | number | undefined | null>;

export function flatObjectsAreEqual(
Expand Down Expand Up @@ -57,3 +56,11 @@ export const removeEmpty = <T extends Record<string, unknown | null | undefined>
}
return acc;
}, {} as NoUndefinedField<T>);

export function trimLinkIfInDev(isDevBuild: boolean, link: string) {
IlyaIzr marked this conversation as resolved.
Show resolved Hide resolved
// trim beginning of url designed for builded apps that serve static files via '/active/static'
if (isDevBuild && link?.startsWith('/active/static')) {
return link.replace('/active/static', '');
}
return link;
}
20 changes: 20 additions & 0 deletions src/utils/hooks/useBrowserTabUpdate.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { useEffect } from 'react';
import app_config from '~core/app_config';
import { trimLinkIfInDev } from '~utils/common';

export function useBrowserTabUpdateEffect(iconPath?: string) {
IlyaIzr marked this conversation as resolved.
Show resolved Hide resolved
// change tab icon (not expected to work in Safari https://stackoverflow.com/questions/63781987/cant-change-favicon-with-javascript-in-safari)
useEffect(() => {
if (!iconPath) return;
const link = trimLinkIfInDev(app_config.isDevBuild, iconPath);
const linkElements = document.querySelectorAll(
"link[rel~='icon']",
) as NodeListOf<HTMLLinkElement>;
linkElements.forEach((linkEl) => {
// keep url icons versions
const linkUrl = new URL(linkEl.href);
linkUrl.pathname = link!;
linkEl.href = linkUrl.pathname + linkUrl.search;
});
}, [iconPath]);
}
5 changes: 5 additions & 0 deletions src/views/CommonView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import { AppFeature } from '~core/auth/types';
import { Row } from '~components/Layout';
import { OriginalLogo } from '~components/KonturLogo/KonturLogo';
import { userResourceAtom } from '~core/auth';
import { currentAppPropertiesResourceAtom } from '~core/shared_state/currentApplication';
import { useBrowserTabUpdateEffect } from '~utils/hooks/useBrowserTabUpdate';
import type { AvailableRoutesAtom, CurrentRouteAtom } from '~core/router';
import type { PropsWithChildren } from 'react';

Expand All @@ -24,6 +26,9 @@ export function CommonView({
}>) {
const [{ data, loading }] = useAtom(userResourceAtom);
const userModel = data && !loading ? data : null;
const [{ data: appParams }] = useAtom(currentAppPropertiesResourceAtom);

useBrowserTabUpdateEffect(appParams?.faviconUrl);

useEffect(() => {
if (userModel?.hasFeature(AppFeature.INTERCOM)) {
Expand Down