Skip to content

Commit

Permalink
fix: rename standalone to focus-mode
Browse files Browse the repository at this point in the history
  • Loading branch information
CataldoMazzilli authored Sep 21, 2023
1 parent 3e1e799 commit 4d47c2d
Show file tree
Hide file tree
Showing 12 changed files with 36 additions and 36 deletions.
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 5 additions & 5 deletions src/boot/bootstrapper.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,15 @@ import { ContextBridge } from './context-bridge';
import { Loader } from './loader';
import ShellI18nextProvider from './shell-i18n-provider';
import { ThemeProvider } from './theme-provider';
import { BASENAME, IS_STANDALONE } from '../constants';
import { BASENAME, IS_FOCUS_MODE } from '../constants';
import { NotificationPermissionChecker } from '../notification/NotificationPermissionChecker';
import ShellView from '../shell/shell-view';
import { useAppStore } from '../store/app';

const StandaloneListener = (): null => {
const FocusModeListener = (): null => {
const { route } = useParams<{ route?: string }>();
useEffect(() => {
if (route) useAppStore.setState({ standalone: route });
if (route) useAppStore.setState({ focusMode: route });
}, [route]);
return null;
};
Expand All @@ -44,10 +44,10 @@ const Bootstrapper: FC = () => (
<SnackbarManager>
<ModalManager>
<Loader />
{IS_STANDALONE && (
{IS_FOCUS_MODE && (
<Switch>
<Route path={'/:route'}>
<StandaloneListener />
<FocusModeListener />
</Route>
</Switch>
)}
Expand Down
4 changes: 2 additions & 2 deletions src/boot/loader.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { find } from 'lodash';
import { useTranslation } from 'react-i18next';

import { loadApps, unloadAllApps } from './app/load-apps';
import { IS_STANDALONE } from '../constants';
import { IS_FOCUS_MODE } from '../constants';
import { getComponents } from '../network/get-components';
import { getInfo } from '../network/get-info';
import { loginConfig } from '../network/login-config';
Expand Down Expand Up @@ -81,7 +81,7 @@ export const Loader = (): React.JSX.Element => {
} else if ('message' in promiseRejectedResult.reason) {
console.error(promiseRejectedResult.reason.message);
}
if (!IS_STANDALONE) {
if (!IS_FOCUS_MODE) {
setOpen(true);
}
}
Expand Down
6 changes: 3 additions & 3 deletions src/constants/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,10 +78,10 @@ export const darkReaderDynamicThemeFixes: DynamicThemeFix = {

const base = '/carbonio/';

const standaloneBase = `${base}standalone`;
const focusModeBase = `${base}focus-mode`;

export const IS_STANDALONE = window.location.pathname.startsWith(standaloneBase);
export const BASENAME = IS_STANDALONE ? standaloneBase : base;
export const IS_FOCUS_MODE = window.location.pathname.startsWith(focusModeBase);
export const BASENAME = IS_FOCUS_MODE ? focusModeBase : base;
export const EMAIL_VALIDATION_REGEX =
// eslint-disable-next-line @typescript-eslint/no-unused-vars, max-len, no-control-regex
/(?:[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*|"(?:[\x01-\x08\x0b\x0c\x0e-\x1f\x21\x23-\x5b\x5d-\x7f]|\\[\x01-\x09\x0b\x0c\x0e-\x7f])*")@(?:(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?|\[(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?|[a-z0-9-]*[a-z0-9]:(?:[\x01-\x08\x0b\x0c\x0e-\x1f\x21-\x5a\x53-\x7f]|\\[\x01-\x09\x0b\x0c\x0e-\x7f])+)\])/;
Expand Down
4 changes: 2 additions & 2 deletions src/network/fetch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import {
SoapContext,
SoapResponse
} from '../../types';
import { IS_STANDALONE, SHELL_APP_ID } from '../constants';
import { IS_FOCUS_MODE, SHELL_APP_ID } from '../constants';
import { report } from '../reporting/functions';
import { useAccountStore } from '../store/account';
import { useNetworkStore } from '../store/network';
Expand Down Expand Up @@ -103,7 +103,7 @@ const handleResponse = <R>(api: string, res: SoapResponse<R>): R | ErrorSoapBody
(code) => code === (<ErrorSoapResponse>res).Body.Fault.Detail?.Error?.Code
)
) {
if (IS_STANDALONE) {
if (IS_FOCUS_MODE) {
useAccountStore.setState({ authenticated: false });
} else {
goToLogin();
Expand Down
4 changes: 2 additions & 2 deletions src/shell/app-view-container.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,14 @@ import { Redirect, Route, Switch, useLocation } from 'react-router-dom';
import styled from 'styled-components';

import AppContextProvider from '../boot/app/app-context-provider';
import { IS_STANDALONE } from '../constants';
import { IS_FOCUS_MODE } from '../constants';
import { useAppList, useAppStore, useRoutes } from '../store/app';

const _BoardsRouterContainer = styled(Container)`
flex-grow: 1;
flex-basis: 0;
min-width: 0.0625rem;
max-height: ${IS_STANDALONE ? '100vh' : 'calc(100vh - 3.75rem)'};
max-height: ${IS_FOCUS_MODE ? '100vh' : 'calc(100vh - 3.75rem)'};
overflow-y: auto;
`;

Expand Down
6 changes: 3 additions & 3 deletions src/shell/shell-view.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import ShellContextProvider from './shell-context-provider';
import ShellHeader from './shell-header';
import ShellNavigationBar from './shell-navigation-bar';
import { ThemeCallbacksContext } from '../boot/theme-provider';
import { IS_STANDALONE } from '../constants';
import { IS_FOCUS_MODE } from '../constants';
import { useDarkReaderResultValue } from '../dark-mode/use-dark-reader-result-value';
import { ShellUtilityBar } from '../utility-bar/bar';
import { ShellUtilityPanel } from '../utility-bar/panel';
Expand Down Expand Up @@ -49,7 +49,7 @@ const ShellComponent = (): React.JSX.Element => {
return (
<Background>
<DarkReaderListener />
{!IS_STANDALONE && (
{!IS_FOCUS_MODE && (
<ShellHeader
mobileNavIsOpen={mobileNavOpen}
onMobileMenuClick={(): void => setMobileNavOpen(!mobileNavOpen)}
Expand All @@ -58,7 +58,7 @@ const ShellComponent = (): React.JSX.Element => {
</ShellHeader>
)}
<Row crossAlignment="unset" style={{ position: 'relative', flexGrow: '1' }}>
{!IS_STANDALONE && <ShellNavigationBar mobileNavIsOpen={mobileNavOpen} />}
{!IS_FOCUS_MODE && <ShellNavigationBar mobileNavIsOpen={mobileNavOpen} />}
<AppViewContainer />
<ShellUtilityPanel />
</Row>
Expand Down
24 changes: 12 additions & 12 deletions src/store/app/store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import { normalizeApp } from './utils';
import type { AppState, CarbonioModule } from '../../../types';
import { SHELL_APP_ID } from '../../constants';

const STANDALONE_RESPONSE = 'standalone';
const FOCUS_MODE_RESPONSE = 'focus-mode';

function addIfNotPresent<T extends { id: unknown }>(
items: T[],
Expand Down Expand Up @@ -42,7 +42,7 @@ function removeById<T extends { id: unknown }>(items: T[], id: unknown): void {

// extra currying as suggested in https://github.com/pmndrs/zustand/blob/main/docs/guides/typescript.md#basic-usage
export const useAppStore = create<AppState>()((set, get) => ({
standalone: false,
focusMode: false,
apps: {},
appContexts: {},
shell: {
Expand Down Expand Up @@ -114,14 +114,14 @@ export const useAppStore = create<AppState>()((set, get) => ({
},
// add route (id route primaryBar secondaryBar app)
addRoute: (routeData): string => {
const { standalone } = get();
if (standalone && (routeData.route !== standalone || !routeData.standalone)) {
return STANDALONE_RESPONSE;
const { focusMode } = get();
if (focusMode && (routeData.route !== focusMode || !routeData.focusMode)) {
return FOCUS_MODE_RESPONSE;
}
set(
produce<AppState>((state) => {
state.routes[routeData.id] = routeData;
if (routeData.primaryBar && !routeData.standalone) {
if (routeData.primaryBar && !routeData.focusMode) {
addAndSort(state.views.primaryBar, {
app: routeData.app,
id: routeData.id,
Expand Down Expand Up @@ -199,9 +199,9 @@ export const useAppStore = create<AppState>()((set, get) => ({

// add settings
addSettingsView: (data): string => {
const { standalone } = get();
if (standalone && data.route !== standalone) {
return STANDALONE_RESPONSE;
const { focusMode } = get();
if (focusMode && data.route !== focusMode) {
return FOCUS_MODE_RESPONSE;
}
set(
produce<AppState>((state) => {
Expand All @@ -222,9 +222,9 @@ export const useAppStore = create<AppState>()((set, get) => ({
//
// add search
addSearchView: (data): string => {
const { standalone } = get();
if (standalone && data.route !== standalone) {
return STANDALONE_RESPONSE;
const { focusMode } = get();
if (focusMode && data.route !== focusMode) {
return FOCUS_MODE_RESPONSE;
}
set(
produce<AppState>((state) => {
Expand Down
2 changes: 1 addition & 1 deletion src/store/app/utils.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ export const normalizeRoute = (
primaryBar: data.primaryBar ?? app.icon ?? 'CubeOutline',
secondaryBar: data.secondaryBar,
appView: data.appView ?? FallbackView,
standalone: data.standalone
focusMode: data.focusMode
};
};

Expand Down
2 changes: 1 addition & 1 deletion src/utility-bar/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export const checkRoute = (
view: UtilityView | PrimaryAccessoryView | SecondaryAccessoryView,
activeRoute?: AppRoute
): boolean => {
const activeRouteValues = Object.values(omit(activeRoute, 'standalone') ?? {});
const activeRouteValues = Object.values(omit(activeRoute, 'focusMode') ?? {});
if (view.blacklistRoutes) return !checkList(activeRouteValues, view.blacklistRoutes);
if (view.whitelistRoutes) return checkList(activeRouteValues, view.whitelistRoutes);
return true;
Expand Down
6 changes: 3 additions & 3 deletions types/apps/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export type AppRoute = {
id: string;
route: string;
app: string;
standalone?: boolean;
focusMode?: boolean;
};

export type AppRouteData = AppRoute & {
Expand Down Expand Up @@ -131,7 +131,7 @@ export type AppRouteDescriptor = {
label: string;
secondaryBar?: ComponentType<SecondaryBarComponentProps>;
appView: ComponentType<AppViewComponentProps>;
standalone?: boolean;
focusMode?: boolean;
};
export type AppSetters = {
setApps: (apps: Array<Partial<CarbonioModule>>) => void;
Expand Down Expand Up @@ -177,7 +177,7 @@ export type AppSetters = {
setAppContext: (app: string) => (context: unknown) => void;
};
export type AppState = {
standalone: false | string;
focusMode: false | string;
apps: Record<string, CarbonioModule>;
appContexts: Record<string, unknown>;
entryPoints: Record<string, ComponentType>;
Expand Down
2 changes: 1 addition & 1 deletion types/exports/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ declare const ROOT_NAME: string;
declare const SHELL_MODES: Record<string, ShellModes>;
declare const BASENAME: string;

declare const IS_STANDALONE: boolean;
declare const IS_FOCUS_MODE: boolean;

// eslint-disable-next-line @typescript-eslint/ban-types
declare const getIntegratedFunction: (id: string) => [Function, boolean];
Expand Down

0 comments on commit 4d47c2d

Please sign in to comment.