Skip to content

armgit / ente

Public Imported from GitHub
0

πŸ’š End-to-end encrypted cloud for everything.

cleanup _app photos page

Abhinavf985b1247f21
diff --git a/apps/photos/src/components/AuthenticateUserModal.tsx b/apps/photos/src/components/AuthenticateUserModal.tsx
index 159235ba1c..44f63bb447 100644
--- a/apps/photos/src/components/AuthenticateUserModal.tsx
+++ b/apps/photos/src/components/AuthenticateUserModal.tsx
@@ -5,10 +5,10 @@ import { AppContext } from 'pages/_app';
import { KeyAttributes, User } from 'types/user';
import VerifyMasterPasswordForm, {
VerifyMasterPasswordFormProps,
-} from 'components/VerifyMasterPasswordForm';
+} from '@ente/shared/components/VerifyMasterPasswordForm';
import { logError } from 'utils/sentry';
import { t } from 'i18next';
-import DialogBoxV2 from './DialogBoxV2';
+import DialogBoxV2 from '@ente/shared/components/DialogBoxV2';
interface Iprops {
open: boolean;
onClose: () => void;
diff --git a/apps/photos/src/components/ChangeEmail.tsx b/apps/photos/src/components/ChangeEmail.tsx
index 5972d3b731..28a6259f12 100644
--- a/apps/photos/src/components/ChangeEmail.tsx
+++ b/apps/photos/src/components/ChangeEmail.tsx
@@ -1,15 +1,15 @@
import { Formik, FormikHelpers } from 'formik';
import React, { useRef, useState } from 'react';
import * as Yup from 'yup';
-import SubmitButton from 'components/SubmitButton';
+import SubmitButton from '@ente/shared/components/SubmitButton';
import router from 'next/router';
import { changeEmail, sendOTTForEmailChange } from 'services/userService';
import { getData, LS_KEYS, setData } from 'utils/storage/localStorage';
-import { PAGES } from 'constants/pages';
+import { PHOTOS_PAGES as PAGES } from '@ente/shared/constants/pages';
import { Alert, Box, TextField } from '@mui/material';
import { VerticallyCentered } from './Container';
import LinkButton from './pages/gallery/LinkButton';
-import FormPaperFooter from './Form/FormPaper/Footer';
+import FormPaperFooter from '@ente/shared/components/Form/FormPaper/Footer';
import { sleep } from 'utils/common';
import { Trans } from 'react-i18next';
import { t } from 'i18next';
diff --git a/apps/photos/src/components/CodeBlock/CopyButton.tsx b/apps/photos/src/components/CodeBlock/CopyButton.tsx
deleted file mode 100644
index 608933459b..0000000000
--- a/apps/photos/src/components/CodeBlock/CopyButton.tsx
+++ /dev/null
@@ -1,43 +0,0 @@
-import React, { useState } from 'react';
-import DoneIcon from '@mui/icons-material/Done';
-import ContentCopyIcon from '@mui/icons-material/ContentCopy';
-import {
- IconButton,
- IconButtonProps,
- SvgIconProps,
- Tooltip,
-} from '@mui/material';
-import { t } from 'i18next';
-
-export default function CopyButton({
- code,
- color,
- size,
-}: {
- code: string;
- color?: IconButtonProps['color'];
- size?: SvgIconProps['fontSize'];
-}) {
- const [copied, setCopied] = useState<boolean>(false);
-
- const copyToClipboardHelper = (text: string) => () => {
- navigator.clipboard.writeText(text);
- setCopied(true);
- setTimeout(() => setCopied(false), 1000);
- };
- return (
- <Tooltip
- arrow
- open={copied}
- title={t('COPIED')}
- PopperProps={{ sx: { zIndex: 2000 } }}>
- <IconButton onClick={copyToClipboardHelper(code)} color={color}>
- {copied ? (
- <DoneIcon fontSize={size ?? 'small'} />
- ) : (
- <ContentCopyIcon fontSize={size ?? 'small'} />
- )}
- </IconButton>
- </Tooltip>
- );
-}
diff --git a/apps/photos/src/components/CodeBlock/index.tsx b/apps/photos/src/components/CodeBlock/index.tsx
deleted file mode 100644
index a05c913b2c..0000000000
--- a/apps/photos/src/components/CodeBlock/index.tsx
+++ /dev/null
@@ -1,37 +0,0 @@
-import { FreeFlowText } from '../Container';
-import React from 'react';
-import EnteSpinner from '../EnteSpinner';
-import { Wrapper, CodeWrapper, CopyButtonWrapper } from './styledComponents';
-import CopyButton from './CopyButton';
-import { BoxProps } from '@mui/material';
-
-type Iprops = React.PropsWithChildren<{
- code: string;
- wordBreak?: 'normal' | 'break-all' | 'keep-all' | 'break-word';
-}>;
-
-export default function CodeBlock({
- code,
- wordBreak,
- ...props
-}: BoxProps<'div', Iprops>) {
- if (!code) {
- return (
- <Wrapper>
- <EnteSpinner />
- </Wrapper>
- );
- }
- return (
- <Wrapper {...props}>
- <CodeWrapper>
- <FreeFlowText style={{ wordBreak: wordBreak }}>
- {code}
- </FreeFlowText>
- </CodeWrapper>
- <CopyButtonWrapper>
- <CopyButton code={code} />
- </CopyButtonWrapper>
- </Wrapper>
- );
-}
diff --git a/apps/photos/src/components/CodeBlock/styledComponents.tsx b/apps/photos/src/components/CodeBlock/styledComponents.tsx
deleted file mode 100644
index 2fe88171c2..0000000000
--- a/apps/photos/src/components/CodeBlock/styledComponents.tsx
+++ /dev/null
@@ -1,19 +0,0 @@
-import { CenteredFlex } from 'components/Container';
-import { Box, styled } from '@mui/material';
-export const Wrapper = styled(CenteredFlex)`
- position: relative;
- background: ${({ theme }) => theme.colors.accent.A700};
- border-radius: ${({ theme }) => theme.shape.borderRadius}px;
- min-height: 80px;
-`;
-export const CopyButtonWrapper = styled(Box)`
- position: absolute;
- top: 0px;
- right: 0px;
- margin-top: ${({ theme }) => theme.spacing(1)};
-`;
-
-export const CodeWrapper = styled('div')`
- padding: 16px 36px 16px 16px;
- border-radius: ${({ theme }) => theme.shape.borderRadius}px;
-`;
diff --git a/apps/photos/src/components/Collections/AllCollections/content.tsx b/apps/photos/src/components/Collections/AllCollections/content.tsx
index 13ff3e4b74..35b83b8220 100644
--- a/apps/photos/src/components/Collections/AllCollections/content.tsx
+++ b/apps/photos/src/components/Collections/AllCollections/content.tsx
@@ -9,7 +9,7 @@ import {
areEqual,
} from 'react-window';
import memoize from 'memoize-one';
-import useWindowSize from 'hooks/useWindowSize';
+import useWindowSize from '@ente/shared/hooks/useWindowSize';
import { AllCollectionMobileBreakpoint } from './dialog';
const MobileColumns = 2;
diff --git a/apps/photos/src/components/Collections/CollectionListBar/ScrollButton.tsx b/apps/photos/src/components/Collections/CollectionListBar/ScrollButton.tsx
index c37d688401..3a7c229e13 100644
--- a/apps/photos/src/components/Collections/CollectionListBar/ScrollButton.tsx
+++ b/apps/photos/src/components/Collections/CollectionListBar/ScrollButton.tsx
@@ -1,6 +1,6 @@
import React from 'react';
import NavigateNextIcon from '@mui/icons-material/NavigateNext';
-import { SCROLL_DIRECTION } from 'hooks/useComponentScroll';
+import { SCROLL_DIRECTION } from '@ente/shared/hooks/useComponentScroll';
import { css, styled } from '@mui/material';
const Wrapper = styled('button')<{ direction: SCROLL_DIRECTION }>`
diff --git a/apps/photos/src/components/Collections/CollectionListBar/index.tsx b/apps/photos/src/components/Collections/CollectionListBar/index.tsx
index 95a255f799..90fdd51782 100644
--- a/apps/photos/src/components/Collections/CollectionListBar/index.tsx
+++ b/apps/photos/src/components/Collections/CollectionListBar/index.tsx
@@ -19,8 +19,10 @@ import {
} from 'react-window';
import AutoSizer from 'react-virtualized-auto-sizer';
import memoize from 'memoize-one';
-import useComponentScroll, { SCROLL_DIRECTION } from 'hooks/useComponentScroll';
-import useWindowSize from 'hooks/useWindowSize';
+import useComponentScroll, {
+ SCROLL_DIRECTION,
+} from '@ente/shared/hooks/useComponentScroll';
+import useWindowSize from '@ente/shared/hooks/useWindowSize';
import ScrollButton from './ScrollButton';
interface IProps {
diff --git a/apps/photos/src/components/Collections/CollectionNamer.tsx b/apps/photos/src/components/Collections/CollectionNamer.tsx
index d01f901238..48d7f4fb3b 100644
--- a/apps/photos/src/components/Collections/CollectionNamer.tsx
+++ b/apps/photos/src/components/Collections/CollectionNamer.tsx
@@ -1,9 +1,9 @@
import React from 'react';
import SingleInputForm, {
SingleInputFormProps,
-} from 'components/SingleInputForm';
+} from '@ente/shared/components/SingleInputForm';
import { t } from 'i18next';
-import DialogBoxV2 from 'components/DialogBoxV2';
+import DialogBoxV2 from '@ente/shared/components/DialogBoxV2';
export interface CollectionNamerAttributes {
callback: (name: string) => void;
diff --git a/apps/photos/src/components/Collections/CollectionOptions/OnlyDownloadCollectionOption.tsx b/apps/photos/src/components/Collections/CollectionOptions/OnlyDownloadCollectionOption.tsx
index 1de0e9adad..04dfa0f47e 100644
--- a/apps/photos/src/components/Collections/CollectionOptions/OnlyDownloadCollectionOption.tsx
+++ b/apps/photos/src/components/Collections/CollectionOptions/OnlyDownloadCollectionOption.tsx
@@ -4,7 +4,7 @@ import React from 'react';
import FileDownloadOutlinedIcon from '@mui/icons-material/FileDownloadOutlined';
import { CollectionActions } from '.';
import { t } from 'i18next';
-import EnteSpinner from 'components/EnteSpinner';
+import EnteSpinner from '@ente/shared/components/EnteSpinner';
interface Iprops {
handleCollectionAction: (
action: CollectionActions,
diff --git a/apps/photos/src/components/Collections/CollectionOptions/QuickOptions/index.tsx b/apps/photos/src/components/Collections/CollectionOptions/QuickOptions/index.tsx
index 735b2da3f3..203494e1d2 100644
--- a/apps/photos/src/components/Collections/CollectionOptions/QuickOptions/index.tsx
+++ b/apps/photos/src/components/Collections/CollectionOptions/QuickOptions/index.tsx
@@ -10,7 +10,7 @@ import {
showShareQuickOption,
showEmptyTrashQuickOption,
} from 'utils/collection';
-import EnteSpinner from 'components/EnteSpinner';
+import EnteSpinner from '@ente/shared/components/EnteSpinner';
interface Iprops {
handleCollectionAction: (
action: CollectionActions,
diff --git a/apps/photos/src/components/Collections/CollectionSelector/index.tsx b/apps/photos/src/components/Collections/CollectionSelector/index.tsx
index fec6754d2a..9b3f12f0cb 100644
--- a/apps/photos/src/components/Collections/CollectionSelector/index.tsx
+++ b/apps/photos/src/components/Collections/CollectionSelector/index.tsx
@@ -4,7 +4,7 @@ import {
CollectionSummaries,
CollectionSummary,
} from 'types/collection';
-import DialogTitleWithCloseButton from 'components/DialogBox/TitleWithCloseButton';
+import DialogTitleWithCloseButton from '@ente/shared/components/DialogBox/TitleWithCloseButton';
import { AppContext } from 'pages/_app';
import { AllCollectionDialog } from 'components/Collections/AllCollections/dialog';
import { DialogContent } from '@mui/material';
diff --git a/apps/photos/src/components/Collections/CollectionShare/emailShare/AddParticipantForm.tsx b/apps/photos/src/components/Collections/CollectionShare/emailShare/AddParticipantForm.tsx
index 2dfa36dd08..1491d84453 100644
--- a/apps/photos/src/components/Collections/CollectionShare/emailShare/AddParticipantForm.tsx
+++ b/apps/photos/src/components/Collections/CollectionShare/emailShare/AddParticipantForm.tsx
@@ -1,7 +1,7 @@
import React, { useMemo, useState } from 'react';
import { Formik, FormikHelpers, FormikState } from 'formik';
import * as Yup from 'yup';
-import SubmitButton from 'components/SubmitButton';
+import SubmitButton from '@ente/shared/components/SubmitButton';
import TextField from '@mui/material/TextField';
import { FlexWrapper } from 'components/Container';
import { Button, FormHelperText, Stack } from '@mui/material';
diff --git a/apps/photos/src/components/Collections/CollectionShare/publicShare/copyLinkModal.tsx b/apps/photos/src/components/Collections/CollectionShare/publicShare/copyLinkModal.tsx
index dfb8a33d32..869f2034c9 100644
--- a/apps/photos/src/components/Collections/CollectionShare/publicShare/copyLinkModal.tsx
+++ b/apps/photos/src/components/Collections/CollectionShare/publicShare/copyLinkModal.tsx
@@ -1,4 +1,4 @@
-import DialogBoxBase from 'components/DialogBox/base';
+import DialogBoxBase from '@ente/shared/components/DialogBox/base';
import {
DialogActions,
Button,
diff --git a/apps/photos/src/components/Collections/CollectionShare/publicShare/manage/linkPassword/setPassword.tsx b/apps/photos/src/components/Collections/CollectionShare/publicShare/manage/linkPassword/setPassword.tsx
index 16a887de1e..b08e49a0b3 100644
--- a/apps/photos/src/components/Collections/CollectionShare/publicShare/manage/linkPassword/setPassword.tsx
+++ b/apps/photos/src/components/Collections/CollectionShare/publicShare/manage/linkPassword/setPassword.tsx
@@ -1,7 +1,7 @@
import { Dialog, Stack, Typography } from '@mui/material';
import SingleInputForm, {
SingleInputFormProps,
-} from 'components/SingleInputForm';
+} from '@ente/shared/components/SingleInputForm';
import React from 'react';
import { t } from 'i18next';
import ComlinkCryptoWorker from 'utils/comlink/ComlinkCryptoWorker';
diff --git a/apps/photos/src/components/Collections/index.tsx b/apps/photos/src/components/Collections/index.tsx
index 0bc6767693..6e5ea11bdf 100644
--- a/apps/photos/src/components/Collections/index.tsx
+++ b/apps/photos/src/components/Collections/index.tsx
@@ -12,7 +12,7 @@ import {
isSystemCollection,
shouldBeShownOnCollectionBar,
} from 'utils/collection';
-import { useLocalState } from 'hooks/useLocalState';
+import { useLocalState } from '@ente/shared/hooks/useLocalState';
import { sortCollectionSummaries } from 'services/collectionService';
import { LS_KEYS } from 'utils/storage/localStorage';
import {
diff --git a/apps/photos/src/components/DeleteAccountModal.tsx b/apps/photos/src/components/DeleteAccountModal.tsx
index 4daee68db0..1be84d7744 100644
--- a/apps/photos/src/components/DeleteAccountModal.tsx
+++ b/apps/photos/src/components/DeleteAccountModal.tsx
@@ -8,13 +8,13 @@ import { decryptDeleteAccountChallenge } from 'utils/crypto';
import { Trans } from 'react-i18next';
import { t } from 'i18next';
import { DELETE_ACCOUNT_EMAIL } from 'constants/urls';
-import DialogBoxV2 from './DialogBoxV2';
+import DialogBoxV2 from '@ente/shared/components/DialogBoxV2';
import * as Yup from 'yup';
import { Formik, FormikHelpers } from 'formik';
import DropdownInput, { DropdownOption } from './DropdownInput';
import MultilineInput from './MultilineInput';
import { CheckboxInput } from './CheckboxInput';
-import EnteButton from './EnteButton';
+import EnteButton from '@ente/shared/components/EnteButton';
import { GalleryContext } from 'pages/gallery';
import { logoutUser } from '@ente/accounts/services/user';
diff --git a/apps/photos/src/components/DialogBox/DialogIcon.tsx b/apps/photos/src/components/DialogBox/DialogIcon.tsx
deleted file mode 100644
index 1a9c275e68..0000000000
--- a/apps/photos/src/components/DialogBox/DialogIcon.tsx
+++ /dev/null
@@ -1,18 +0,0 @@
-import { Box } from '@mui/material';
-import React from 'react';
-
-export default function DialogIcon({ icon }: { icon: React.ReactNode }) {
- return (
- <Box
- className="DialogIcon"
- sx={{
- svg: {
- width: '48px',
- height: '48px',
- },
- color: 'stroke.muted',
- }}>
- {icon}
- </Box>
- );
-}
diff --git a/apps/photos/src/components/DialogBox/TitleWithCloseButton.tsx b/apps/photos/src/components/DialogBox/TitleWithCloseButton.tsx
deleted file mode 100644
index f78902b7ab..0000000000
--- a/apps/photos/src/components/DialogBox/TitleWithCloseButton.tsx
+++ /dev/null
@@ -1,54 +0,0 @@
-import React from 'react';
-import {
- DialogProps,
- DialogTitle,
- IconButton,
- Typography,
-} from '@mui/material';
-import CloseIcon from '@mui/icons-material/Close';
-import { SpaceBetweenFlex } from 'components/Container';
-
-const DialogTitleWithCloseButton = (props) => {
- const { children, onClose, ...other } = props;
-
- return (
- <DialogTitle {...other}>
- <SpaceBetweenFlex>
- <Typography variant="h3" fontWeight={'bold'}>
- {children}
- </Typography>
- {onClose && (
- <IconButton
- aria-label="close"
- onClick={onClose}
- sx={{ float: 'right' }}
- color="secondary">
- <CloseIcon />
- </IconButton>
- )}
- </SpaceBetweenFlex>
- </DialogTitle>
- );
-};
-
-export default DialogTitleWithCloseButton;
-
-export const dialogCloseHandler =
- ({
- staticBackdrop,
- nonClosable,
- onClose,
- }: {
- staticBackdrop?: boolean;
- nonClosable?: boolean;
- onClose: () => void;
- }): DialogProps['onClose'] =>
- (_, reason) => {
- if (nonClosable) {
- // no-op
- } else if (staticBackdrop && reason === 'backdropClick') {
- // no-op
- } else {
- onClose();
- }
- };
diff --git a/apps/photos/src/components/DialogBox/base.tsx b/apps/photos/src/components/DialogBox/base.tsx
deleted file mode 100644
index 159dad9619..0000000000
--- a/apps/photos/src/components/DialogBox/base.tsx
+++ /dev/null
@@ -1,40 +0,0 @@
-import { Dialog, styled } from '@mui/material';
-
-const DialogBoxBase = styled(Dialog)(({ theme }) => ({
- '& .MuiDialog-paper': {
- padding: theme.spacing(1, 1.5),
- maxWidth: '346px',
- },
-
- '& .DialogIcon': {
- padding: theme.spacing(2),
- paddingBottom: theme.spacing(1),
- },
-
- '& .MuiDialogTitle-root': {
- padding: theme.spacing(2),
- paddingBottom: theme.spacing(1),
- },
- '& .MuiDialogContent-root': {
- padding: theme.spacing(2),
- },
-
- '.DialogIcon + .MuiDialogTitle-root': {
- paddingTop: 0,
- },
-
- '.MuiDialogTitle-root + .MuiDialogContent-root': {
- paddingTop: 0,
- },
- '.MuiDialogTitle-root + .MuiDialogActions-root': {
- paddingTop: theme.spacing(3),
- },
- '& .MuiDialogActions-root': {
- flexWrap: 'wrap-reverse',
- },
- '& .MuiButton-root': {
- margin: `${theme.spacing(0.5, 0)} !important`,
- },
-}));
-
-export default DialogBoxBase;
diff --git a/apps/photos/src/components/DialogBox/index.tsx b/apps/photos/src/components/DialogBox/index.tsx
deleted file mode 100644
index 9597cf081b..0000000000
--- a/apps/photos/src/components/DialogBox/index.tsx
+++ /dev/null
@@ -1,116 +0,0 @@
-import React from 'react';
-import {
- Breakpoint,
- Button,
- DialogActions,
- DialogContent,
- DialogProps,
- Typography,
-} from '@mui/material';
-import DialogTitleWithCloseButton, {
- dialogCloseHandler,
-} from './TitleWithCloseButton';
-import DialogBoxBase from './base';
-import { DialogBoxAttributes } from 'types/dialogBox';
-import DialogIcon from './DialogIcon';
-import { t } from 'i18next';
-
-type IProps = React.PropsWithChildren<
- Omit<DialogProps, 'onClose' | 'maxSize'> & {
- onClose: () => void;
- attributes: DialogBoxAttributes;
- size?: Breakpoint;
- titleCloseButton?: boolean;
- }
->;
-
-export default function DialogBox({
- attributes,
- children,
- open,
- size,
- onClose,
- titleCloseButton,
- ...props
-}: IProps) {
- if (!attributes) {
- return <></>;
- }
-
- const handleClose = dialogCloseHandler({
- staticBackdrop: attributes.staticBackdrop,
- nonClosable: attributes.nonClosable,
- onClose: onClose,
- });
-
- return (
- <DialogBoxBase
- open={open}
- maxWidth={size}
- onClose={handleClose}
- {...props}>
- {attributes.icon && <DialogIcon icon={attributes.icon} />}
- {attributes.title && (
- <DialogTitleWithCloseButton
- onClose={
- titleCloseButton &&
- !attributes.nonClosable &&
- handleClose
- }>
- {attributes.title}
- </DialogTitleWithCloseButton>
- )}
- {(children || attributes?.content) && (
- <DialogContent>
- {children || (
- <Typography color="text.muted">
- {attributes.content}
- </Typography>
- )}
- </DialogContent>
- )}
- {(attributes.close || attributes.proceed) && (
- <DialogActions>
- <>
- {attributes.close && (
- <Button
- size="large"
- color={attributes.close?.variant ?? 'secondary'}
- onClick={() => {
- attributes.close.action &&
- attributes.close?.action();
- onClose();
- }}>
- {attributes.close?.text ?? t('OK')}
- </Button>
- )}
- {attributes.proceed && (
- <Button
- size="large"
- color={attributes.proceed?.variant}
- onClick={() => {
- attributes.proceed.action();
- onClose();
- }}
- disabled={attributes.proceed.disabled}>
- {attributes.proceed.text}
- </Button>
- )}
- {attributes.secondary && (
- <Button
- size="large"
- color={attributes.secondary?.variant}
- onClick={() => {
- attributes.secondary.action();
- onClose();
- }}
- disabled={attributes.secondary.disabled}>
- {attributes.secondary.text}
- </Button>
- )}
- </>
- </DialogActions>
- )}
- </DialogBoxBase>
- );
-}
diff --git a/apps/photos/src/components/DialogBoxV2/index.tsx b/apps/photos/src/components/DialogBoxV2/index.tsx
deleted file mode 100644
index f34aafaf10..0000000000
--- a/apps/photos/src/components/DialogBoxV2/index.tsx
+++ /dev/null
@@ -1,135 +0,0 @@
-import React, { useState } from 'react';
-import {
- Box,
- Button,
- Dialog,
- DialogProps,
- Stack,
- Typography,
-} from '@mui/material';
-import { t } from 'i18next';
-import { dialogCloseHandler } from 'components/DialogBox/TitleWithCloseButton';
-import { DialogBoxAttributesV2 } from 'types/dialogBox';
-import EnteButton from 'components/EnteButton';
-
-type IProps = React.PropsWithChildren<
- Omit<DialogProps, 'onClose'> & {
- onClose: () => void;
- attributes: DialogBoxAttributesV2;
- }
->;
-
-export default function DialogBoxV2({
- attributes,
- children,
- open,
- onClose,
- ...props
-}: IProps) {
- const [loading, setLoading] = useState(false);
- if (!attributes) {
- return <></>;
- }
-
- const handleClose = dialogCloseHandler({
- staticBackdrop: attributes.staticBackdrop,
- nonClosable: attributes.nonClosable,
- onClose: onClose,
- });
-
- const { PaperProps, ...rest } = props;
-
- return (
- <Dialog
- open={open}
- onClose={handleClose}
- PaperProps={{
- ...PaperProps,
- sx: {
- padding: '8px 12px',
- maxWidth: '360px',
- ...PaperProps?.sx,
- },
- }}
- {...rest}>
- <Stack spacing={'36px'} p={'16px'}>
- <Stack spacing={'19px'}>
- {attributes.icon && (
- <Box
- sx={{
- '& > svg': {
- fontSize: '32px',
- },
- }}>
- {attributes.icon}
- </Box>
- )}
- {attributes.title && (
- <Typography variant="large" fontWeight={'bold'}>
- {attributes.title}
- </Typography>
- )}
- {children ||
- (attributes?.content && (
- <Typography color="text.muted">
- {attributes.content}
- </Typography>
- ))}
- </Stack>
- {(attributes.proceed ||
- attributes.close ||
- attributes.buttons?.length) && (
- <Stack
- spacing={'8px'}
- direction={
- attributes.buttonDirection === 'row'
- ? 'row-reverse'
- : 'column'
- }
- flex={1}>
- {attributes.proceed && (
- <EnteButton
- loading={loading}
- size="large"
- color={attributes.proceed?.variant}
- onClick={async () => {
- await attributes.proceed.action(setLoading);
-
- onClose();
- }}
- disabled={attributes.proceed.disabled}>
- {attributes.proceed.text}
- </EnteButton>
- )}
- {attributes.close && (
- <Button
- size="large"
- color={attributes.close?.variant ?? 'secondary'}
- onClick={() => {
- attributes.close.action &&
- attributes.close?.action();
- onClose();
- }}>
- {attributes.close?.text ?? t('OK')}
- </Button>
- )}
- {attributes.buttons &&
- attributes.buttons.map((b) => (
- <Button
- size="large"
- key={b.text}
- color={b.variant}
- onClick={() => {
- b.action();
- onClose();
- }}
- disabled={b.disabled}>
- {b.text}
- </Button>
- ))}
- </Stack>
- )}
- </Stack>
- </Dialog>
- );
-}
diff --git a/apps/photos/src/components/EnteButton.tsx b/apps/photos/src/components/EnteButton.tsx
deleted file mode 100644
index b684198fc6..0000000000
--- a/apps/photos/src/components/EnteButton.tsx
+++ /dev/null
@@ -1,47 +0,0 @@
-import Done from '@mui/icons-material/Done';
-import {
- Button,
- ButtonProps,
- CircularProgress,
- PaletteColor,
-} from '@mui/material';
-
-interface Iprops extends ButtonProps {
- loading?: boolean;
- success?: boolean;
-}
-
-export default function EnteButton({
- children,
- loading,
- success,
- disabled,
- sx,
- ...props
-}: Iprops) {
- return (
- <Button
- disabled={disabled}
- sx={{
- ...sx,
- ...((loading || success) && {
- '&.Mui-disabled': (theme) => ({
- backgroundColor: (
- theme.palette[props.color] as PaletteColor
- ).main,
- color: (theme.palette[props.color] as PaletteColor)
- .contrastText,
- }),
- }),
- }}
- {...props}>
- {loading ? (
- <CircularProgress size={20} sx={{ color: 'inherit' }} />
- ) : success ? (
- <Done sx={{ fontSize: 20 }} />
- ) : (
- children
- )}
- </Button>
- );
-}
diff --git a/apps/photos/src/components/EnteSpinner.tsx b/apps/photos/src/components/EnteSpinner.tsx
deleted file mode 100644
index 4a4ae36a84..0000000000
--- a/apps/photos/src/components/EnteSpinner.tsx
+++ /dev/null
@@ -1,8 +0,0 @@
-import React from 'react';
-import CircularProgress, {
- CircularProgressProps,
-} from '@mui/material/CircularProgress';
-
-export default function EnteSpinner(props: CircularProgressProps) {
- return <CircularProgress color="accent" size={32} {...props} />;
-}
diff --git a/apps/photos/src/components/ExportModal.tsx b/apps/photos/src/components/ExportModal.tsx
index ade4aec5be..30b0cc8264 100644
--- a/apps/photos/src/components/ExportModal.tsx
+++ b/apps/photos/src/components/ExportModal.tsx
@@ -20,7 +20,7 @@ import ExportInit from './ExportInit';
import ExportInProgress from './ExportInProgress';
import FolderIcon from '@mui/icons-material/Folder';
import { ExportStage } from 'constants/export';
-import DialogTitleWithCloseButton from './DialogBox/TitleWithCloseButton';
+import DialogTitleWithCloseButton from '@ente/shared/components/DialogBox/TitleWithCloseButton';
import MoreHoriz from '@mui/icons-material/MoreHoriz';
import OverflowMenu from './OverflowMenu/menu';
import { OverflowMenuOption } from './OverflowMenu/option';
diff --git a/apps/photos/src/components/ExportPendingList.tsx b/apps/photos/src/components/ExportPendingList.tsx
index 4de889e55f..20c05b7a73 100644
--- a/apps/photos/src/components/ExportPendingList.tsx
+++ b/apps/photos/src/components/ExportPendingList.tsx
@@ -1,6 +1,6 @@
import { EnteFile } from 'types/file';
import ItemList from 'components/ItemList';
-import DialogBoxV2 from './DialogBoxV2';
+import DialogBoxV2 from '@ente/shared/components/DialogBoxV2';
import { t } from 'i18next';
import { FlexWrapper } from './Container';
import CollectionCard from './Collections/CollectionCard';
diff --git a/apps/photos/src/components/FixCreationTime/index.tsx b/apps/photos/src/components/FixCreationTime/index.tsx
index 71041009e1..786d9e0393 100644
--- a/apps/photos/src/components/FixCreationTime/index.tsx
+++ b/apps/photos/src/components/FixCreationTime/index.tsx
@@ -1,4 +1,4 @@
-import DialogBox from '../DialogBox';
+import DialogBox from '@ente/shared/components/DialogBox/';
import React, { useContext, useEffect, useState } from 'react';
import { updateCreationTimeWithExif } from 'services/updateCreationTimeWithExif';
import { GalleryContext } from 'pages/gallery';
diff --git a/apps/photos/src/components/FixLargeThumbnail.tsx b/apps/photos/src/components/FixLargeThumbnail.tsx
index f938e390e4..68a06af0e1 100644
--- a/apps/photos/src/components/FixLargeThumbnail.tsx
+++ b/apps/photos/src/components/FixLargeThumbnail.tsx
@@ -1,4 +1,4 @@
-import DialogBox from './DialogBox';
+import DialogBox from '@ente/shared/components/DialogBox/';
import React, { useEffect, useState } from 'react';
import { ProgressBar, Button } from 'react-bootstrap';
import { ComfySpan } from './ExportInProgress';
diff --git a/apps/photos/src/components/Form/FormPaper/Footer.tsx b/apps/photos/src/components/Form/FormPaper/Footer.tsx
deleted file mode 100644
index 9973a7b0c8..0000000000
--- a/apps/photos/src/components/Form/FormPaper/Footer.tsx
+++ /dev/null
@@ -1,22 +0,0 @@
-import React, { FC } from 'react';
-import { BoxProps, Divider } from '@mui/material';
-import { VerticallyCentered } from 'components/Container';
-
-const FormPaperFooter: FC<BoxProps> = ({ sx, style, ...props }) => {
- return (
- <>
- <Divider />
- <VerticallyCentered
- style={{ flexDirection: 'row', ...style }}
- sx={{
- mt: 3,
- ...sx,
- }}
- {...props}>
- {props.children}
- </VerticallyCentered>
- </>
- );
-};
-
-export default FormPaperFooter;
diff --git a/apps/photos/src/components/Form/FormPaper/Title.tsx b/apps/photos/src/components/Form/FormPaper/Title.tsx
deleted file mode 100644
index 62d8bd35f6..0000000000
--- a/apps/photos/src/components/Form/FormPaper/Title.tsx
+++ /dev/null
@@ -1,12 +0,0 @@
-import React, { FC } from 'react';
-import { Typography, TypographyProps } from '@mui/material';
-
-const FormPaperTitle: FC<TypographyProps> = ({ sx, ...props }) => {
- return (
- <Typography variant="h2" sx={{ mb: 8, ...sx }} {...props}>
- {props.children}
- </Typography>
- );
-};
-
-export default FormPaperTitle;
diff --git a/apps/photos/src/components/Form/FormPaper/index.tsx b/apps/photos/src/components/Form/FormPaper/index.tsx
deleted file mode 100644
index 32f2ad21a7..0000000000
--- a/apps/photos/src/components/Form/FormPaper/index.tsx
+++ /dev/null
@@ -1,9 +0,0 @@
-import { Paper, styled } from '@mui/material';
-
-const FormPaper = styled(Paper)(({ theme }) => ({
- padding: theme.spacing(4, 2),
- maxWidth: '360px',
- width: '100%',
- textAlign: 'left',
-}));
-export default FormPaper;
diff --git a/apps/photos/src/components/Form/ShowHidePassword.tsx b/apps/photos/src/components/Form/ShowHidePassword.tsx
deleted file mode 100644
index 0aa5ed6489..0000000000
--- a/apps/photos/src/components/Form/ShowHidePassword.tsx
+++ /dev/null
@@ -1,31 +0,0 @@
-import React from 'react';
-import { IconButton, InputAdornment } from '@mui/material';
-import VisibilityIcon from '@mui/icons-material/Visibility';
-import VisibilityOffIcon from '@mui/icons-material/VisibilityOff';
-
-interface Iprops {
- showPassword: boolean;
- handleClickShowPassword: () => void;
- handleMouseDownPassword: (
- event: React.MouseEvent<HTMLButtonElement>
- ) => void;
-}
-const ShowHidePassword = ({
- showPassword,
- handleClickShowPassword,
- handleMouseDownPassword,
-}: Iprops) => (
- <InputAdornment position="end">
- <IconButton
- tabIndex={-1}
- color="secondary"
- aria-label="toggle password visibility"
- onClick={handleClickShowPassword}
- onMouseDown={handleMouseDownPassword}
- edge="end">
- {showPassword ? <VisibilityOffIcon /> : <VisibilityIcon />}
- </IconButton>
- </InputAdornment>
-);
-
-export default ShowHidePassword;
diff --git a/apps/photos/src/components/GalleryEmptyState.tsx b/apps/photos/src/components/GalleryEmptyState.tsx
index 2c1e3748a0..f0780daf12 100644
--- a/apps/photos/src/components/GalleryEmptyState.tsx
+++ b/apps/photos/src/components/GalleryEmptyState.tsx
@@ -7,7 +7,7 @@ import FolderIcon from '@mui/icons-material/FolderOutlined';
import { UploadTypeSelectorIntent } from 'types/gallery';
import { Trans } from 'react-i18next';
import { t } from 'i18next';
-import { EnteLogo } from './EnteLogo';
+import { EnteLogo } from '@ente/shared/components/EnteLogo';
const Wrapper = styled(Box)`
display: flex;
diff --git a/apps/photos/src/components/MachineLearning/MlDebug-disabled.tsx b/apps/photos/src/components/MachineLearning/MlDebug-disabled.tsx
index 86405b3d23..e14569975d 100644
--- a/apps/photos/src/components/MachineLearning/MlDebug-disabled.tsx
+++ b/apps/photos/src/components/MachineLearning/MlDebug-disabled.tsx
@@ -5,7 +5,7 @@ export {};
// import { useRouter } from 'next/router';
// import { ComlinkWorker } from 'utils/comlink';
// import { AppContext } from 'pages/_app';
-// import { PAGES } from 'constants/pages';
+// import { PHOTOS_PAGES as PAGES } from '@ente/shared/constants/pages';
// import * as Comlink from 'comlink';
// import { runningInBrowser } from 'utils/common';
// import TFJSImage from './TFJSImage';
diff --git a/apps/photos/src/components/MemberSubscriptionManage.tsx b/apps/photos/src/components/MemberSubscriptionManage.tsx
index 0aef509295..add35315fe 100644
--- a/apps/photos/src/components/MemberSubscriptionManage.tsx
+++ b/apps/photos/src/components/MemberSubscriptionManage.tsx
@@ -5,7 +5,7 @@ import React, { useContext, useEffect } from 'react';
import billingService from 'services/billingService';
import { getFamilyPlanAdmin } from 'utils/user/family';
import { preloadImage } from 'utils/common';
-import DialogTitleWithCloseButton from './DialogBox/TitleWithCloseButton';
+import DialogTitleWithCloseButton from '@ente/shared/components/DialogBox/TitleWithCloseButton';
import { t } from 'i18next';
export function MemberSubscriptionManage({ open, userDetails, onClose }) {
diff --git a/apps/photos/src/components/Navbar/app.tsx b/apps/photos/src/components/Navbar/app.tsx
deleted file mode 100644
index 7a47a1e003..0000000000
--- a/apps/photos/src/components/Navbar/app.tsx
+++ /dev/null
@@ -1,14 +0,0 @@
-import { EnteLogo } from './../EnteLogo';
-import { CenteredFlex } from 'components/Container';
-import React from 'react';
-import NavbarBase from './base';
-
-export default function AppNavbar() {
- return (
- <NavbarBase>
- <CenteredFlex>
- <EnteLogo />
- </CenteredFlex>
- </NavbarBase>
- );
-}
diff --git a/apps/photos/src/components/PasswordStrength.tsx b/apps/photos/src/components/PasswordStrength.tsx
deleted file mode 100644
index 91c936687d..0000000000
--- a/apps/photos/src/components/PasswordStrength.tsx
+++ /dev/null
@@ -1,37 +0,0 @@
-import { Typography } from '@mui/material';
-import { PasswordStrength } from 'constants/crypto';
-import { useMemo } from 'react';
-import { t } from 'i18next';
-import { estimatePasswordStrength } from 'utils/crypto';
-import { FlexWrapper } from './Container';
-
-export const PasswordStrengthHint = ({
- password,
-}: {
- password: string;
-}): JSX.Element => {
- const passwordStrength = useMemo(
- () => estimatePasswordStrength(password),
- [password]
- );
- return (
- <FlexWrapper mt={'8px'} mb={'4px'}>
- <Typography
- variant="small"
- sx={(theme) => ({
- color:
- passwordStrength === PasswordStrength.WEAK
- ? theme.colors.danger.A700
- : passwordStrength === PasswordStrength.MODERATE
- ? theme.colors.warning.A500
- : theme.colors.accent.A500,
- })}
- textAlign={'left'}
- flex={1}>
- {password
- ? t('PASSPHRASE_STRENGTH', { context: passwordStrength })
- : ''}
- </Typography>
- </FlexWrapper>
- );
-};
diff --git a/apps/photos/src/components/PhotoFrame.tsx b/apps/photos/src/components/PhotoFrame.tsx
index 65e5da96d2..ebfca71568 100644
--- a/apps/photos/src/components/PhotoFrame.tsx
+++ b/apps/photos/src/components/PhotoFrame.tsx
@@ -16,7 +16,7 @@ import { useRouter } from 'next/router';
import { logError } from 'utils/sentry';
import { addLogLine } from 'utils/logging';
import PhotoSwipe from 'photoswipe';
-import useMemoSingleThreaded from 'hooks/useMemoSingleThreaded';
+import useMemoSingleThreaded from '@ente/shared/hooks/useMemoSingleThreaded';
import { getPlayableVideo } from 'utils/file';
import { FILE_TYPE } from 'constants/file';
diff --git a/apps/photos/src/components/PhotoViewer/FileInfo/ExifData.tsx b/apps/photos/src/components/PhotoViewer/FileInfo/ExifData.tsx
index b02e1bc9af..8aa1b4c74e 100644
--- a/apps/photos/src/components/PhotoViewer/FileInfo/ExifData.tsx
+++ b/apps/photos/src/components/PhotoViewer/FileInfo/ExifData.tsx
@@ -4,7 +4,7 @@ import { Stack, styled, Typography } from '@mui/material';
import { FileInfoSidebar } from '.';
import Titlebar from 'components/Titlebar';
import { Box } from '@mui/system';
-import CopyButton from 'components/CodeBlock/CopyButton';
+import CopyButton from '@ente/shared/components/CodeBlock/CopyButton';
import { formatDateTimeFull } from 'utils/time/format';
import { t } from 'i18next';
diff --git a/apps/photos/src/components/PhotoViewer/FileInfo/FileNameEditDialog.tsx b/apps/photos/src/components/PhotoViewer/FileInfo/FileNameEditDialog.tsx
index f7ab205bc6..6514060cb4 100644
--- a/apps/photos/src/components/PhotoViewer/FileInfo/FileNameEditDialog.tsx
+++ b/apps/photos/src/components/PhotoViewer/FileInfo/FileNameEditDialog.tsx
@@ -1,8 +1,8 @@
import SingleInputForm, {
SingleInputFormProps,
-} from 'components/SingleInputForm';
+} from '@ente/shared/components/SingleInputForm';
import { t } from 'i18next';
-import DialogBoxV2 from 'components/DialogBoxV2';
+import DialogBoxV2 from '@ente/shared/components/DialogBoxV2';
export const FileNameEditDialog = ({
isInEditMode,
diff --git a/apps/photos/src/components/PhotoViewer/FileInfo/index.tsx b/apps/photos/src/components/PhotoViewer/FileInfo/index.tsx
index b0a77f71fd..8e2a4ac865 100644
--- a/apps/photos/src/components/PhotoViewer/FileInfo/index.tsx
+++ b/apps/photos/src/components/PhotoViewer/FileInfo/index.tsx
@@ -4,13 +4,13 @@ import { RenderCreationTime } from './RenderCreationTime';
import { Box, DialogProps, Link, Stack, styled } from '@mui/material';
import { getEXIFLocation } from 'services/upload/exifService';
import { RenderCaption } from './RenderCaption';
-import CopyButton from 'components/CodeBlock/CopyButton';
+import CopyButton from '@ente/shared/components/CodeBlock/CopyButton';
import { formatDate, formatTime } from 'utils/time/format';
import Titlebar from 'components/Titlebar';
import MapBox from './MapBox';
import InfoItem from './InfoItem';
import { FlexWrapper } from 'components/Container';
-import EnteSpinner from 'components/EnteSpinner';
+import EnteSpinner from '@ente/shared/components/EnteSpinner';
import { EnteFile } from 'types/file';
import { Chip } from 'components/Chip';
import LinkButton from 'components/pages/gallery/LinkButton';
diff --git a/apps/photos/src/components/PhotoViewer/index.tsx b/apps/photos/src/components/PhotoViewer/index.tsx
index 2c948e2f05..cd75087d9b 100644
--- a/apps/photos/src/components/PhotoViewer/index.tsx
+++ b/apps/photos/src/components/PhotoViewer/index.tsx
@@ -51,7 +51,7 @@ import { GalleryContext } from 'pages/gallery';
import downloadManager from 'services/downloadManager';
import publicCollectionDownloadManager from 'services/publicCollectionDownloadManager';
import CircularProgressWithLabel from './styledComponents/CircularProgressWithLabel';
-import EnteSpinner from 'components/EnteSpinner';
+import EnteSpinner from '@ente/shared/components/EnteSpinner';
import AlbumOutlined from '@mui/icons-material/AlbumOutlined';
import { FlexWrapper } from 'components/Container';
import isElectron from 'is-electron';
diff --git a/apps/photos/src/components/PhotoViewer/styledComponents/SmallLoadingSpinner.tsx b/apps/photos/src/components/PhotoViewer/styledComponents/SmallLoadingSpinner.tsx
index 9a1b03e441..a73b7c0c8b 100644
--- a/apps/photos/src/components/PhotoViewer/styledComponents/SmallLoadingSpinner.tsx
+++ b/apps/photos/src/components/PhotoViewer/styledComponents/SmallLoadingSpinner.tsx
@@ -1,5 +1,5 @@
import React from 'react';
-import EnteSpinner from 'components/EnteSpinner';
+import EnteSpinner from '@ente/shared/components/EnteSpinner';
export const SmallLoadingSpinner = () => (
<EnteSpinner
diff --git a/apps/photos/src/components/RecoveryKey/index.tsx b/apps/photos/src/components/RecoveryKey/index.tsx
index 4194fa8422..d9552ca87e 100644
--- a/apps/photos/src/components/RecoveryKey/index.tsx
+++ b/apps/photos/src/components/RecoveryKey/index.tsx
@@ -1,7 +1,7 @@
import React, { useContext, useEffect, useState } from 'react';
import { downloadAsFile } from 'utils/file';
import { getRecoveryKey } from 'utils/crypto';
-import CodeBlock from '../CodeBlock';
+import CodeBlock from '@ente/shared/components/CodeBlock';
import {
Button,
Dialog,
@@ -12,7 +12,7 @@ import {
import * as bip39 from 'bip39';
import { DashedBorderWrapper } from './styledComponents';
import { AppContext } from 'pages/_app';
-import DialogTitleWithCloseButton from 'components/DialogBox/TitleWithCloseButton';
+import DialogTitleWithCloseButton from '@ente/shared/components/DialogBox/TitleWithCloseButton';
import { t } from 'i18next';
// mobile client library only supports english.
diff --git a/apps/photos/src/components/SetPasswordForm.tsx b/apps/photos/src/components/SetPasswordForm.tsx
deleted file mode 100644
index 14d0b66a51..0000000000
--- a/apps/photos/src/components/SetPasswordForm.tsx
+++ /dev/null
@@ -1,159 +0,0 @@
-import React, { useState } from 'react';
-import { Formik } from 'formik';
-import * as Yup from 'yup';
-import SubmitButton from './SubmitButton';
-import { Box, Input, TextField, Typography } from '@mui/material';
-import { PasswordStrengthHint } from './PasswordStrength';
-import { isWeakPassword } from 'utils/crypto';
-import { Trans } from 'react-i18next';
-import { t } from 'i18next';
-import ShowHidePassword from './Form/ShowHidePassword';
-
-export interface SetPasswordFormProps {
- userEmail: string;
- callback: (
- passphrase: string,
- setFieldError: (
- field: keyof SetPasswordFormValues,
- message: string
- ) => void
- ) => Promise<void>;
- buttonText: string;
-}
-export interface SetPasswordFormValues {
- passphrase: string;
- confirm: string;
-}
-function SetPasswordForm(props: SetPasswordFormProps) {
- const [loading, setLoading] = useState(false);
- const [showPassword, setShowPassword] = useState(false);
-
- const handleClickShowPassword = () => {
- setShowPassword(!showPassword);
- };
-
- const handleMouseDownPassword = (
- event: React.MouseEvent<HTMLButtonElement>
- ) => {
- event.preventDefault();
- };
-
- const onSubmit = async (
- values: SetPasswordFormValues,
- {
- setFieldError,
- }: {
- setFieldError: (
- field: keyof SetPasswordFormValues,
- message: string
- ) => void;
- }
- ) => {
- setLoading(true);
- try {
- const { passphrase, confirm } = values;
- if (passphrase === confirm) {
- await props.callback(passphrase, setFieldError);
- } else {
- setFieldError('confirm', t('PASSPHRASE_MATCH_ERROR'));
- }
- } catch (e) {
- setFieldError('confirm', `${t('UNKNOWN_ERROR')} ${e.message}`);
- } finally {
- setLoading(false);
- }
- };
-
- return (
- <Formik<SetPasswordFormValues>
- initialValues={{ passphrase: '', confirm: '' }}
- validationSchema={Yup.object().shape({
- passphrase: Yup.string().required(t('REQUIRED')),
- confirm: Yup.string().required(t('REQUIRED')),
- })}
- validateOnChange={false}
- validateOnBlur={false}
- onSubmit={onSubmit}>
- {({ values, errors, handleChange, handleSubmit }) => (
- <form noValidate onSubmit={handleSubmit}>
- <Typography mb={2} color="text.muted" variant="small">
- {t('ENTER_ENC_PASSPHRASE')}
- </Typography>
-
- <Input
- hidden
- name="email"
- id="email"
- autoComplete="username"
- type="email"
- value={props.userEmail}
- />
- <TextField
- fullWidth
- name="password"
- id="password"
- autoComplete="new-password"
- type={showPassword ? 'text' : 'password'}
- label={t('PASSPHRASE_HINT')}
- value={values.passphrase}
- onChange={handleChange('passphrase')}
- error={Boolean(errors.passphrase)}
- helperText={errors.passphrase}
- autoFocus
- disabled={loading}
- InputProps={{
- endAdornment: (
- <ShowHidePassword
- showPassword={showPassword}
- handleClickShowPassword={
- handleClickShowPassword
- }
- handleMouseDownPassword={
- handleMouseDownPassword
- }
- />
- ),
- }}
- />
- <TextField
- fullWidth
- name="confirm-password"
- id="confirm-password"
- autoComplete="new-password"
- type="password"
- label={t('CONFIRM_PASSPHRASE')}
- value={values.confirm}
- onChange={handleChange('confirm')}
- disabled={loading}
- error={Boolean(errors.confirm)}
- helperText={errors.confirm}
- />
- <PasswordStrengthHint password={values.passphrase} />
-
- <Typography my={2} variant="small">
- <Trans i18nKey={'PASSPHRASE_DISCLAIMER'} />
- </Typography>
-
- <Box my={4}>
- <SubmitButton
- sx={{ my: 0 }}
- loading={loading}
- buttonText={props.buttonText}
- disabled={isWeakPassword(values.passphrase)}
- />
- {loading && (
- <Typography
- textAlign="center"
- mt={1}
- color="text.muted"
- variant="small">
- {t('KEY_GENERATION_IN_PROGRESS_MESSAGE')}
- </Typography>
- )}
- </Box>
- </form>
- )}
- </Formik>
- );
-}
-export default SetPasswordForm;
diff --git a/apps/photos/src/components/Sidebar/Header.tsx b/apps/photos/src/components/Sidebar/Header.tsx
index aac152a049..836edaa4e2 100644
--- a/apps/photos/src/components/Sidebar/Header.tsx
+++ b/apps/photos/src/components/Sidebar/Header.tsx
@@ -2,7 +2,7 @@ import { IconButton } from '@mui/material';
import React from 'react';
import CloseIcon from '@mui/icons-material/Close';
import { SpaceBetweenFlex } from 'components/Container';
-import { EnteLogo } from 'components/EnteLogo';
+import { EnteLogo } from '@ente/shared/components/EnteLogo';
interface IProps {
closeSidebar: () => void;
diff --git a/apps/photos/src/components/Sidebar/HelpSection.tsx b/apps/photos/src/components/Sidebar/HelpSection.tsx
index dfc09980cd..d3d7ee6e77 100644
--- a/apps/photos/src/components/Sidebar/HelpSection.tsx
+++ b/apps/photos/src/components/Sidebar/HelpSection.tsx
@@ -4,7 +4,7 @@ import { t } from 'i18next';
import exportService from 'services/export';
import isElectron from 'is-electron';
import { AppContext } from 'pages/_app';
-import EnteSpinner from 'components/EnteSpinner';
+import EnteSpinner from '@ente/shared/components/EnteSpinner';
import { getDownloadAppMessage } from 'utils/ui';
import { NoStyleAnchor } from 'components/pages/sharedAlbum/GoToEnte';
import { openLink } from 'utils/common';
diff --git a/apps/photos/src/components/Sidebar/Preferences/LanguageSelector.tsx b/apps/photos/src/components/Sidebar/Preferences/LanguageSelector.tsx
index 11148a101e..95203c9d77 100644
--- a/apps/photos/src/components/Sidebar/Preferences/LanguageSelector.tsx
+++ b/apps/photos/src/components/Sidebar/Preferences/LanguageSelector.tsx
@@ -1,9 +1,9 @@
import DropdownInput, { DropdownOption } from 'components/DropdownInput';
-import { Language } from 'constants/locale';
-import { useLocalState } from 'hooks/useLocalState';
+import { Language } from '@ente/shared/i18n/locale';
+import { useLocalState } from '@ente/shared/hooks/useLocalState';
import { t } from 'i18next';
import { useRouter } from 'next/router';
-import { getBestPossibleUserLocale } from 'utils/i18n';
+import { getBestPossibleUserLocale } from '@ente/shared/i18n/utils';
import { LS_KEYS } from 'utils/storage/localStorage';
const getLocaleDisplayName = (l: Language) => {
diff --git a/apps/photos/src/components/Sidebar/Preferences/index.tsx b/apps/photos/src/components/Sidebar/Preferences/index.tsx
index 9f14d15a59..a7930487e7 100644
--- a/apps/photos/src/components/Sidebar/Preferences/index.tsx
+++ b/apps/photos/src/components/Sidebar/Preferences/index.tsx
@@ -11,7 +11,7 @@ import MapSettings from '../MapSetting';
import { LanguageSelector } from './LanguageSelector';
import { EnteMenuItem } from 'components/Menu/EnteMenuItem';
import { LS_KEYS } from 'utils/storage/localStorage';
-import { useLocalState } from 'hooks/useLocalState';
+import { useLocalState } from '@ente/shared/hooks/useLocalState';
import ElectronService from 'services/electron/common';
import InMemoryStore, { MS_KEYS } from 'services/InMemoryStore';
import { logError } from 'utils/sentry';
diff --git a/apps/photos/src/components/Sidebar/UtilitySection.tsx b/apps/photos/src/components/Sidebar/UtilitySection.tsx
index a7bbd345c0..adf4e9198f 100644
--- a/apps/photos/src/components/Sidebar/UtilitySection.tsx
+++ b/apps/photos/src/components/Sidebar/UtilitySection.tsx
@@ -4,7 +4,7 @@ import { t } from 'i18next';
// import FixLargeThumbnails from 'components/FixLargeThumbnail';
import RecoveryKey from 'components/RecoveryKey';
import TwoFactorModal from 'components/TwoFactor/Modal';
-import { PAGES } from 'constants/pages';
+import { PHOTOS_PAGES as PAGES } from '@ente/shared/constants/pages';
import { useRouter } from 'next/router';
import { AppContext } from 'pages/_app';
// import mlIDbStorage from 'utils/storage/mlIDbStorage';
@@ -15,8 +15,8 @@ import { getDownloadAppMessage } from 'utils/ui';
import { isInternalUser } from 'utils/user';
import Preferences from './Preferences';
import { EnteMenuItem } from 'components/Menu/EnteMenuItem';
-import ThemeSwitcher from './ThemeSwitcher';
-import { THEME_COLOR } from 'constants/theme';
+import ThemeSwitcher from '@ente/shared/components/ThemeSwitcher';
+import { THEME_COLOR } from '@ente/shared/themes/constants';
export default function UtilitySection({ closeSidebar }) {
const router = useRouter();
diff --git a/apps/photos/src/components/Sidebar/userDetailsSection.tsx b/apps/photos/src/components/Sidebar/userDetailsSection.tsx
index 965dedd5cb..4fb0559b23 100644
--- a/apps/photos/src/components/Sidebar/userDetailsSection.tsx
+++ b/apps/photos/src/components/Sidebar/userDetailsSection.tsx
@@ -3,7 +3,7 @@ import SubscriptionCard from './SubscriptionCard';
import { getUserDetailsV2 } from 'services/userService';
import { UserDetails } from 'types/user';
import { getData, LS_KEYS, setData } from 'utils/storage/localStorage';
-import { useLocalState } from 'hooks/useLocalState';
+import { useLocalState } from '@ente/shared/hooks/useLocalState';
import Typography from '@mui/material/Typography';
import SubscriptionStatus from './SubscriptionStatus';
import { Box, Skeleton } from '@mui/material';
diff --git a/apps/photos/src/components/SingleInputForm.tsx b/apps/photos/src/components/SingleInputForm.tsx
deleted file mode 100644
index 03be563c60..0000000000
--- a/apps/photos/src/components/SingleInputForm.tsx
+++ /dev/null
@@ -1,179 +0,0 @@
-import React, { useMemo, useState } from 'react';
-import { Formik, FormikHelpers, FormikState } from 'formik';
-import * as Yup from 'yup';
-import SubmitButton from './SubmitButton';
-import TextField from '@mui/material/TextField';
-import ShowHidePassword from './Form/ShowHidePassword';
-import { FlexWrapper } from './Container';
-import { Button, FormHelperText } from '@mui/material';
-import { t } from 'i18next';
-
-interface formValues {
- inputValue: string;
-}
-export interface SingleInputFormProps {
- callback: (
- inputValue: string,
- setFieldError: (errorMessage: string) => void,
- resetForm: (nextState?: Partial<FormikState<formValues>>) => void
- ) => Promise<void>;
- fieldType: 'text' | 'email' | 'password';
- placeholder: string;
- buttonText: string;
- submitButtonProps?: any;
- initialValue?: string;
- secondaryButtonAction?: () => void;
- disableAutoFocus?: boolean;
- hiddenPreInput?: any;
- caption?: any;
- hiddenPostInput?: any;
- autoComplete?: string;
- blockButton?: boolean;
- hiddenLabel?: boolean;
- disableAutoComplete?: boolean;
-}
-
-export default function SingleInputForm(props: SingleInputFormProps) {
- const { submitButtonProps } = props;
- const { sx: buttonSx, ...restSubmitButtonProps } = submitButtonProps ?? {};
-
- const [loading, SetLoading] = useState(false);
- const [showPassword, setShowPassword] = useState(false);
-
- const submitForm = async (
- values: formValues,
- { setFieldError, resetForm }: FormikHelpers<formValues>
- ) => {
- SetLoading(true);
- await props.callback(
- values.inputValue,
- (message) => setFieldError('inputValue', message),
- resetForm
- );
- SetLoading(false);
- };
-
- const handleClickShowPassword = () => {
- setShowPassword(!showPassword);
- };
-
- const handleMouseDownPassword = (
- event: React.MouseEvent<HTMLButtonElement>
- ) => {
- event.preventDefault();
- };
-
- const validationSchema = useMemo(() => {
- switch (props.fieldType) {
- case 'text':
- return Yup.object().shape({
- inputValue: Yup.string().required(t('REQUIRED')),
- });
- case 'password':
- return Yup.object().shape({
- inputValue: Yup.string().required(t('REQUIRED')),
- });
- case 'email':
- return Yup.object().shape({
- inputValue: Yup.string()
- .email(t('EMAIL_ERROR'))
- .required(t('REQUIRED')),
- });
- }
- }, [props.fieldType]);
-
- return (
- <Formik<formValues>
- initialValues={{ inputValue: props.initialValue ?? '' }}
- onSubmit={submitForm}
- validationSchema={validationSchema}
- validateOnChange={false}
- validateOnBlur={false}>
- {({ values, errors, handleChange, handleSubmit }) => (
- <form noValidate onSubmit={handleSubmit}>
- {props.hiddenPreInput}
- <TextField
- hiddenLabel={props.hiddenLabel}
- variant="filled"
- fullWidth
- type={showPassword ? 'text' : props.fieldType}
- id={props.fieldType}
- name={props.fieldType}
- {...(props.hiddenLabel
- ? { placeholder: props.placeholder }
- : { label: props.placeholder })}
- value={values.inputValue}
- onChange={handleChange('inputValue')}
- error={Boolean(errors.inputValue)}
- helperText={errors.inputValue}
- disabled={loading}
- autoFocus={!props.disableAutoFocus}
- autoComplete={props.autoComplete}
- InputProps={{
- autoComplete:
- props.disableAutoComplete ||
- props.fieldType === 'password'
- ? 'off'
- : 'on',
- endAdornment: props.fieldType === 'password' && (
- <ShowHidePassword
- showPassword={showPassword}
- handleClickShowPassword={
- handleClickShowPassword
- }
- handleMouseDownPassword={
- handleMouseDownPassword
- }
- />
- ),
- }}
- />
- <FormHelperText
- sx={{
- position: 'relative',
- top: errors.inputValue ? '-22px' : '0',
- float: 'right',
- padding: '0 8px',
- }}>
- {props.caption}
- </FormHelperText>
- {props.hiddenPostInput}
- <FlexWrapper
- justifyContent={'flex-end'}
- flexWrap={
- props.blockButton ? 'wrap-reverse' : 'nowrap'
- }>
- {props.secondaryButtonAction && (
- <Button
- onClick={props.secondaryButtonAction}
- size="large"
- color="secondary"
- sx={{
- '&&&': {
- mt: !props.blockButton ? 2 : 0.5,
- mb: !props.blockButton ? 4 : 0,
- mr: !props.blockButton ? 1 : 0,
- ...buttonSx,
- },
- }}
- {...restSubmitButtonProps}>
- {t('CANCEL')}
- </Button>
- )}
- <SubmitButton
- sx={{
- '&&&': {
- mt: 2,
- ...buttonSx,
- },
- }}
- buttonText={props.buttonText}
- loading={loading}
- {...restSubmitButtonProps}
- />
- </FlexWrapper>
- </form>
- )}
- </Formik>
- );
-}
diff --git a/apps/photos/src/components/SubmitButton.tsx b/apps/photos/src/components/SubmitButton.tsx
deleted file mode 100644
index fa6b37c694..0000000000
--- a/apps/photos/src/components/SubmitButton.tsx
+++ /dev/null
@@ -1,52 +0,0 @@
-import Done from '@mui/icons-material/Done';
-import { Button, ButtonProps, CircularProgress } from '@mui/material';
-import React, { FC } from 'react';
-
-export interface SubmitButtonProps {
- loading: boolean;
- buttonText: string;
-
- disabled?: boolean;
- success?: boolean;
-}
-const SubmitButton: FC<ButtonProps<'button', SubmitButtonProps>> = ({
- loading,
- buttonText,
- disabled,
- success,
- sx,
- ...props
-}) => {
- return (
- <Button
- size="large"
- variant="contained"
- color="accent"
- type="submit"
- disabled={disabled || loading || success}
- sx={{
- my: 4,
- ...(loading
- ? {
- '&.Mui-disabled': {
- backgroundColor: (theme) =>
- theme.colors.accent.A500,
- color: (theme) => theme.colors.text.base,
- },
- }
- : {}),
- ...sx,
- }}
- {...props}>
- {loading ? (
- <CircularProgress size={20} />
- ) : success ? (
- <Done sx={{ fontSize: 20 }} />
- ) : (
- buttonText
- )}
- </Button>
- );
-};
-
-export default SubmitButton;
diff --git a/apps/photos/src/components/TwoFactor/Modal/Manage.tsx b/apps/photos/src/components/TwoFactor/Modal/Manage.tsx
index 084ce6730c..1907342931 100644
--- a/apps/photos/src/components/TwoFactor/Modal/Manage.tsx
+++ b/apps/photos/src/components/TwoFactor/Modal/Manage.tsx
@@ -2,7 +2,7 @@ import React, { useContext } from 'react';
import { t } from 'i18next';
import { AppContext } from 'pages/_app';
-import { PAGES } from 'constants/pages';
+import { PHOTOS_PAGES as PAGES } from '@ente/shared/constants/pages';
import router from 'next/router';
import { disableTwoFactor } from '@ente/accounts/api/user';
import { setData, LS_KEYS, getData } from 'utils/storage/localStorage';
diff --git a/apps/photos/src/components/TwoFactor/Modal/Setup.tsx b/apps/photos/src/components/TwoFactor/Modal/Setup.tsx
index bdf6f93ee4..1170f933fc 100644
--- a/apps/photos/src/components/TwoFactor/Modal/Setup.tsx
+++ b/apps/photos/src/components/TwoFactor/Modal/Setup.tsx
@@ -1,6 +1,6 @@
import React from 'react';
import LockIcon from '@mui/icons-material/Lock';
-import { PAGES } from 'constants/pages';
+import { PHOTOS_PAGES as PAGES } from '@ente/shared/constants/pages';
import { useRouter } from 'next/router';
import { t } from 'i18next';
diff --git a/apps/photos/src/components/TwoFactor/Modal/index.tsx b/apps/photos/src/components/TwoFactor/Modal/index.tsx
index 88f8a5dc3f..9ad1f34005 100644
--- a/apps/photos/src/components/TwoFactor/Modal/index.tsx
+++ b/apps/photos/src/components/TwoFactor/Modal/index.tsx
@@ -7,7 +7,7 @@ import { t } from 'i18next';
import TwoFactorModalSetupSection from './Setup';
import TwoFactorModalManageSection from './Manage';
import { Dialog, DialogContent, styled } from '@mui/material';
-import DialogTitleWithCloseButton from 'components/DialogBox/TitleWithCloseButton';
+import DialogTitleWithCloseButton from '@ente/shared/components/DialogBox/TitleWithCloseButton';
const TwoFactorDialog = styled(Dialog)(({ theme }) => ({
'& .MuiDialogContent-root': {
diff --git a/apps/photos/src/components/Upload/UploadProgress/dialog.tsx b/apps/photos/src/components/Upload/UploadProgress/dialog.tsx
index 91c13529b6..0f5c5bc413 100644
--- a/apps/photos/src/components/Upload/UploadProgress/dialog.tsx
+++ b/apps/photos/src/components/Upload/UploadProgress/dialog.tsx
@@ -9,7 +9,7 @@ import { InProgressSection } from './inProgressSection';
import { ResultSection } from './resultSection';
import { NotUploadSectionHeader } from './styledComponents';
import UploadProgressContext from 'contexts/uploadProgress';
-import { dialogCloseHandler } from 'components/DialogBox/TitleWithCloseButton';
+import { dialogCloseHandler } from '@ente/shared/components/DialogBox/TitleWithCloseButton';
import { APP_DOWNLOAD_URL } from 'constants/urls';
import { Trans } from 'react-i18next';
diff --git a/apps/photos/src/components/Upload/UploadStrategyChoiceModal.tsx b/apps/photos/src/components/Upload/UploadStrategyChoiceModal.tsx
index 0d7f7a670a..78dba9a375 100644
--- a/apps/photos/src/components/Upload/UploadStrategyChoiceModal.tsx
+++ b/apps/photos/src/components/Upload/UploadStrategyChoiceModal.tsx
@@ -2,7 +2,7 @@ import { Button, Dialog, DialogContent, Typography } from '@mui/material';
import { CenteredFlex, SpaceBetweenFlex } from 'components/Container';
import DialogTitleWithCloseButton, {
dialogCloseHandler,
-} from 'components/DialogBox/TitleWithCloseButton';
+} from '@ente/shared/components/DialogBox/TitleWithCloseButton';
import React from 'react';
import { t } from 'i18next';
diff --git a/apps/photos/src/components/Upload/UploadTypeSelector/index.tsx b/apps/photos/src/components/Upload/UploadTypeSelector/index.tsx
index ec70cf74fc..63b94efd00 100644
--- a/apps/photos/src/components/Upload/UploadTypeSelector/index.tsx
+++ b/apps/photos/src/components/Upload/UploadTypeSelector/index.tsx
@@ -6,7 +6,7 @@ import { default as FolderUploadIcon } from '@mui/icons-material/PermMediaOutlin
import GoogleIcon from '@mui/icons-material/Google';
import DialogTitleWithCloseButton, {
dialogCloseHandler,
-} from 'components/DialogBox/TitleWithCloseButton';
+} from '@ente/shared/components/DialogBox/TitleWithCloseButton';
import { Box, Dialog, Stack, Typography } from '@mui/material';
import { PublicCollectionGalleryContext } from 'utils/publicCollectionGallery';
import { isMobileOrTable } from 'utils/common/deviceDetection';
diff --git a/apps/photos/src/components/UserNameInputDialog.tsx b/apps/photos/src/components/UserNameInputDialog.tsx
index 86e46bb2ed..358387e185 100644
--- a/apps/photos/src/components/UserNameInputDialog.tsx
+++ b/apps/photos/src/components/UserNameInputDialog.tsx
@@ -1,8 +1,8 @@
import React from 'react';
-import DialogBox from './DialogBox';
+import DialogBox from '@ente/shared/components/DialogBox/';
import AutoAwesomeOutlinedIcon from '@mui/icons-material/AutoAwesomeOutlined';
import { Typography } from '@mui/material';
-import SingleInputForm from './SingleInputForm';
+import SingleInputForm from '@ente/shared/components/SingleInputForm';
import { t } from 'i18next';
export default function UserNameInputDialog({
diff --git a/apps/photos/src/components/VerifyMasterPasswordForm.tsx b/apps/photos/src/components/VerifyMasterPasswordForm.tsx
deleted file mode 100644
index 39d30f068c..0000000000
--- a/apps/photos/src/components/VerifyMasterPasswordForm.tsx
+++ /dev/null
@@ -1,121 +0,0 @@
-import React from 'react';
-
-import SingleInputForm, {
- SingleInputFormProps,
-} from 'components/SingleInputForm';
-import { logError } from 'utils/sentry';
-import { CustomError } from 'utils/error';
-
-import { ButtonProps, Input } from '@mui/material';
-import { KeyAttributes, SRPAttributes, User } from 'types/user';
-import ComlinkCryptoWorker from 'utils/comlink/ComlinkCryptoWorker';
-import { t } from 'i18next';
-
-export interface VerifyMasterPasswordFormProps {
- user: User;
- keyAttributes: KeyAttributes;
- callback: (
- key: string,
- kek: string,
- keyAttributes: KeyAttributes,
- passphrase?: string
- ) => void;
- buttonText: string;
- submitButtonProps?: ButtonProps;
- getKeyAttributes?: (kek: string) => Promise<KeyAttributes>;
- srpAttributes?: SRPAttributes;
-}
-
-export default function VerifyMasterPasswordForm({
- user,
- keyAttributes,
- srpAttributes,
- callback,
- buttonText,
- submitButtonProps,
- getKeyAttributes,
-}: VerifyMasterPasswordFormProps) {
- const verifyPassphrase: SingleInputFormProps['callback'] = async (
- passphrase,
- setFieldError
- ) => {
- try {
- const cryptoWorker = await ComlinkCryptoWorker.getInstance();
- let kek: string = null;
- try {
- if (srpAttributes) {
- kek = await cryptoWorker.deriveKey(
- passphrase,
- srpAttributes.kekSalt,
- srpAttributes.opsLimit,
- srpAttributes.memLimit
- );
- } else {
- kek = await cryptoWorker.deriveKey(
- passphrase,
- keyAttributes.kekSalt,
- keyAttributes.opsLimit,
- keyAttributes.memLimit
- );
- }
- } catch (e) {
- logError(e, 'failed to derive key');
- throw Error(CustomError.WEAK_DEVICE);
- }
- if (!keyAttributes && typeof getKeyAttributes === 'function') {
- keyAttributes = await getKeyAttributes(kek);
- }
- if (!keyAttributes) {
- throw Error("couldn't get key attributes");
- }
- try {
- const key = await cryptoWorker.decryptB64(
- keyAttributes.encryptedKey,
- keyAttributes.keyDecryptionNonce,
- kek
- );
- callback(key, kek, keyAttributes, passphrase);
- } catch (e) {
- logError(e, 'user entered a wrong password');
- throw Error(CustomError.INCORRECT_PASSWORD);
- }
- } catch (e) {
- if (e.message === CustomError.TWO_FACTOR_ENABLED) {
- // two factor enabled, user has been redirected to two factor page
- return;
- }
- logError(e, 'failed to verify passphrase');
- switch (e.message) {
- case CustomError.WEAK_DEVICE:
- setFieldError(t('WEAK_DEVICE'));
- break;
- case CustomError.INCORRECT_PASSWORD:
- setFieldError(t('INCORRECT_PASSPHRASE'));
- break;
- default:
- setFieldError(`${t('UNKNOWN_ERROR')} ${e.message}`);
- }
- }
- };
-
- return (
- <SingleInputForm
- callback={verifyPassphrase}
- placeholder={t('RETURN_PASSPHRASE_HINT')}
- buttonText={buttonText}
- submitButtonProps={submitButtonProps}
- hiddenPreInput={
- <Input
- id="email"
- name="email"
- autoComplete="username"
- type="email"
- hidden
- value={user?.email}
- />
- }
- autoComplete={'current-password'}
- fieldType="password"
- />
- );
-}
diff --git a/apps/photos/src/components/WatchFolder/index.tsx b/apps/photos/src/components/WatchFolder/index.tsx
index 687ccc1028..fb7f2f38ca 100644
--- a/apps/photos/src/components/WatchFolder/index.tsx
+++ b/apps/photos/src/components/WatchFolder/index.tsx
@@ -6,7 +6,7 @@ import { WatchMapping } from 'types/watchFolder';
import { AppContext } from 'pages/_app';
import { t } from 'i18next';
-import DialogTitleWithCloseButton from 'components/DialogBox/TitleWithCloseButton';
+import DialogTitleWithCloseButton from '@ente/shared/components/DialogBox/TitleWithCloseButton';
import UploadStrategyChoiceModal from 'components/Upload/UploadStrategyChoiceModal';
import { UPLOAD_STRATEGY } from 'constants/upload';
import { getImportSuggestion } from 'utils/upload';
diff --git a/apps/photos/src/components/pages/auth/Navbar.tsx b/apps/photos/src/components/pages/auth/Navbar.tsx
index 5b386dc5ca..fe8d83c223 100644
--- a/apps/photos/src/components/pages/auth/Navbar.tsx
+++ b/apps/photos/src/components/pages/auth/Navbar.tsx
@@ -1,17 +1,19 @@
import { HorizontalFlex } from 'components/Container';
-import NavbarBase from 'components/Navbar/base';
+import NavbarBase from '@ente/shared/components/Navbar/base';
import React from 'react';
import { t } from 'i18next';
import { logoutUser } from '@ente/accounts/services/user';
-import { EnteLogo } from 'components/EnteLogo';
+import { EnteLogo } from '@ente/shared/components/EnteLogo';
import OverflowMenu from 'components/OverflowMenu/menu';
import { OverflowMenuOption } from 'components/OverflowMenu/option';
import MoreHoriz from '@mui/icons-material/MoreHoriz';
import LogoutOutlined from '@mui/icons-material/LogoutOutlined';
+import { AppContext } from 'pages/_app';
export default function AuthNavbar() {
+ const { isMobile } = React.useContext(AppContext);
return (
- <NavbarBase>
+ <NavbarBase isMobile={isMobile}>
<HorizontalFlex flex={1} justifyContent={'center'}>
<EnteLogo />
</HorizontalFlex>
diff --git a/apps/photos/src/components/pages/dedupe/SelectedFileOptions.tsx b/apps/photos/src/components/pages/dedupe/SelectedFileOptions.tsx
index 068e06153a..0bdc0fad1e 100644
--- a/apps/photos/src/components/pages/dedupe/SelectedFileOptions.tsx
+++ b/apps/photos/src/components/pages/dedupe/SelectedFileOptions.tsx
@@ -1,5 +1,5 @@
import { FluidContainer } from 'components/Container';
-import { SelectionBar } from '../../Navbar/SelectionBar';
+import { SelectionBar } from '@ente/shared/components/Navbar/SelectionBar';
import { useContext } from 'react';
import { Box, IconButton, Tooltip } from '@mui/material';
import { AppContext } from 'pages/_app';
@@ -23,13 +23,13 @@ export default function DeduplicateOptions({
count,
clearSelection,
}: IProps) {
- const { setDialogMessage } = useContext(AppContext);
+ const { setDialogMessage, isMobile } = useContext(AppContext);
const trashHandler = () =>
setDialogMessage(getTrashFilesMessage(deleteFileHelper));
return (
- <SelectionBar>
+ <SelectionBar isMobile={isMobile}>
<FluidContainer>
{count ? (
<IconButton onClick={clearSelection}>
diff --git a/apps/photos/src/components/pages/gallery/Navbar.tsx b/apps/photos/src/components/pages/gallery/Navbar.tsx
index ee5916f824..7af0c3b82d 100644
--- a/apps/photos/src/components/pages/gallery/Navbar.tsx
+++ b/apps/photos/src/components/pages/gallery/Navbar.tsx
@@ -1,6 +1,6 @@
import React from 'react';
-import NavbarBase from 'components/Navbar/base';
-import SidebarToggler from 'components/Navbar/SidebarToggler';
+import NavbarBase from '@ente/shared/components/Navbar/base';
+import SidebarToggler from '@ente/shared/components/Navbar/SidebarToggler';
import SearchBar from 'components/Search/SearchBar';
import { Collection } from 'types/collection';
import { EnteFile } from 'types/file';
@@ -10,6 +10,7 @@ import { IconButton, Typography } from '@mui/material';
import ArrowBack from '@mui/icons-material/ArrowBack';
import { FlexWrapper, HorizontalFlex } from 'components/Container';
import { t } from 'i18next';
+import { AppContext } from 'pages/_app';
interface Iprops {
openSidebar: () => void;
@@ -34,8 +35,11 @@ export function GalleryNavbar({
setIsInSearchMode,
exitHiddenSection,
}: Iprops) {
+ const appContext = React.useContext(AppContext);
return (
- <NavbarBase sx={{ background: 'transparent', position: 'absolute' }}>
+ <NavbarBase
+ sx={{ background: 'transparent', position: 'absolute' }}
+ isMobile={appContext.isMobile}>
{isInHiddenSection ? (
<HorizontalFlex
gap={'24px'}
diff --git a/apps/photos/src/components/pages/gallery/PlanSelector/card/index.tsx b/apps/photos/src/components/pages/gallery/PlanSelector/card/index.tsx
index 424f75aaaf..c3fc8893ac 100644
--- a/apps/photos/src/components/pages/gallery/PlanSelector/card/index.tsx
+++ b/apps/photos/src/components/pages/gallery/PlanSelector/card/index.tsx
@@ -19,7 +19,7 @@ import { SetLoading } from 'types/gallery';
import { logError } from 'utils/sentry';
import { AppContext } from 'pages/_app';
import { Link, Stack } from '@mui/material';
-import { useLocalState } from 'hooks/useLocalState';
+import { useLocalState } from '@ente/shared/hooks/useLocalState';
import { LS_KEYS } from 'utils/storage/localStorage';
import { getLocalUserDetails } from 'utils/user';
import { PLAN_PERIOD } from 'constants/gallery';
diff --git a/apps/photos/src/components/pages/gallery/PreviewCard.tsx b/apps/photos/src/components/pages/gallery/PreviewCard.tsx
index 44201c8215..566f31b142 100644
--- a/apps/photos/src/components/pages/gallery/PreviewCard.tsx
+++ b/apps/photos/src/components/pages/gallery/PreviewCard.tsx
@@ -3,7 +3,7 @@ import { EnteFile } from 'types/file';
import { styled } from '@mui/material';
import PlayCircleOutlineOutlinedIcon from '@mui/icons-material/PlayCircleOutlineOutlined';
import DownloadManager from 'services/downloadManager';
-import useLongPress from 'hooks/useLongPress';
+import useLongPress from '@ente/shared/hooks/useLongPress';
import { GalleryContext } from 'pages/gallery';
import { GAP_BTW_TILES, IMAGE_CONTAINER_MAX_WIDTH } from 'constants/gallery';
import { PublicCollectionGalleryContext } from 'utils/publicCollectionGallery';
diff --git a/apps/photos/src/components/pages/gallery/SelectedFileOptions.tsx b/apps/photos/src/components/pages/gallery/SelectedFileOptions.tsx
index 19f2d22bc8..697031f93f 100644
--- a/apps/photos/src/components/pages/gallery/SelectedFileOptions.tsx
+++ b/apps/photos/src/components/pages/gallery/SelectedFileOptions.tsx
@@ -10,7 +10,7 @@ import {
ARCHIVE_SECTION,
TRASH_SECTION,
} from 'constants/collection';
-import { SelectionBar } from '../../Navbar/SelectionBar';
+import { SelectionBar } from '@ente/shared/components/Navbar/SelectionBar';
import { AppContext } from 'pages/_app';
import { Box, IconButton, Stack, Tooltip } from '@mui/material';
import CloseIcon from '@mui/icons-material/Close';
@@ -66,7 +66,7 @@ const SelectedFileOptions = ({
isInSearchMode,
isInHiddenSection,
}: Props) => {
- const { setDialogMessage } = useContext(AppContext);
+ const { setDialogMessage, isMobile } = useContext(AppContext);
const addToCollection = () =>
setCollectionSelectorAttributes({
callback: handleCollectionOps(COLLECTION_OPS_TYPE.ADD),
@@ -155,7 +155,7 @@ const SelectedFileOptions = ({
};
return (
- <SelectionBar>
+ <SelectionBar isMobile={isMobile}>
<FluidContainer>
<IconButton onClick={clearSelection}>
<CloseIcon />
diff --git a/apps/photos/src/components/pages/sharedAlbum/Navbar.tsx b/apps/photos/src/components/pages/sharedAlbum/Navbar.tsx
index a11fcfda3b..25513e3995 100644
--- a/apps/photos/src/components/pages/sharedAlbum/Navbar.tsx
+++ b/apps/photos/src/components/pages/sharedAlbum/Navbar.tsx
@@ -1,15 +1,17 @@
-import { EnteLinkLogo } from 'components/Navbar/EnteLinkLogo';
+import { EnteLinkLogo } from '@ente/shared/components/Navbar/EnteLinkLogo';
import { FluidContainer } from 'components/Container';
-import NavbarBase from 'components/Navbar/base';
+import NavbarBase from '@ente/shared/components/Navbar/base';
import UploadButton from 'components/Upload/UploadButton';
-import React from 'react';
+import React, { useContext } from 'react';
import GoToEnte from './GoToEnte';
import { t } from 'i18next';
import AddPhotoAlternateOutlined from '@mui/icons-material/AddPhotoAlternateOutlined';
+import { AppContext } from 'pages/_app';
export default function SharedAlbumNavbar({ showUploadButton, openUploader }) {
+ const { isMobile } = useContext(AppContext);
return (
- <NavbarBase>
+ <NavbarBase isMobile={isMobile}>
<FluidContainer>
<EnteLinkLogo />
</FluidContainer>
diff --git a/apps/photos/src/constants/apps.ts b/apps/photos/src/constants/apps.ts
deleted file mode 100644
index 79e4e12322..0000000000
--- a/apps/photos/src/constants/apps.ts
+++ /dev/null
@@ -1,59 +0,0 @@
-import { PAGES } from 'constants/pages';
-import { runningInBrowser } from 'utils/common';
-import { getAlbumsURL, getAuthURL } from 'utils/common/apiUtil';
-
-export enum APPS {
- PHOTOS = 'PHOTOS',
- AUTH = 'AUTH',
- ALBUMS = 'ALBUMS',
-}
-
-export const ALLOWED_APP_PAGES = new Map([
- [APPS.ALBUMS, [PAGES.SHARED_ALBUMS, PAGES.ROOT]],
- [
- APPS.AUTH,
- [
- PAGES.ROOT,
- PAGES.LOGIN,
- PAGES.SIGNUP,
- PAGES.VERIFY,
- PAGES.CREDENTIALS,
- PAGES.RECOVER,
- PAGES.CHANGE_PASSWORD,
- PAGES.GENERATE,
- PAGES.AUTH,
- PAGES.TWO_FACTOR_VERIFY,
- PAGES.TWO_FACTOR_RECOVER,
- ],
- ],
-]);
-
-export const CLIENT_PACKAGE_NAMES = new Map([
- [APPS.ALBUMS, 'io.ente.albums.web'],
- [APPS.PHOTOS, 'io.ente.photos.web'],
- [APPS.AUTH, 'io.ente.auth.web'],
-]);
-
-export const getAppNameAndTitle = () => {
- if (!runningInBrowser()) {
- return {};
- }
- const currentURL = new URL(window.location.href);
- const albumsURL = new URL(getAlbumsURL());
- const authURL = new URL(getAuthURL());
- if (currentURL.origin === albumsURL.origin) {
- return { name: APPS.ALBUMS, title: 'ente Photos' };
- } else if (currentURL.origin === authURL.origin) {
- return { name: APPS.AUTH, title: 'ente Auth' };
- } else {
- return { name: APPS.PHOTOS, title: 'ente Photos' };
- }
-};
-
-export const getAppTitle = () => {
- return getAppNameAndTitle().title;
-};
-
-export const getAppName = () => {
- return getAppNameAndTitle().name;
-};
diff --git a/apps/photos/src/pages/404.tsx b/apps/photos/src/pages/404.tsx
index 8ec92cb842..4eb0ad5121 100644
--- a/apps/photos/src/pages/404.tsx
+++ b/apps/photos/src/pages/404.tsx
@@ -3,7 +3,7 @@ import React, { useContext, useEffect, useState } from 'react';
import { t } from 'i18next';
import { AppContext } from './_app';
-import EnteSpinner from 'components/EnteSpinner';
+import EnteSpinner from '@ente/shared/components/EnteSpinner';
export default function NotFound() {
const appContext = useContext(AppContext);
diff --git a/apps/photos/src/pages/_app.tsx b/apps/photos/src/pages/_app.tsx
index 2938ec5efb..0c27c5f7d5 100644
--- a/apps/photos/src/pages/_app.tsx
+++ b/apps/photos/src/pages/_app.tsx
@@ -1,22 +1,16 @@
-import React, {
- createContext,
- useEffect,
- useMemo,
- useRef,
- useState,
-} from 'react';
-import AppNavbar from 'components/Navbar/app';
+import React, { createContext, useEffect, useRef, useState } from 'react';
+import AppNavbar from '@ente/shared/components/Navbar/app';
import { t } from 'i18next';
import { useRouter } from 'next/router';
-import { Overlay } from 'components/Container';
+import { Overlay } from '@ente/shared/components/Container';
import 'bootstrap/dist/css/bootstrap.min.css';
import 'photoswipe/dist/photoswipe.css';
import 'styles/global.css';
-import EnteSpinner from 'components/EnteSpinner';
-import { logError } from '../utils/sentry';
-import { getData, LS_KEYS } from 'utils/storage/localStorage';
-import HTTPService from 'services/HTTPService';
+import EnteSpinner from '@ente/shared/components/EnteSpinner';
+import { logError } from '@ente/shared/sentry';
+import { getData, LS_KEYS } from '@ente/shared/storage/localStorage';
+import HTTPService from '@ente/shared/network/HTTPService';
import Head from 'next/head';
import { eventBus, Events } from 'services/events';
import mlWorkManager from 'services/machineLearning/mlWorkManager';
@@ -25,26 +19,27 @@ import {
updateMLSearchConfig,
} from 'utils/machineLearning/config';
import LoadingBar from 'react-top-loading-bar';
-import DialogBox from 'components/DialogBox';
+import DialogBox from '@ente/shared/components/DialogBox';
+import DialogBoxV2 from '@ente/shared/components/DialogBoxV2';
import { ThemeProvider } from '@mui/material/styles';
import { MessageContainer } from '@ente/shared/components/MessageContainer';
import { CssBaseline, useMediaQuery } from '@mui/material';
import {
SetDialogBoxAttributes,
DialogBoxAttributes,
+} from '@ente/shared/components/DialogBox/types';
+import {
DialogBoxAttributesV2,
SetDialogBoxAttributesV2,
-} from 'types/dialogBox';
+} from '@ente/shared/components/DialogBoxV2/types';
import {
getFamilyPortalRedirectURL,
getRoadmapRedirectURL,
updateMapEnabledStatus,
} from 'services/userService';
-import { CustomError } from 'utils/error';
-import {
- addLogLine,
- clearLogsIfLocalStorageLimitExceeded,
-} from 'utils/logging';
+import { CustomError } from '@ente/shared/error';
+import { addLogLine } from '@ente/shared/logging';
+import { clearLogsIfLocalStorageLimitExceeded } from '@ente/shared/logging/web';
import isElectron from 'is-electron';
import ElectronUpdateService from 'services/electron/update';
import {
@@ -58,28 +53,29 @@ import {
} from 'types/Notification';
import ArrowForward from '@mui/icons-material/ArrowForward';
import { AppUpdateInfo } from 'types/electron';
-import { getSentryUserID } from 'utils/user';
-import { User } from 'types/user';
-import { SetTheme } from 'types/theme';
-import { useLocalState } from 'hooks/useLocalState';
-import { THEME_COLOR } from 'constants/theme';
-import { setupI18n } from 'i18n';
-import createEmotionCache from 'themes/createEmotionCache';
-import { CacheProvider, EmotionCache } from '@emotion/react';
-import { AppProps } from 'next/app';
-import DialogBoxV2 from 'components/DialogBoxV2';
-import { getTheme } from 'themes';
-import { PAGES } from 'constants/pages';
+import { CacheProvider } from '@emotion/react';
import {
- ALLOWED_APP_PAGES,
+ APP_TITLES,
APPS,
CLIENT_PACKAGE_NAMES,
- getAppNameAndTitle,
-} from 'constants/apps';
+} from '@ente/shared/apps/constants';
import exportService from 'services/export';
import { REDIRECTS } from 'constants/redirects';
-import { getLocalMapEnabled, setLocalMapEnabled } from 'utils/storage';
+import {
+ getLocalMapEnabled,
+ setLocalMapEnabled,
+} from '@ente/shared/storage/localStorage/helpers';
import { isExportInProgress } from 'utils/export';
+import { EnteAppProps } from '@ente/shared/apps/types';
+import createEmotionCache from '@ente/shared/themes/createEmotionCache';
+import { THEME_COLOR } from '@ente/shared/themes/constants';
+import { SetTheme } from '@ente/shared/themes/types';
+import { setupI18n } from '@ente/shared/i18n';
+import { getSentryUserID } from '@ente/shared/sentry/utils';
+import { User } from '@ente/shared/user/types';
+import { useLocalState } from '@ente/shared/hooks/useLocalState';
+import { PHOTOS_PAGES as PAGES } from '@ente/shared/constants/pages';
+import { getTheme } from '@ente/shared/themes';
const redirectMap = new Map([
[REDIRECTS.ROADMAP, getRoadmapRedirectURL],
@@ -117,11 +113,7 @@ export const AppContext = createContext<AppContextType>(null);
// Client-side cache, shared for the whole session of the user in the browser.
const clientSideEmotionCache = createEmotionCache();
-export interface EnteAppProps extends AppProps {
- emotionCache?: EmotionCache;
-}
-
-export default function App(props) {
+export default function App(props: EnteAppProps) {
const {
Component,
emotionCache = clientSideEmotionCache,
@@ -159,24 +151,14 @@ export default function App(props) {
THEME_COLOR.DARK
);
- const { name: appName, title: appTitle } = useMemo(() => {
- return getAppNameAndTitle();
- }, []);
-
useEffect(() => {
+ //setup i18n
setupI18n().finally(() => setIsI18nReady(true));
- }, []);
-
- useEffect(() => {
- if (!appName) {
- return;
- }
+ // set client package name in headers
HTTPService.setHeaders({
- 'X-Client-Package': CLIENT_PACKAGE_NAMES.get(appName),
+ 'X-Client-Package': CLIENT_PACKAGE_NAMES.get(APPS.PHOTOS),
});
- }, [appName]);
-
- useEffect(() => {
+ // setup logging
clearLogsIfLocalStorageLimitExceeded();
const main = async () => {
addLogLine(`userID: ${(getData(LS_KEYS.USER) as User)?.id}`);
@@ -318,20 +300,6 @@ export default function App(props) {
setLoading(true);
}
- if (
- appName === APPS.ALBUMS &&
- ALLOWED_APP_PAGES.get(APPS.ALBUMS).indexOf(newPathname) === -1
- ) {
- router.replace(PAGES.SHARED_ALBUMS);
- throw `Aborting route change, changing page ${newPathname} is not allowed for ${appName}`;
- } else if (
- appName === APPS.AUTH &&
- ALLOWED_APP_PAGES.get(APPS.AUTH).indexOf(newPathname) === -1
- ) {
- router.replace(PAGES.AUTH);
- throw `Aborting route change, changing page ${newPathname} is not allowed for ${appName}`;
- }
-
if (redirectName) {
const user = getData(LS_KEYS.USER);
if (user?.token) {
@@ -355,7 +323,7 @@ export default function App(props) {
window.removeEventListener('online', setUserOnline);
window.removeEventListener('offline', setUserOffline);
};
- }, [redirectName, appName]);
+ }, [redirectName]);
useEffect(() => {
setMessageDialogView(true);
@@ -417,7 +385,9 @@ export default function App(props) {
<CacheProvider value={emotionCache}>
<Head>
<title>
- {isI18nReady ? t('TITLE', { context: appName }) : appTitle}
+ {isI18nReady
+ ? t('TITLE', { context: APPS.PHOTOS })
+ : APP_TITLES.get(APPS.PHOTOS)}
</title>
<meta
name="viewport"
@@ -425,9 +395,9 @@ export default function App(props) {
/>
</Head>
- <ThemeProvider theme={getTheme(themeColor, appName)}>
+ <ThemeProvider theme={getTheme(themeColor, APPS.PHOTOS)}>
<CssBaseline enableColorScheme />
- {showNavbar && <AppNavbar />}
+ {showNavbar && <AppNavbar isMobile={isMobile} />}
<MessageContainer>
{offline && t('OFFLINE_MSG')}
</MessageContainer>
diff --git a/apps/photos/src/pages/_document.tsx b/apps/photos/src/pages/_document.tsx
index 3c9cbe54e5..97085e2b32 100644
--- a/apps/photos/src/pages/_document.tsx
+++ b/apps/photos/src/pages/_document.tsx
@@ -10,8 +10,8 @@ import Document, {
import createEmotionServer from '@emotion/server/create-instance';
import { AppType } from 'next/app';
-import createEmotionCache from 'themes/createEmotionCache';
-import { EnteAppProps } from './_app';
+import createEmotionCache from '@ente/shared/themes/createEmotionCache';
+import { EnteAppProps } from '@ente/shared/apps/types';
interface EnteDocumentProps extends DocumentProps {
emotionStyleTags: JSX.Element[];
diff --git a/apps/photos/src/pages/auth/index.tsx b/apps/photos/src/pages/auth/index.tsx
index 8f139d3a9c..0f49930288 100644
--- a/apps/photos/src/pages/auth/index.tsx
+++ b/apps/photos/src/pages/auth/index.tsx
@@ -2,14 +2,14 @@ import React, { useContext, useEffect, useState } from 'react';
import OTPDisplay from 'components/Authenicator/OTPDisplay';
import { getAuthCodes } from 'services/authenticator/authenticatorService';
import { CustomError } from 'utils/error';
-import { PAGES } from 'constants/pages';
+import { PHOTOS_PAGES as PAGES } from '@ente/shared/constants/pages';
import { useRouter } from 'next/router';
import { AuthFooter } from 'components/Authenicator/AuthFooter';
import { AppContext } from 'pages/_app';
import { TextField } from '@mui/material';
import AuthNavbar from 'components/pages/auth/Navbar';
import { t } from 'i18next';
-import EnteSpinner from 'components/EnteSpinner';
+import EnteSpinner from '@ente/shared/components/EnteSpinner';
import { VerticallyCentered } from 'components/Container';
import InMemoryStore, { MS_KEYS } from 'services/InMemoryStore';
diff --git a/apps/photos/src/pages/deduplicate/index.tsx b/apps/photos/src/pages/deduplicate/index.tsx
index b6405078cd..f4128bb27f 100644
--- a/apps/photos/src/pages/deduplicate/index.tsx
+++ b/apps/photos/src/pages/deduplicate/index.tsx
@@ -20,15 +20,15 @@ import {
} from 'types/deduplicate';
import Router from 'next/router';
import DeduplicateOptions from 'components/pages/dedupe/SelectedFileOptions';
-import { PAGES } from 'constants/pages';
+import { PHOTOS_PAGES as PAGES } from '@ente/shared/constants/pages';
import router from 'next/router';
import { getKey, SESSION_KEYS } from 'utils/storage/sessionStorage';
import { styled } from '@mui/material';
import { getLatestCollections } from 'services/collectionService';
-import EnteSpinner from 'components/EnteSpinner';
+import EnteSpinner from '@ente/shared/components/EnteSpinner';
import { VerticallyCentered } from 'components/Container';
import Typography from '@mui/material/Typography';
-import useMemoSingleThreaded from 'hooks/useMemoSingleThreaded';
+import useMemoSingleThreaded from '@ente/shared/hooks/useMemoSingleThreaded';
import InMemoryStore, { MS_KEYS } from 'services/InMemoryStore';
import { HttpStatusCode } from 'axios';
diff --git a/apps/photos/src/pages/gallery/index.tsx b/apps/photos/src/pages/gallery/index.tsx
index 29d275eeb0..0c06ad180f 100644
--- a/apps/photos/src/pages/gallery/index.tsx
+++ b/apps/photos/src/pages/gallery/index.tsx
@@ -39,7 +39,7 @@ import {
validateKey,
} from 'services/userService';
import { useDropzone } from 'react-dropzone';
-import EnteSpinner from 'components/EnteSpinner';
+import EnteSpinner from '@ente/shared/components/EnteSpinner';
import { LoadingOverlay } from 'components/LoadingOverlay';
import PhotoFrame from 'components/PhotoFrame';
import {
@@ -71,7 +71,7 @@ import {
} from 'constants/collection';
import { AppContext } from 'pages/_app';
import { CustomError } from 'utils/error';
-import { PAGES } from 'constants/pages';
+import { PHOTOS_PAGES as PAGES } from '@ente/shared/constants/pages';
import {
COLLECTION_OPS_TYPE,
handleCollectionOps,
@@ -101,7 +101,7 @@ import { Search, SearchResultSummary, UpdateSearch } from 'types/search';
import SearchResultInfo from 'components/Search/SearchResultInfo';
import { ITEM_TYPE, TimeStampListItem } from 'components/PhotoList';
import UploadInputs from 'components/UploadSelectorInputs';
-import useFileInput from 'hooks/useFileInput';
+import useFileInput from '@ente/shared/hooks/useFileInput';
import { FamilyData, User } from 'types/user';
import { getData, LS_KEYS } from 'utils/storage/localStorage';
import { CenteredFlex } from 'components/Container';
@@ -113,7 +113,7 @@ import { getToken } from 'utils/common/key';
import ExportModal from 'components/ExportModal';
import GalleryEmptyState from 'components/GalleryEmptyState';
import AuthenticateUserModal from 'components/AuthenticateUserModal';
-import useMemoSingleThreaded from 'hooks/useMemoSingleThreaded';
+import useMemoSingleThreaded from '@ente/shared/hooks/useMemoSingleThreaded';
import { isArchivedFile } from 'utils/magicMetadata';
import { isSameDayAnyYear, isInsideLocationTag } from 'utils/search';
import { getSessionExpiredMessage } from 'utils/ui';
diff --git a/apps/photos/src/pages/index.tsx b/apps/photos/src/pages/index.tsx
index 93501dc219..97848f89f1 100644
--- a/apps/photos/src/pages/index.tsx
+++ b/apps/photos/src/pages/index.tsx
@@ -6,20 +6,20 @@ import Login from '@ente/accounts/components/Login';
import { useRouter } from 'next/router';
import { getData, LS_KEYS } from 'utils/storage/localStorage';
import SignUp from '@ente/accounts/components/SignUp';
-import EnteSpinner from 'components/EnteSpinner';
+import EnteSpinner from '@ente/shared/components/EnteSpinner';
import { t } from 'i18next';
import localForage from 'utils/storage/localForage';
import { logError } from 'utils/sentry';
-import { PAGES } from 'constants/pages';
-import { EnteLogo } from 'components/EnteLogo';
+import { PHOTOS_PAGES as PAGES } from '@ente/shared/constants/pages';
+import { EnteLogo } from '@ente/shared/components/EnteLogo';
import isElectron from 'is-electron';
import safeStorageService from 'services/electron/safeStorage';
import { saveKeyInSessionStore } from 'utils/crypto';
import { getKey, SESSION_KEYS } from 'utils/storage/sessionStorage';
import { getAlbumsURL } from 'utils/common/apiUtil';
import { Trans } from 'react-i18next';
-import { APPS, getAppName } from 'constants/apps';
+import { APPS } from '@ente/shared/apps/constants';
const Container = styled('div')`
display: flex;
@@ -129,7 +129,6 @@ export default function LandingPage() {
};
const handleNormalRedirect = async () => {
- const appName = getAppName();
const user = getData(LS_KEYS.USER);
let key = getKey(SESSION_KEYS.ENCRYPTION_KEY);
if (!key && isElectron()) {
@@ -143,17 +142,17 @@ export default function LandingPage() {
}
}
if (key) {
- if (appName === APPS.AUTH) {
- await router.push(PAGES.AUTH);
- } else {
- await router.push(PAGES.GALLERY);
- }
+ // if (appName === APPS.AUTH) {
+ // await router.push(PAGES.AUTH);
+ // } else {
+ await router.push(PAGES.GALLERY);
+ // }
} else if (user?.email) {
await router.push(PAGES.VERIFY);
} else {
- if (appName === APPS.AUTH) {
- await router.push(PAGES.LOGIN);
- }
+ // if (appName === APPS.AUTH) {
+ // await router.push(PAGES.LOGIN);
+ // }
}
await initLocalForage();
setLoading(false);
diff --git a/apps/photos/src/pages/shared-albums/index.tsx b/apps/photos/src/pages/shared-albums/index.tsx
index 2805adf8a0..877d155630 100644
--- a/apps/photos/src/pages/shared-albums/index.tsx
+++ b/apps/photos/src/pages/shared-albums/index.tsx
@@ -27,24 +27,24 @@ import {
} from 'components/Container';
import { t } from 'i18next';
-import EnteSpinner from 'components/EnteSpinner';
-import { PAGES } from 'constants/pages';
+import EnteSpinner from '@ente/shared/components/EnteSpinner';
+import { PHOTOS_PAGES as PAGES } from '@ente/shared/constants/pages';
import { useRouter } from 'next/router';
import SingleInputForm, {
SingleInputFormProps,
-} from 'components/SingleInputForm';
+} from '@ente/shared/components/SingleInputForm';
import { logError } from 'utils/sentry';
import SharedAlbumNavbar from 'components/pages/sharedAlbum/Navbar';
import { CollectionInfo } from 'components/Collections/CollectionInfo';
import { CollectionInfoBarWrapper } from 'components/Collections/styledComponents';
import { ITEM_TYPE, TimeStampListItem } from 'components/PhotoList';
-import FormPaper from 'components/Form/FormPaper';
-import FormPaperTitle from 'components/Form/FormPaper/Title';
+import FormPaper from '@ente/shared/components/Form/FormPaper';
+import FormPaperTitle from '@ente/shared/components/Form/FormPaper/Title';
import Typography from '@mui/material/Typography';
import Uploader from 'components/Upload/Uploader';
import { LoadingOverlay } from 'components/LoadingOverlay';
import FullScreenDropZone from 'components/FullScreenDropZone';
-import useFileInput from 'hooks/useFileInput';
+import useFileInput from '@ente/shared/hooks/useFileInput';
import { useDropzone } from 'react-dropzone';
import UploadSelectorInputs from 'components/UploadSelectorInputs';
import { logoutUser } from '@ente/accounts/services/user';
diff --git a/apps/photos/src/utils/storage/index.ts b/apps/photos/src/utils/storage/index.ts
index 87e858d43c..d159f82155 100644
--- a/apps/photos/src/utils/storage/index.ts
+++ b/apps/photos/src/utils/storage/index.ts
@@ -1,4 +1,4 @@
-import { Language } from 'constants/locale';
+import { Language } from '@ente/shared/i18n/locale';
import { getData, LS_KEYS, setData } from './localStorage';
export const isFirstLogin = () =>
diff --git a/apps/photos/tsconfig.json b/apps/photos/tsconfig.json
index 9eb9375675..d9092609dc 100644
--- a/apps/photos/tsconfig.json
+++ b/apps/photos/tsconfig.json
@@ -18,7 +18,7 @@
"**/*.ts",
"**/*.tsx",
"**/*.js",
- "../../packages/shared/theme/mui-theme.d.ts"
+ "../../packages/shared/themes/mui-theme.d.ts"
],
"exclude": ["node_modules", "out", ".next", "thirdparty"]
}
diff --git a/packages/accounts/package.json b/packages/accounts/package.json
index 35436ca3eb..ee1d88c689 100644
--- a/packages/accounts/package.json
+++ b/packages/accounts/package.json
@@ -1,6 +1,7 @@
{
"name": "@ente/accounts",
"version": "0.0.0",
+ "private": true,
"scripts": {
"lint": "eslint .",
"build": "yarn lint && tsc"
diff --git a/packages/accounts/tsconfig.json b/packages/accounts/tsconfig.json
index c683c0756d..bf522b090f 100644
--- a/packages/accounts/tsconfig.json
+++ b/packages/accounts/tsconfig.json
@@ -16,6 +16,6 @@
"**/*.ts",
"**/*.tsx",
"**/*.js",
- "../shared/theme/mui-theme.d.ts"
+ "../shared/themes/mui-theme.d.ts"
]
}
diff --git a/packages/eslint-config/package.json b/packages/eslint-config/package.json
index c73f8a7771..3835b87823 100644
--- a/packages/eslint-config/package.json
+++ b/packages/eslint-config/package.json
@@ -7,7 +7,9 @@
"parser": "babel-eslint"
},
"devDependencies": {
+ "@typescript-eslint/parser": "^5.59.2",
"@typescript-eslint/eslint-plugin": "^5.43.0",
+ "eslint": "latest",
"eslint-config-next": "latest",
"eslint-config-prettier": "latest",
"eslint-config-turbo": "latest",
diff --git a/packages/shared/apps/constants.ts b/packages/shared/apps/constants.ts
index b3d44d1011..8fc3514fc2 100644
--- a/packages/shared/apps/constants.ts
+++ b/packages/shared/apps/constants.ts
@@ -14,52 +14,14 @@ export enum APP_ENV {
TEST = 'test',
}
-// export const ALLOWED_APP_PAGES = new Map([
-// [APPS.ALBUMS, [PAGES.SHARED_ALBUMS, PAGES.ROOT]],
-// [
-// APPS.AUTH,
-// [
-// PAGES.ROOT,
-// PAGES.LOGIN,
-// PAGES.SIGNUP,
-// PAGES.VERIFY,
-// PAGES.CREDENTIALS,
-// PAGES.RECOVER,
-// PAGES.CHANGE_PASSWORD,
-// PAGES.GENERATE,
-// PAGES.AUTH,
-// PAGES.TWO_FACTOR_VERIFY,
-// PAGES.TWO_FACTOR_RECOVER,
-// ],
-// ],
-// ]);
+export const CLIENT_PACKAGE_NAMES = new Map([
+ [APPS.ALBUMS, 'io.ente.albums.web'],
+ [APPS.PHOTOS, 'io.ente.photos.web'],
+ [APPS.AUTH, 'io.ente.auth.web'],
+]);
-// export const CLIENT_PACKAGE_NAMES = new Map([
-// [APPS.ALBUMS, 'io.ente.albums.web'],
-// [APPS.PHOTOS, 'io.ente.photos.web'],
-// [APPS.AUTH, 'io.ente.auth.web'],
-// ]);
-
-// export const getAppNameAndTitle = () => {
-// if (!runningInBrowser()) {
-// return {};
-// }
-// const currentURL = new URL(window.location.href);
-// const albumsURL = new URL(getAlbumsURL());
-// const authURL = new URL(getAuthURL());
-// if (currentURL.origin === albumsURL.origin) {
-// return { name: APPS.ALBUMS, title: 'ente Photos' };
-// } else if (currentURL.origin === authURL.origin) {
-// return { name: APPS.AUTH, title: 'ente Auth' };
-// } else {
-// return { name: APPS.PHOTOS, title: 'ente Photos' };
-// }
-// };
-
-// export const getAppTitle = () => {
-// return getAppNameAndTitle().title;
-// };
-
-// export const getAppName = () => {
-// return getAppNameAndTitle().name;
-// };
+export const APP_TITLES = new Map([
+ [APPS.ALBUMS, 'Albums'],
+ [APPS.PHOTOS, 'Photos'],
+ [APPS.AUTH, 'Auth'],
+]);
diff --git a/packages/shared/apps/env.ts b/packages/shared/apps/env.ts
index 2f70873980..73b5aa6082 100644
--- a/packages/shared/apps/env.ts
+++ b/packages/shared/apps/env.ts
@@ -2,3 +2,7 @@ import { APP_ENV } from './constants';
export const getAppEnv = () =>
process.env.NEXT_PUBLIC_APP_ENV ?? APP_ENV.DEVELOPMENT;
+
+export const isEnableSentryFlagSet = () => {
+ return process.env.NEXT_PUBLIC_ENABLE_SENTRY === 'true';
+};
diff --git a/packages/shared/apps/types.ts b/packages/shared/apps/types.ts
index ea2084944f..c952e5397d 100644
--- a/packages/shared/apps/types.ts
+++ b/packages/shared/apps/types.ts
@@ -1,6 +1,12 @@
import { NextRouter } from 'next/router';
import { APPS } from './constants';
import { SetDialogBoxAttributesV2 } from '@ente/shared/components/DialogBoxV2/types';
+import { EmotionCache } from '@emotion/react';
+import { AppProps } from 'next/app';
+
+export interface EnteAppProps extends AppProps {
+ emotionCache?: EmotionCache;
+}
export interface PageProps {
appContext: {
diff --git a/apps/photos/src/components/EnteLogo.tsx b/packages/shared/components/EnteLogo.tsx
similarity index 100%
rename from apps/photos/src/components/EnteLogo.tsx
rename to packages/shared/components/EnteLogo.tsx
diff --git a/apps/photos/src/components/Navbar/EnteLinkLogo.tsx b/packages/shared/components/Navbar/EnteLinkLogo.tsx
similarity index 81%
rename from apps/photos/src/components/Navbar/EnteLinkLogo.tsx
rename to packages/shared/components/Navbar/EnteLinkLogo.tsx
index d315fecfcc..557510337b 100644
--- a/apps/photos/src/components/Navbar/EnteLinkLogo.tsx
+++ b/packages/shared/components/Navbar/EnteLinkLogo.tsx
@@ -1,7 +1,7 @@
import { Box } from '@mui/material';
-import Ente from 'components/icons/ente';
+import Ente from '../../components/icons/ente';
import Link from 'next/link';
-import { ENTE_WEBSITE_LINK } from 'constants/urls';
+import { ENTE_WEBSITE_LINK } from '@ente/shared/constants/urls';
export function EnteLinkLogo() {
return (
diff --git a/apps/photos/src/components/Navbar/SelectionBar.tsx b/packages/shared/components/Navbar/SelectionBar.tsx
similarity index 72%
rename from apps/photos/src/components/Navbar/SelectionBar.tsx
rename to packages/shared/components/Navbar/SelectionBar.tsx
index 1eab57619a..19d552aaf7 100644
--- a/apps/photos/src/components/Navbar/SelectionBar.tsx
+++ b/packages/shared/components/Navbar/SelectionBar.tsx
@@ -1,4 +1,4 @@
-import NavbarBase from 'components/Navbar/base';
+import NavbarBase from './base';
import { styled } from '@mui/material';
export const SelectionBar = styled(NavbarBase)`
position: fixed;
diff --git a/apps/photos/src/components/Navbar/SidebarToggler.tsx b/packages/shared/components/Navbar/SidebarToggler.tsx
similarity index 92%
rename from apps/photos/src/components/Navbar/SidebarToggler.tsx
rename to packages/shared/components/Navbar/SidebarToggler.tsx
index a9b89acb18..cc3cfb14af 100644
--- a/apps/photos/src/components/Navbar/SidebarToggler.tsx
+++ b/packages/shared/components/Navbar/SidebarToggler.tsx
@@ -1,4 +1,3 @@
-import React from 'react';
import MenuIcon from '@mui/icons-material/Menu';
import IconButton from '@mui/material/IconButton';
diff --git a/packages/shared/components/Navbar/app.tsx b/packages/shared/components/Navbar/app.tsx
new file mode 100644
index 0000000000..24cc8a8989
--- /dev/null
+++ b/packages/shared/components/Navbar/app.tsx
@@ -0,0 +1,13 @@
+import { EnteLogo } from '../EnteLogo';
+import { CenteredFlex } from '../../components/Container';
+import NavbarBase from './base';
+
+export default function AppNavbar({ isMobile }) {
+ return (
+ <NavbarBase isMobile={isMobile}>
+ <CenteredFlex>
+ <EnteLogo />
+ </CenteredFlex>
+ </NavbarBase>
+ );
+}
diff --git a/apps/photos/src/components/Navbar/base.tsx b/packages/shared/components/Navbar/base.tsx
similarity index 56%
rename from apps/photos/src/components/Navbar/base.tsx
rename to packages/shared/components/Navbar/base.tsx
index 2acd2c7b55..3d68aa1219 100644
--- a/apps/photos/src/components/Navbar/base.tsx
+++ b/packages/shared/components/Navbar/base.tsx
@@ -1,7 +1,6 @@
-import { FlexWrapper } from 'components/Container';
+import { FlexWrapper } from '../../components/Container';
import { styled } from '@mui/material';
-import { IMAGE_CONTAINER_MAX_WIDTH, MIN_COLUMNS } from 'constants/gallery';
-const NavbarBase = styled(FlexWrapper)`
+const NavbarBase = styled(FlexWrapper)<{ isMobile: boolean }>`
min-height: 64px;
position: sticky;
top: 0;
@@ -11,9 +10,7 @@ const NavbarBase = styled(FlexWrapper)`
background-color: ${({ theme }) => theme.colors.background.base};
margin-bottom: 16px;
padding: 0 24px;
- @media (max-width: ${IMAGE_CONTAINER_MAX_WIDTH * MIN_COLUMNS}px) {
- padding: 0 4px;
- }
+ padding: ${(props) => (props.isMobile ? '0 16px;' : '0 4px;')};
`;
export default NavbarBase;
diff --git a/apps/photos/src/components/Sidebar/ThemeSwitcher.tsx b/packages/shared/components/ThemeSwitcher.tsx
similarity index 94%
rename from apps/photos/src/components/Sidebar/ThemeSwitcher.tsx
rename to packages/shared/components/ThemeSwitcher.tsx
index 1df658ed52..1d091c6910 100644
--- a/apps/photos/src/components/Sidebar/ThemeSwitcher.tsx
+++ b/packages/shared/components/ThemeSwitcher.tsx
@@ -2,7 +2,7 @@ import { ToggleButton, ToggleButtonGroup } from '@mui/material';
import React from 'react';
import DarkModeIcon from '@mui/icons-material/DarkMode';
import LightModeIcon from '@mui/icons-material/LightMode';
-import { THEME_COLOR } from 'constants/theme';
+import { THEME_COLOR } from '@ente/shared/themes/constants';
interface Iprops {
themeColor: THEME_COLOR;
setThemeColor: (theme: THEME_COLOR) => void;
diff --git a/apps/photos/src/components/icons/ente.tsx b/packages/shared/components/icons/ente.tsx
similarity index 100%
rename from apps/photos/src/components/icons/ente.tsx
rename to packages/shared/components/icons/ente.tsx
diff --git a/apps/photos/src/constants/pages.ts b/packages/shared/constants/pages.tsx
similarity index 95%
rename from apps/photos/src/constants/pages.ts
rename to packages/shared/constants/pages.tsx
index 85b9db0189..f5202b16c3 100644
--- a/apps/photos/src/constants/pages.ts
+++ b/packages/shared/constants/pages.tsx
@@ -1,4 +1,4 @@
-export enum PAGES {
+export enum PHOTOS_PAGES {
CHANGE_EMAIL = '/change-email',
CHANGE_PASSWORD = '/change-password',
CREDENTIALS = '/credentials',
diff --git a/apps/photos/src/hooks/useComponentScroll.tsx b/packages/shared/hooks/useComponentScroll.tsx
similarity index 100%
rename from apps/photos/src/hooks/useComponentScroll.tsx
rename to packages/shared/hooks/useComponentScroll.tsx
diff --git a/apps/photos/src/hooks/useFileInput.tsx b/packages/shared/hooks/useFileInput.tsx
similarity index 100%
rename from apps/photos/src/hooks/useFileInput.tsx
rename to packages/shared/hooks/useFileInput.tsx
diff --git a/apps/photos/src/hooks/useLocalState.tsx b/packages/shared/hooks/useLocalState.tsx
similarity index 87%
rename from apps/photos/src/hooks/useLocalState.tsx
rename to packages/shared/hooks/useLocalState.tsx
index a33a8a177f..d50107921d 100644
--- a/apps/photos/src/hooks/useLocalState.tsx
+++ b/packages/shared/hooks/useLocalState.tsx
@@ -1,5 +1,5 @@
import { Dispatch, SetStateAction, useEffect, useState } from 'react';
-import { getData, LS_KEYS, setData } from 'utils/storage/localStorage';
+import { getData, LS_KEYS, setData } from '@ente/shared/storage/localStorage';
export function useLocalState<T>(
key: LS_KEYS,
diff --git a/apps/photos/src/hooks/useLongPress.ts b/packages/shared/hooks/useLongPress.ts
similarity index 100%
rename from apps/photos/src/hooks/useLongPress.ts
rename to packages/shared/hooks/useLongPress.ts
diff --git a/apps/photos/src/hooks/useMemoSingleThreaded.tsx b/packages/shared/hooks/useMemoSingleThreaded.tsx
similarity index 100%
rename from apps/photos/src/hooks/useMemoSingleThreaded.tsx
rename to packages/shared/hooks/useMemoSingleThreaded.tsx
diff --git a/apps/photos/src/hooks/useWindowSize.tsx b/packages/shared/hooks/useWindowSize.tsx
similarity index 100%
rename from apps/photos/src/hooks/useWindowSize.tsx
rename to packages/shared/hooks/useWindowSize.tsx
diff --git a/apps/photos/src/i18n/index.ts b/packages/shared/i18n/index.ts
similarity index 96%
rename from apps/photos/src/i18n/index.ts
rename to packages/shared/i18n/index.ts
index d9685f8bd6..7f7665ff3b 100644
--- a/apps/photos/src/i18n/index.ts
+++ b/packages/shared/i18n/index.ts
@@ -1,7 +1,7 @@
import i18n from 'i18next';
import { initReactI18next } from 'react-i18next';
import Backend from 'i18next-http-backend';
-import { getBestPossibleUserLocale } from 'utils/i18n';
+import { getBestPossibleUserLocale } from './utils';
export const setupI18n = async () => {
await i18n
diff --git a/apps/photos/src/constants/locale.ts b/packages/shared/i18n/locale.ts
similarity index 100%
rename from apps/photos/src/constants/locale.ts
rename to packages/shared/i18n/locale.ts
diff --git a/apps/photos/src/utils/i18n/index.ts b/packages/shared/i18n/utils.ts
similarity index 85%
rename from apps/photos/src/utils/i18n/index.ts
rename to packages/shared/i18n/utils.ts
index c000582d81..a9f3f835ec 100644
--- a/apps/photos/src/utils/i18n/index.ts
+++ b/packages/shared/i18n/utils.ts
@@ -1,7 +1,7 @@
-import { Language } from 'constants/locale';
+import { Language } from './locale';
import { getUserLocales } from 'get-user-locale';
-import { getUserLocale } from 'utils/storage';
+import { getUserLocale } from '@ente/shared/storage/localStorage/helpers';
export function getBestPossibleUserLocale(): Language {
const locale = getUserLocale();
diff --git a/packages/shared/next/env.js b/packages/shared/next/env.js
new file mode 100644
index 0000000000..6cf1178b7d
--- /dev/null
+++ b/packages/shared/next/env.js
@@ -0,0 +1,17 @@
+const ENV_DEVELOPMENT = 'development';
+const ENV_PRODUCTION = 'production';
+const ENV_TEST = 'test';
+
+module.exports = {
+ ENV_DEVELOPMENT,
+ ENV_PRODUCTION,
+ ENV_TEST,
+};
+
+module.exports.getAppEnv = () => {
+ return process.env.NEXT_PUBLIC_APP_ENV ?? ENV_DEVELOPMENT;
+};
+
+module.exports.isEnableSentryFlagSet = () => {
+ return process.env.NEXT_PUBLIC_ENABLE_SENTRY === 'true';
+};
diff --git a/packages/shared/next/next.config.base.js b/packages/shared/next/next.config.base.js
new file mode 100644
index 0000000000..7f3def142b
--- /dev/null
+++ b/packages/shared/next/next.config.base.js
@@ -0,0 +1,75 @@
+const { withSentryConfig } = require('@sentry/nextjs');
+const { PHASE_DEVELOPMENT_SERVER } = require('next/constants');
+
+const {
+ convertToNextHeaderFormat,
+ buildCSPHeader,
+ WEB_SECURITY_HEADERS,
+ CSP_DIRECTIVES,
+ ALL_ROUTES,
+} = require('./utils/headers');
+
+const { getGitSha, getIsSentryEnabled } = require('./utils/sentry');
+
+const GIT_SHA = getGitSha();
+
+const IS_SENTRY_ENABLED = getIsSentryEnabled();
+
+module.exports = (phase) =>
+ withSentryConfig(
+ {
+ sentry: {
+ widenClientFileUpload: true,
+ disableServerWebpackPlugin: true,
+ autoInstrumentServerFunctions: false,
+ },
+ output: 'export',
+ compiler: {
+ emotion: {
+ importMap: {
+ '@mui/material': {
+ styled: {
+ canonicalImport: ['@emotion/styled', 'default'],
+ styledBaseImport: ['@mui/material', 'styled'],
+ },
+ },
+ '@mui/material/styles': {
+ styled: {
+ canonicalImport: ['@emotion/styled', 'default'],
+ styledBaseImport: [
+ '@mui/material/styles',
+ 'styled',
+ ],
+ },
+ },
+ },
+ },
+ },
+ transpilePackages: [
+ '@mui/material',
+ '@mui/system',
+ '@mui/icons-material',
+ ],
+ env: {
+ SENTRY_RELEASE: GIT_SHA,
+ NEXT_PUBLIC_IS_TEST_APP: process.env.IS_TEST_RELEASE || 'false',
+ },
+
+ headers() {
+ return [
+ {
+ // Apply these headers to all routes in your application....
+ source: ALL_ROUTES,
+ headers: convertToNextHeaderFormat({
+ ...WEB_SECURITY_HEADERS,
+ ...buildCSPHeader(CSP_DIRECTIVES),
+ }),
+ },
+ ];
+ },
+ },
+ {
+ dryRun: phase === PHASE_DEVELOPMENT_SERVER || !IS_SENTRY_ENABLED,
+ release: GIT_SHA,
+ }
+ );
diff --git a/packages/shared/next/pages/404.tsx b/packages/shared/next/pages/404.tsx
new file mode 100644
index 0000000000..b5fe170f7a
--- /dev/null
+++ b/packages/shared/next/pages/404.tsx
@@ -0,0 +1,19 @@
+import { VerticallyCentered } from '@ente/shared/components/Container';
+import React, { useEffect, useState } from 'react';
+import { t } from 'i18next';
+
+import EnteSpinner from '@ente/shared/components/EnteSpinner';
+import { PageProps } from '@ente/shared/apps/types';
+
+export default function NotFound({ appContext }: PageProps) {
+ const [loading, setLoading] = useState(true);
+ useEffect(() => {
+ appContext.showNavBar(true);
+ setLoading(false);
+ }, []);
+ return (
+ <VerticallyCentered>
+ {loading ? <EnteSpinner /> : t('NOT_FOUND')}
+ </VerticallyCentered>
+ );
+}
diff --git a/packages/shared/next/pages/_document.tsx b/packages/shared/next/pages/_document.tsx
new file mode 100644
index 0000000000..d33dca37c5
--- /dev/null
+++ b/packages/shared/next/pages/_document.tsx
@@ -0,0 +1,103 @@
+import React from 'react';
+import Document, {
+ Html,
+ Head,
+ Main,
+ NextScript,
+ DocumentProps,
+ DocumentContext,
+} from 'next/document';
+
+import createEmotionServer from '@emotion/server/create-instance';
+import { AppType } from 'next/app';
+import createEmotionCache from '@ente/shared/themes/createEmotionCache';
+import { EnteAppProps } from '@ente/shared/apps/types';
+
+interface EnteDocumentProps extends DocumentProps {
+ emotionStyleTags: JSX.Element[];
+}
+
+export default function EnteDocument({ emotionStyleTags }: EnteDocumentProps) {
+ return (
+ <Html lang="en">
+ <Head>
+ <meta
+ name="description"
+ content="ente - end-to-end encrypted cloud with open-source apps"
+ />
+ <link rel="icon" href="/images/favicon.png" type="image/png" />
+ <link rel="icon" type="image/png" href="/images/favicon.png" />
+ <meta name="apple-mobile-web-app-capable" content="yes" />
+ {emotionStyleTags}
+ </Head>
+ <body>
+ <Main />
+ <NextScript />
+ </body>
+ </Html>
+ );
+}
+
+// `getInitialProps` belongs to `_document` (instead of `_app`),
+// it's compatible with static-site generation (SSG).
+EnteDocument.getInitialProps = async (ctx: DocumentContext) => {
+ // Resolution order
+ //
+ // On the server:
+ // 1. app.getInitialProps
+ // 2. page.getInitialProps
+ // 3. document.getInitialProps
+ // 4. app.render
+ // 5. page.render
+ // 6. document.render
+ //
+ // On the server with error:
+ // 1. document.getInitialProps
+ // 2. app.render
+ // 3. page.render
+ // 4. document.render
+ //
+ // On the client
+ // 1. app.getInitialProps
+ // 2. page.getInitialProps
+ // 3. app.render
+ // 4. page.render
+
+ const originalRenderPage = ctx.renderPage;
+
+ // You can consider sharing the same Emotion cache between all the SSR requests to speed up performance.
+ // However, be aware that it can have global side effects.
+ const cache = createEmotionCache();
+ // eslint-disable-next-line @typescript-eslint/unbound-method
+ const { extractCriticalToChunks } = createEmotionServer(cache);
+
+ ctx.renderPage = () =>
+ originalRenderPage({
+ enhanceApp: (
+ App: React.ComponentType<
+ React.ComponentProps<AppType> & EnteAppProps
+ >
+ ) =>
+ function EnhanceApp(props) {
+ return <App emotionCache={cache} {...props} />;
+ },
+ });
+
+ const initialProps = await Document.getInitialProps(ctx);
+ // This is important. It prevents Emotion to render invalid HTML.
+ // See https://github.com/mui/material-ui/issues/26561#issuecomment-855286153
+ const emotionStyles = extractCriticalToChunks(initialProps.html);
+ const emotionStyleTags = emotionStyles.styles.map((style) => (
+ <style
+ data-emotion={`${style.key} ${style.ids.join(' ')}`}
+ key={style.key}
+ // eslint-disable-next-line react/no-danger
+ dangerouslySetInnerHTML={{ __html: style.css }}
+ />
+ ));
+
+ return {
+ ...initialProps,
+ emotionStyleTags,
+ };
+};
diff --git a/packages/shared/next/pages/_error.tsx b/packages/shared/next/pages/_error.tsx
new file mode 100644
index 0000000000..9160c65cf7
--- /dev/null
+++ b/packages/shared/next/pages/_error.tsx
@@ -0,0 +1,17 @@
+import * as Sentry from '@sentry/nextjs';
+import NextErrorComponent from 'next/error';
+
+const CustomErrorComponent = (props) => (
+ <NextErrorComponent statusCode={props.statusCode} />
+);
+
+CustomErrorComponent.getInitialProps = async (contextData) => {
+ // In case this is running in a serverless function, await this in order to give Sentry
+ // time to send the error before the lambda exits
+ await Sentry.captureUnderscoreErrorException(contextData);
+
+ // This will contain the status code of the response
+ return NextErrorComponent.getInitialProps(contextData);
+};
+
+export default CustomErrorComponent;
diff --git a/packages/shared/next/utils/headers.js b/packages/shared/next/utils/headers.js
new file mode 100644
index 0000000000..181b7c1474
--- /dev/null
+++ b/packages/shared/next/utils/headers.js
@@ -0,0 +1,42 @@
+module.exports = {
+ WEB_SECURITY_HEADERS: {
+ 'Strict-Transport-Security': ' max-age=63072000',
+ 'X-Content-Type-Options': 'nosniff',
+ 'X-Download-Options': 'noopen',
+ 'X-Frame-Options': 'deny',
+ 'X-XSS-Protection': '1; mode=block',
+ 'Referrer-Policy': 'same-origin',
+ },
+
+ CSP_DIRECTIVES: {
+ // self is safe enough
+ 'default-src': "'self'",
+ // data to allow two factor qr code
+ 'img-src': "'self' blob: data: https://*.openstreetmap.org",
+ 'media-src': "'self' blob:",
+ 'manifest-src': "'self'",
+ 'style-src': "'self' 'unsafe-inline'",
+ 'font-src ': "'self'; script-src 'self' 'unsafe-eval' blob:",
+ 'connect-src':
+ "'self' https://*.ente.io http://localhost:8080 data: blob: https://ente-prod-eu.s3.eu-central-003.backblazeb2.com https://ente-prod-v3.s3.eu-central-2.wasabisys.com/ https://ente-staging-eu.s3.eu-central-003.backblazeb2.com/ ws://localhost:3000/",
+ 'base-uri ': "'self'",
+ // to allow worker
+ 'child-src': "'self' blob:",
+ 'object-src': "'none'",
+ 'frame-ancestors': " 'none'",
+ 'form-action': "'none'",
+ 'report-uri': ' https://csp-reporter.ente.io/local',
+ 'report-to': ' https://csp-reporter.ente.io/local',
+ },
+
+ ALL_ROUTES: '/(.*)',
+
+ buildCSPHeader: (directives) => ({
+ 'Content-Security-Policy-Report-Only': Object.entries(
+ directives
+ ).reduce((acc, [key, value]) => acc + `${key} ${value};`, ''),
+ }),
+
+ convertToNextHeaderFormat: (headers) =>
+ Object.entries(headers).map(([key, value]) => ({ key, value })),
+};
diff --git a/packages/shared/next/utils/sentry.js b/packages/shared/next/utils/sentry.js
new file mode 100644
index 0000000000..c1c1ca5fdb
--- /dev/null
+++ b/packages/shared/next/utils/sentry.js
@@ -0,0 +1,18 @@
+const {
+ getAppEnv,
+ ENV_DEVELOPMENT,
+ isEnableSentryFlagSet,
+} = require('../env.js');
+const cp = require('child_process');
+
+module.exports.getIsSentryEnabled = () => {
+ const isAppENVDevelopment = getAppEnv() === ENV_DEVELOPMENT;
+ const isSentryEnabled = isEnableSentryFlagSet();
+ return !isAppENVDevelopment || isSentryEnabled;
+};
+
+module.exports.getGitSha = () =>
+ cp.execSync('git rev-parse --short HEAD', {
+ cwd: __dirname,
+ encoding: 'utf8',
+ });
diff --git a/packages/shared/package.json b/packages/shared/package.json
index 6da5c15cd6..2cbf2c7b39 100644
--- a/packages/shared/package.json
+++ b/packages/shared/package.json
@@ -1,10 +1,13 @@
{
"name": "@ente/shared",
"version": "0.0.0",
+ "private": true,
"scripts": {
"lint": "eslint .",
"build": "yarn lint && tsc"
},
- "dependencies": {},
+ "dependencies": {
+ "@sentry/nextjs": "^7.77.0"
+ },
"devDependencies": {}
}
diff --git a/packages/shared/sentry/config/sentry.config.base.ts b/packages/shared/sentry/config/sentry.config.base.ts
new file mode 100644
index 0000000000..22b50d3ffc
--- /dev/null
+++ b/packages/shared/sentry/config/sentry.config.base.ts
@@ -0,0 +1,43 @@
+import * as Sentry from '@sentry/nextjs';
+import { getSentryTunnelURL } from '@ente/shared/network/api';
+import { getSentryUserID } from '@ente/shared/sentry/utils';
+import { runningInBrowser } from '@ente/shared/platform';
+import { getHasOptedOutOfCrashReports } from '@ente/shared/storage/localStorage/helpers';
+import { getIsSentryEnabled } from '@ente/shared/sentry/utils';
+import { getAppEnv } from '@ente/shared/apps/env';
+
+export const setupSentry = async () => {
+ const HAS_OPTED_OUT_OF_CRASH_REPORTING =
+ runningInBrowser() && getHasOptedOutOfCrashReports();
+
+ if (!HAS_OPTED_OUT_OF_CRASH_REPORTING) {
+ const APP_ENV = getAppEnv();
+ const IS_ENABLED = getIsSentryEnabled();
+
+ Sentry.init({
+ enabled: IS_ENABLED,
+ environment: APP_ENV,
+ attachStacktrace: true,
+ autoSessionTracking: false,
+ tunnel: getSentryTunnelURL(),
+ beforeSend(event) {
+ event.request = event.request || {};
+ const currentURL = new URL(document.location.href);
+ currentURL.hash = '';
+ event.request.url = currentURL.href;
+ return event;
+ },
+ integrations: function (i) {
+ return i.filter(function (i) {
+ return i.name !== 'Breadcrumbs';
+ });
+ },
+ // ...
+ // Note: if you want to override the automatic release value, do not set a
+ // `release` value here - use the environment variable `SENTRY_RELEASE`, so
+ // that it will also get attached to your source maps
+ });
+
+ Sentry.setUser({ id: await getSentryUserID() });
+ }
+};
diff --git a/packages/shared/sentry/utils.ts b/packages/shared/sentry/utils.ts
index e394ba6028..0b6209ab48 100644
--- a/packages/shared/sentry/utils.ts
+++ b/packages/shared/sentry/utils.ts
@@ -4,6 +4,9 @@ import {
setLocalSentryUserID,
} from '@ente/shared/storage/localStorage/helpers';
import isElectron from 'is-electron';
+import { getAppEnv } from '@ente/shared/apps/env';
+import { APP_ENV } from '@ente/shared/apps/constants';
+import { isEnableSentryFlagSet } from '@ente/shared/apps/env';
export async function getSentryUserID() {
if (isElectron()) {
@@ -39,3 +42,9 @@ export function isErrorUnnecessaryForSentry(error: any) {
}
return false;
}
+
+export const getIsSentryEnabled = () => {
+ const isAppENVDevelopment = getAppEnv() === APP_ENV.DEVELOPMENT;
+ const isSentryEnabled = isEnableSentryFlagSet();
+ return !isAppENVDevelopment || isSentryEnabled;
+};
diff --git a/packages/shared/storage/localStorage/helpers.ts b/packages/shared/storage/localStorage/helpers.ts
index 05cfebc342..58cc9b1a65 100644
--- a/packages/shared/storage/localStorage/helpers.ts
+++ b/packages/shared/storage/localStorage/helpers.ts
@@ -1,5 +1,6 @@
import { CustomError } from '@ente/shared/error';
import { LS_KEYS, getData, setData } from '.';
+import { Language } from '@ente/shared/i18n/locale';
export const getToken = () => {
const token = getData(LS_KEYS.USER)?.token;
@@ -31,6 +32,10 @@ export function setLivePhotoInfoShownCount(count: boolean) {
setData(LS_KEYS.LIVE_PHOTO_INFO_SHOWN_COUNT, { count });
}
+export function getUserLocale(): Language {
+ return getData(LS_KEYS.LOCALE)?.value;
+}
+
export function getLocalMapEnabled(): boolean {
return getData(LS_KEYS.MAP_ENABLED)?.value ?? false;
}
diff --git a/apps/photos/src/themes/colors/dark.ts b/packages/shared/themes/colors/dark.ts
similarity index 100%
rename from apps/photos/src/themes/colors/dark.ts
rename to packages/shared/themes/colors/dark.ts
diff --git a/apps/photos/src/themes/colors/fixed.ts b/packages/shared/themes/colors/fixed.ts
similarity index 96%
rename from apps/photos/src/themes/colors/fixed.ts
rename to packages/shared/themes/colors/fixed.ts
index 72d930955f..bc523cdfb0 100644
--- a/apps/photos/src/themes/colors/fixed.ts
+++ b/packages/shared/themes/colors/fixed.ts
@@ -1,5 +1,5 @@
import { FixedColors, ThemeColorsOptions } from '@mui/material';
-import { APPS } from 'constants/apps';
+import { APPS } from '@ente/shared/apps/constants';
export const getFixesColors = (
appName: APPS
diff --git a/apps/photos/src/themes/colors/index.ts b/packages/shared/themes/colors/index.ts
similarity index 83%
rename from apps/photos/src/themes/colors/index.ts
rename to packages/shared/themes/colors/index.ts
index 3585771551..d8e4705cb9 100644
--- a/apps/photos/src/themes/colors/index.ts
+++ b/packages/shared/themes/colors/index.ts
@@ -1,8 +1,8 @@
import { ThemeColorsOptions } from '@mui/material';
-import { THEME_COLOR } from 'constants/theme';
+import { THEME_COLOR } from '../constants';
import darkThemeColors from './dark';
import lightThemeColors from './light';
-import { APPS } from 'constants/apps';
+import { APPS } from '@ente/shared/apps/constants';
import { getFixesColors } from './fixed';
export const getColors = (
diff --git a/apps/photos/src/themes/colors/light.ts b/packages/shared/themes/colors/light.ts
similarity index 100%
rename from apps/photos/src/themes/colors/light.ts
rename to packages/shared/themes/colors/light.ts
diff --git a/apps/photos/src/themes/components.ts b/packages/shared/themes/components.ts
similarity index 100%
rename from apps/photos/src/themes/components.ts
rename to packages/shared/themes/components.ts
diff --git a/apps/photos/src/constants/theme.ts b/packages/shared/themes/constants.ts
similarity index 100%
rename from apps/photos/src/constants/theme.ts
rename to packages/shared/themes/constants.ts
diff --git a/apps/photos/src/themes/createEmotionCache.ts b/packages/shared/themes/createEmotionCache.ts
similarity index 100%
rename from apps/photos/src/themes/createEmotionCache.ts
rename to packages/shared/themes/createEmotionCache.ts
diff --git a/apps/photos/src/themes/index.ts b/packages/shared/themes/index.ts
similarity index 88%
rename from apps/photos/src/themes/index.ts
rename to packages/shared/themes/index.ts
index 2f71558734..ef79241657 100644
--- a/apps/photos/src/themes/index.ts
+++ b/packages/shared/themes/index.ts
@@ -1,10 +1,10 @@
import { createTheme } from '@mui/material';
-import { THEME_COLOR } from 'constants/theme';
+import { THEME_COLOR } from './constants';
import { getColors } from './colors';
import { getComponents } from './components';
import { getPallette } from './palette';
import { typography } from './typography';
-import { APPS } from 'constants/apps';
+import { APPS } from '@ente/shared/apps/constants';
export const getTheme = (themeColor: THEME_COLOR, appName: APPS) => {
const colors = getColors(themeColor, appName);
diff --git a/packages/shared/theme/mui-theme.d.ts b/packages/shared/themes/mui-theme.d.ts
similarity index 100%
rename from packages/shared/theme/mui-theme.d.ts
rename to packages/shared/themes/mui-theme.d.ts
diff --git a/apps/photos/src/themes/palette/index.tsx b/packages/shared/themes/palette/index.tsx
similarity index 97%
rename from apps/photos/src/themes/palette/index.tsx
rename to packages/shared/themes/palette/index.tsx
index c0ca2ea845..db89766648 100644
--- a/apps/photos/src/themes/palette/index.tsx
+++ b/packages/shared/themes/palette/index.tsx
@@ -1,5 +1,5 @@
import { PaletteOptions, ThemeColorsOptions } from '@mui/material';
-import { THEME_COLOR } from 'constants/theme';
+import { THEME_COLOR } from '../constants';
export const getPallette = (
themeColor: THEME_COLOR,
diff --git a/apps/photos/src/types/theme/index.ts b/packages/shared/themes/types.ts
similarity index 61%
rename from apps/photos/src/types/theme/index.ts
rename to packages/shared/themes/types.ts
index 5c49d30d97..10d2c989a8 100644
--- a/apps/photos/src/types/theme/index.ts
+++ b/packages/shared/themes/types.ts
@@ -1,3 +1,3 @@
-import { THEME_COLOR } from 'constants/theme';
+import { THEME_COLOR } from './constants';
export type SetTheme = React.Dispatch<React.SetStateAction<THEME_COLOR>>;
diff --git a/apps/photos/src/themes/typography.ts b/packages/shared/themes/typography.ts
similarity index 100%
rename from apps/photos/src/themes/typography.ts
rename to packages/shared/themes/typography.ts
diff --git a/packages/shared/tsconfig.json b/packages/shared/tsconfig.json
index 3943cf709d..67674e1acd 100644
--- a/packages/shared/tsconfig.json
+++ b/packages/shared/tsconfig.json
@@ -12,5 +12,5 @@
"target": "es5",
"useUnknownInCatchVariables": false
},
- "include": ["**/*.ts", "**/*.tsx", "**/*.js"]
+ "include": ["**/*.ts", "**/*.tsx", "**/*.js", "themes/mui-theme.d.ts"]
}