From dfdf2897d40da2dbd1c62dd20740a01c6b5b711c Mon Sep 17 00:00:00 2001 From: Abhinav Date: Tue, 4 Jan 2022 16:46:30 +0530 Subject: [PATCH] move constants from util to src directory and split into sub folders --- src/components/ChangeEmail.tsx | 2 +- src/components/Login.tsx | 2 +- src/components/PhotoList.tsx | 2 +- src/components/Sidebar.tsx | 2 +- src/components/SignUp.tsx | 2 +- src/components/TwoFactorModal.tsx | 2 +- src/components/pages/gallery/Collections.tsx | 2 +- src/components/pages/gallery/PreviewCard.tsx | 2 +- src/constants/crypto/index.ts | 1 + src/constants/gallery/index.ts | 7 +++++++ src/{utils/constants => constants/pages}/index.ts | 9 --------- src/pages/change-email/index.tsx | 2 +- src/pages/change-password/index.tsx | 2 +- src/pages/credentials/index.tsx | 2 +- src/pages/gallery/index.tsx | 2 +- src/pages/generate/index.tsx | 2 +- src/pages/index.tsx | 2 +- src/pages/login/index.tsx | 2 +- src/pages/recover/index.tsx | 2 +- src/pages/signup/index.tsx | 2 +- src/pages/two-factor/recover/index.tsx | 2 +- src/pages/two-factor/setup/index.tsx | 2 +- src/pages/two-factor/verify/index.tsx | 2 +- src/pages/verify/index.tsx | 2 +- src/services/userService.ts | 2 +- src/types/upload/index.ts | 2 +- src/utils/crypto/libsodium.ts | 2 +- 27 files changed, 32 insertions(+), 33 deletions(-) create mode 100644 src/constants/crypto/index.ts create mode 100644 src/constants/gallery/index.ts rename src/{utils/constants => constants/pages}/index.ts (57%) diff --git a/src/components/ChangeEmail.tsx b/src/components/ChangeEmail.tsx index cbf27b0a3..0eb94a694 100644 --- a/src/components/ChangeEmail.tsx +++ b/src/components/ChangeEmail.tsx @@ -9,7 +9,7 @@ import { changeEmail, getOTTForEmailChange } from 'services/userService'; import styled from 'styled-components'; import { AppContext, FLASH_MESSAGE_TYPE } from 'pages/_app'; import { getData, LS_KEYS, setData } from 'utils/storage/localStorage'; -import { PAGES } from 'utils/constants'; +import { PAGES } from 'constants/pages'; interface formValues { email: string; diff --git a/src/components/Login.tsx b/src/components/Login.tsx index 38b6b6099..1309d2b97 100644 --- a/src/components/Login.tsx +++ b/src/components/Login.tsx @@ -11,7 +11,7 @@ import { setData, LS_KEYS, getData } from 'utils/storage/localStorage'; import SubmitButton from 'components/SubmitButton'; import Button from 'react-bootstrap/Button'; import LogoImg from './LogoImg'; -import { PAGES } from 'utils/constants'; +import { PAGES } from 'constants/pages'; interface formValues { email: string; diff --git a/src/components/PhotoList.tsx b/src/components/PhotoList.tsx index 523865253..0c34407ba 100644 --- a/src/components/PhotoList.tsx +++ b/src/components/PhotoList.tsx @@ -9,7 +9,7 @@ import { DATE_CONTAINER_HEIGHT, GAP_BTW_TILES, SPACE_BTW_DATES, -} from 'utils/constants'; +} from 'constants/gallery'; import constants from 'utils/strings/constants'; const A_DAY = 24 * 60 * 60 * 1000; diff --git a/src/components/Sidebar.tsx b/src/components/Sidebar.tsx index 4f7506158..28e502464 100644 --- a/src/components/Sidebar.tsx +++ b/src/components/Sidebar.tsx @@ -31,7 +31,7 @@ import { GalleryContext } from 'pages/gallery'; import InProgressIcon from './icons/InProgressIcon'; import exportService from 'services/exportService'; import { Subscription } from 'types/billing'; -import { PAGES } from 'utils/constants'; +import { PAGES } from 'constants/pages'; import { ARCHIVE_SECTION, TRASH_SECTION, diff --git a/src/components/SignUp.tsx b/src/components/SignUp.tsx index f31f2999a..8a2399f86 100644 --- a/src/components/SignUp.tsx +++ b/src/components/SignUp.tsx @@ -19,7 +19,7 @@ import { setJustSignedUp } from 'utils/storage'; import LogoImg from './LogoImg'; import { logError } from 'utils/sentry'; import { SESSION_KEYS } from 'utils/storage/sessionStorage'; -import { PAGES } from 'utils/constants'; +import { PAGES } from 'constants/pages'; interface FormValues { email: string; diff --git a/src/components/TwoFactorModal.tsx b/src/components/TwoFactorModal.tsx index d5e0707dd..c7597fac2 100644 --- a/src/components/TwoFactorModal.tsx +++ b/src/components/TwoFactorModal.tsx @@ -5,7 +5,7 @@ import React, { useContext, useEffect, useState } from 'react'; import { Button } from 'react-bootstrap'; import { disableTwoFactor, getTwoFactorStatus } from 'services/userService'; import { SetLoading } from 'types/gallery'; -import { PAGES } from 'utils/constants'; +import { PAGES } from 'constants/pages'; import { getData, LS_KEYS, setData } from 'utils/storage/localStorage'; import constants from 'utils/strings/constants'; import { Label, Value, Row } from './Container'; diff --git a/src/components/pages/gallery/Collections.tsx b/src/components/pages/gallery/Collections.tsx index 1cf609664..923948a10 100644 --- a/src/components/pages/gallery/Collections.tsx +++ b/src/components/pages/gallery/Collections.tsx @@ -8,7 +8,7 @@ import { OverlayTrigger, Tooltip } from 'react-bootstrap'; import { sortCollections } from 'services/collectionService'; import { User } from 'types/user'; import styled from 'styled-components'; -import { IMAGE_CONTAINER_MAX_WIDTH } from 'utils/constants'; +import { IMAGE_CONTAINER_MAX_WIDTH } from 'constants/gallery'; import { Collection, CollectionAndItsLatestFile, diff --git a/src/components/pages/gallery/PreviewCard.tsx b/src/components/pages/gallery/PreviewCard.tsx index 77e343b76..6454832ce 100644 --- a/src/components/pages/gallery/PreviewCard.tsx +++ b/src/components/pages/gallery/PreviewCard.tsx @@ -5,7 +5,7 @@ import PlayCircleOutline from 'components/icons/PlayCircleOutline'; import DownloadManager from 'services/downloadManager'; import useLongPress from 'utils/common/useLongPress'; import { GalleryContext } from 'pages/gallery'; -import { GAP_BTW_TILES } from 'utils/constants'; +import { GAP_BTW_TILES } from 'constants/gallery'; interface IProps { file: EnteFile; diff --git a/src/constants/crypto/index.ts b/src/constants/crypto/index.ts new file mode 100644 index 000000000..9226ed874 --- /dev/null +++ b/src/constants/crypto/index.ts @@ -0,0 +1 @@ +export const ENCRYPTION_CHUNK_SIZE = 4 * 1024 * 1024; diff --git a/src/constants/gallery/index.ts b/src/constants/gallery/index.ts new file mode 100644 index 000000000..be5c385f4 --- /dev/null +++ b/src/constants/gallery/index.ts @@ -0,0 +1,7 @@ +export const GAP_BTW_TILES = 4; +export const DATE_CONTAINER_HEIGHT = 48; +export const IMAGE_CONTAINER_MAX_HEIGHT = 200; +export const IMAGE_CONTAINER_MAX_WIDTH = + IMAGE_CONTAINER_MAX_HEIGHT - GAP_BTW_TILES; +export const MIN_COLUMNS = 4; +export const SPACE_BTW_DATES = 44; diff --git a/src/utils/constants/index.ts b/src/constants/pages/index.ts similarity index 57% rename from src/utils/constants/index.ts rename to src/constants/pages/index.ts index 6a8481bb4..aad2a4831 100644 --- a/src/utils/constants/index.ts +++ b/src/constants/pages/index.ts @@ -1,12 +1,3 @@ -export const ENCRYPTION_CHUNK_SIZE = 4 * 1024 * 1024; -export const GAP_BTW_TILES = 4; -export const DATE_CONTAINER_HEIGHT = 48; -export const IMAGE_CONTAINER_MAX_HEIGHT = 200; -export const IMAGE_CONTAINER_MAX_WIDTH = - IMAGE_CONTAINER_MAX_HEIGHT - GAP_BTW_TILES; -export const MIN_COLUMNS = 4; -export const SPACE_BTW_DATES = 44; - export enum PAGES { CHANGE_EMAIL = '/change-email', CHANGE_PASSWORD = '/change-password', diff --git a/src/pages/change-email/index.tsx b/src/pages/change-email/index.tsx index a557da438..f81b971a6 100644 --- a/src/pages/change-email/index.tsx +++ b/src/pages/change-email/index.tsx @@ -8,7 +8,7 @@ import { getToken } from 'utils/common/key'; import EnteSpinner from 'components/EnteSpinner'; import ChangeEmailForm from 'components/ChangeEmail'; import EnteCard from 'components/EnteCard'; -import { PAGES } from 'utils/constants'; +import { PAGES } from 'constants/pages'; function ChangeEmailPage() { const [email, setEmail] = useState(''); diff --git a/src/pages/change-password/index.tsx b/src/pages/change-password/index.tsx index b297ce406..1eaee4a70 100644 --- a/src/pages/change-password/index.tsx +++ b/src/pages/change-password/index.tsx @@ -12,7 +12,7 @@ import { setKeys } from 'services/userService'; import SetPasswordForm from 'components/SetPasswordForm'; import { AppContext } from 'pages/_app'; import { SESSION_KEYS } from 'utils/storage/sessionStorage'; -import { PAGES } from 'utils/constants'; +import { PAGES } from 'constants/pages'; import { UpdatedKey } from 'types/user'; export interface KEK { diff --git a/src/pages/credentials/index.tsx b/src/pages/credentials/index.tsx index ddf7dbf1a..86d44ce5f 100644 --- a/src/pages/credentials/index.tsx +++ b/src/pages/credentials/index.tsx @@ -3,7 +3,7 @@ import React, { useContext, useEffect, useState } from 'react'; import constants from 'utils/strings/constants'; import { clearData, getData, LS_KEYS } from 'utils/storage/localStorage'; import { useRouter } from 'next/router'; -import { PAGES } from 'utils/constants'; +import { PAGES } from 'constants/pages'; import { SESSION_KEYS, getKey } from 'utils/storage/sessionStorage'; import CryptoWorker, { decryptAndStoreToken, diff --git a/src/pages/gallery/index.tsx b/src/pages/gallery/index.tsx index f91ee4323..a8452b1cb 100644 --- a/src/pages/gallery/index.tsx +++ b/src/pages/gallery/index.tsx @@ -71,7 +71,7 @@ import Collections, { } from 'components/pages/gallery/Collections'; import { AppContext } from 'pages/_app'; import { CustomError, ServerErrorCodes } from 'utils/common/errorUtil'; -import { PAGES } from 'utils/constants'; +import { PAGES } from 'constants/pages'; import { COLLECTION_OPS_TYPE, isSharedCollection, diff --git a/src/pages/generate/index.tsx b/src/pages/generate/index.tsx index 1efba5981..8457b6940 100644 --- a/src/pages/generate/index.tsx +++ b/src/pages/generate/index.tsx @@ -12,7 +12,7 @@ import { import SetPasswordForm from 'components/SetPasswordForm'; import { justSignedUp, setJustSignedUp } from 'utils/storage'; import RecoveryKeyModal from 'components/RecoveryKeyModal'; -import { PAGES } from 'utils/constants'; +import { PAGES } from 'constants/pages'; import Container from 'components/Container'; import EnteSpinner from 'components/EnteSpinner'; import { AppContext } from 'pages/_app'; diff --git a/src/pages/index.tsx b/src/pages/index.tsx index 015d9748c..4d80828c5 100644 --- a/src/pages/index.tsx +++ b/src/pages/index.tsx @@ -12,7 +12,7 @@ import constants from 'utils/strings/constants'; import localForage from 'utils/storage/localForage'; import IncognitoWarning from 'components/IncognitoWarning'; import { logError } from 'utils/sentry'; -import { PAGES } from 'utils/constants'; +import { PAGES } from 'constants/pages'; const Container = styled.div` display: flex; diff --git a/src/pages/login/index.tsx b/src/pages/login/index.tsx index 561c29b03..ef056f426 100644 --- a/src/pages/login/index.tsx +++ b/src/pages/login/index.tsx @@ -6,7 +6,7 @@ import Login from 'components/Login'; import Container from 'components/Container'; import { getData, LS_KEYS } from 'utils/storage/localStorage'; import Card from 'react-bootstrap/Card'; -import { PAGES } from 'utils/constants'; +import { PAGES } from 'constants/pages'; export default function Home() { const router = useRouter(); diff --git a/src/pages/recover/index.tsx b/src/pages/recover/index.tsx index b4e3370ed..a6a7deee9 100644 --- a/src/pages/recover/index.tsx +++ b/src/pages/recover/index.tsx @@ -7,7 +7,7 @@ import { setData, } from 'utils/storage/localStorage'; import { useRouter } from 'next/router'; -import { PAGES } from 'utils/constants'; +import { PAGES } from 'constants/pages'; import CryptoWorker, { decryptAndStoreToken, SaveKeyInSessionStore, diff --git a/src/pages/signup/index.tsx b/src/pages/signup/index.tsx index ce7b105a3..78d2e5e27 100644 --- a/src/pages/signup/index.tsx +++ b/src/pages/signup/index.tsx @@ -6,7 +6,7 @@ import Container from 'components/Container'; import EnteSpinner from 'components/EnteSpinner'; import { getData, LS_KEYS } from 'utils/storage/localStorage'; import SignUp from 'components/SignUp'; -import { PAGES } from 'utils/constants'; +import { PAGES } from 'constants/pages'; export default function SignUpPage() { const router = useRouter(); diff --git a/src/pages/two-factor/recover/index.tsx b/src/pages/two-factor/recover/index.tsx index e7097c73b..867f4983b 100644 --- a/src/pages/two-factor/recover/index.tsx +++ b/src/pages/two-factor/recover/index.tsx @@ -11,7 +11,7 @@ import LogoImg from 'components/LogoImg'; import { logError } from 'utils/sentry'; import { recoverTwoFactor, removeTwoFactor } from 'services/userService'; import { AppContext, FLASH_MESSAGE_TYPE } from 'pages/_app'; -import { PAGES } from 'utils/constants'; +import { PAGES } from 'constants/pages'; const bip39 = require('bip39'); // mobile client library only supports english. bip39.setDefaultWordlist('english'); diff --git a/src/pages/two-factor/setup/index.tsx b/src/pages/two-factor/setup/index.tsx index 6f051da25..8fe4d432e 100644 --- a/src/pages/two-factor/setup/index.tsx +++ b/src/pages/two-factor/setup/index.tsx @@ -14,7 +14,7 @@ import { B64EncryptionResult } from 'utils/crypto'; import { encryptWithRecoveryKey } from 'utils/crypto'; import { setData, LS_KEYS, getData } from 'utils/storage/localStorage'; import { AppContext, FLASH_MESSAGE_TYPE } from 'pages/_app'; -import { PAGES } from 'utils/constants'; +import { PAGES } from 'constants/pages'; import { TwoFactorSecret } from 'types/user'; enum SetupMode { diff --git a/src/pages/two-factor/verify/index.tsx b/src/pages/two-factor/verify/index.tsx index f54a65c98..3ccdb14ee 100644 --- a/src/pages/two-factor/verify/index.tsx +++ b/src/pages/two-factor/verify/index.tsx @@ -5,7 +5,7 @@ import router from 'next/router'; import React, { useEffect, useState } from 'react'; import { Button, Card } from 'react-bootstrap'; import { logoutUser, verifyTwoFactor } from 'services/userService'; -import { PAGES } from 'utils/constants'; +import { PAGES } from 'constants/pages'; import { User } from 'types/user'; import { setData, LS_KEYS, getData } from 'utils/storage/localStorage'; import constants from 'utils/strings/constants'; diff --git a/src/pages/verify/index.tsx b/src/pages/verify/index.tsx index 21c250638..07023c5de 100644 --- a/src/pages/verify/index.tsx +++ b/src/pages/verify/index.tsx @@ -19,7 +19,7 @@ import SubmitButton from 'components/SubmitButton'; import { clearKeys } from 'utils/storage/sessionStorage'; import { AppContext } from 'pages/_app'; import LogoImg from 'components/LogoImg'; -import { PAGES } from 'utils/constants'; +import { PAGES } from 'constants/pages'; import { User } from '@sentry/nextjs'; import { KeyAttributes, EmailVerificationResponse } from 'types/user'; diff --git a/src/services/userService.ts b/src/services/userService.ts index 48f835bf6..94a5b2851 100644 --- a/src/services/userService.ts +++ b/src/services/userService.ts @@ -1,4 +1,4 @@ -import { PAGES } from 'utils/constants'; +import { PAGES } from 'constants/pages'; import { getEndpoint } from 'utils/common/apiUtil'; import { clearKeys } from 'utils/storage/sessionStorage'; import router from 'next/router'; diff --git a/src/types/upload/index.ts b/src/types/upload/index.ts index f8e09ec09..59bb15f70 100644 --- a/src/types/upload/index.ts +++ b/src/types/upload/index.ts @@ -1,5 +1,5 @@ import { fileAttribute, FILE_TYPE } from 'types/file'; -import { ENCRYPTION_CHUNK_SIZE } from 'utils/constants'; +import { ENCRYPTION_CHUNK_SIZE } from 'constants/crypto'; // list of format that were missed by type-detection for some files. export const FORMAT_MISSED_BY_FILE_TYPE_LIB = [ diff --git a/src/utils/crypto/libsodium.ts b/src/utils/crypto/libsodium.ts index 24a386dc7..e4678a2c7 100644 --- a/src/utils/crypto/libsodium.ts +++ b/src/utils/crypto/libsodium.ts @@ -1,5 +1,5 @@ import sodium, { StateAddress } from 'libsodium-wrappers'; -import { ENCRYPTION_CHUNK_SIZE } from 'utils/constants'; +import { ENCRYPTION_CHUNK_SIZE } from 'constants/crypto'; export async function decryptChaChaOneShot( data: Uint8Array,