Remove unused code

This commit is contained in:
Jackson Harper
2023-02-27 11:12:29 +08:00
parent 9d6a28cc74
commit 066766d980
36 changed files with 70 additions and 338 deletions

View File

@ -1,38 +0,0 @@
import { Root, Content, Anchor, Arrow } from '@radix-ui/react-popover'
import type { ReactNode } from 'react'
import { styled } from '../tokens/stitches.config'
type AnchoredPopoverProps = {
children: ReactNode
xAnchorCoordinate: number
yAnchorCoordinate: number
preventAutoFocus: boolean
}
export function AnchoredPopover(props: AnchoredPopoverProps): JSX.Element {
const StyledAnchor = styled(Anchor, {
position: 'absolute',
left: props.xAnchorCoordinate,
top: props.yAnchorCoordinate,
})
const StyledArrow = styled(Arrow, {
fill: '$grayBase',
})
return (
<Root defaultOpen modal>
<StyledAnchor />
<Content
onOpenAutoFocus={(event) => {
if (props.preventAutoFocus) {
event.preventDefault()
}
}}
>
{props.children}
<StyledArrow />
</Content>
</Root>
)
}

View File

@ -1,7 +1,6 @@
import { isAndroid } from '../../lib/deviceType'
import { styled, theme } from '../tokens/stitches.config'
import { AnchoredPopover } from '../patterns/AnchoredPopover'
import { StyledText } from '../elements/StyledText'
import { Button } from '../elements/Button'

View File

@ -7,7 +7,6 @@ import {
gauthRedirectURI,
appleAuthRedirectURI,
} from '../../lib/appConfig'
import AppleLogin from 'react-apple-login'
import { AppleIdButton } from './auth/AppleIdButton'
export type LoginFormProps = {

View File

@ -81,16 +81,12 @@ function MediumLoginLayout(props: LoginFormProps) {
>
<LoginForm {...props} />
</Box>
<OmnivoreIllustration isLargeLayout={true} />
<OmnivoreIllustration />
</HStack>
)
}
type OmnivoreIllustrationProps = {
isLargeLayout?: boolean
}
function OmnivoreIllustration({ isLargeLayout }: OmnivoreIllustrationProps) {
function OmnivoreIllustration() {
return (
<Box
css={{

View File

@ -50,7 +50,7 @@ export function PrimaryDropdown(): JSX.Element {
break
}
},
[updateTheme, router]
[router]
)
if (!viewerData?.me) {

View File

@ -47,7 +47,7 @@ export function PrimaryLayout(props: PrimaryLayoutProps): JSX.Element {
if (!user && viewerData?.me?.id) {
window.analytics?.identify({ userId: viewerData?.me?.id })
}
}, [viewerData?.me?.id])
}, [viewerData?.me])
async function logout(): Promise<void> {
await logoutMutation()
@ -65,7 +65,7 @@ export function PrimaryLayout(props: PrimaryLayoutProps): JSX.Element {
const showLogout = useCallback(() => {
setShowLogoutConfirmation(true)
}, [showLogoutConfirmation, setShowLogoutConfirmation, logoutMutation])
}, [setShowLogoutConfirmation])
useEffect(() => {
document.addEventListener('logout', showLogout)

View File

@ -8,7 +8,6 @@ import {
} from 'phosphor-react'
import { ArticleAttributes } from '../../../lib/networking/queries/useGetArticleQuery'
import { Button } from '../../elements/Button'
import { Dropdown } from '../../elements/DropdownElements'
import { Box, SpanBox } from '../../elements/LayoutPrimitives'
import { TooltipWrapped } from '../../elements/Tooltip'
import { styled, theme } from '../../tokens/stitches.config'
@ -42,12 +41,6 @@ const MenuSeparator = (props: MenuSeparatorProps): JSX.Element => {
return props.layout == 'side' ? <LineSeparator /> : <></>
}
type ActionDropdownProps = {
layout: ArticleActionsMenuLayout
triggerElement: JSX.Element
children: JSX.Element
}
export function ArticleActionsMenu(
props: ArticleActionsMenuProps
): JSX.Element {

View File

@ -3,7 +3,6 @@ import { Article } from './../../../components/templates/article/Article'
import { Box, HStack, SpanBox, VStack } from './../../elements/LayoutPrimitives'
import { StyledText } from './../../elements/StyledText'
import {
ArticleSavedInfo,
ArticleSubtitle,
ReaderSavedInfo,
} from './../../patterns/ArticleSubtitle'

View File

@ -10,8 +10,6 @@ import { Highlight } from '../../../lib/networking/fragments/highlightFragment'
import { useCallback, useState } from 'react'
import { StyledTextArea } from '../../elements/StyledTextArea'
import { updateHighlightMutation } from '../../../lib/networking/mutations/updateHighlightMutation'
import { readableUpdatedAtMessage } from './../../../lib/dateFormatting'
import { useConfirmListener } from '../../../lib/keyboardShortcuts/useKeyboardShortcuts'
import { showErrorToast } from '../../../lib/toastHelpers'
type HighlightNoteModalProps = {

View File

@ -4,20 +4,14 @@ import {
ModalContent,
ModalTitleBar,
} from '../../elements/ModalPrimitives'
import {
Box,
HStack,
VStack,
Separator,
SpanBox,
} from '../../elements/LayoutPrimitives'
import { Box, HStack, VStack, SpanBox } from '../../elements/LayoutPrimitives'
import { Button } from '../../elements/Button'
import { StyledText } from '../../elements/StyledText'
import { TrashIcon } from '../../elements/images/TrashIcon'
import { theme } from '../../tokens/stitches.config'
import type { Highlight } from '../../../lib/networking/fragments/highlightFragment'
import { HighlightView } from '../../patterns/HighlightView'
import { useCallback, useMemo, useRef, useState } from 'react'
import { useCallback, useMemo, useState } from 'react'
import { StyledTextArea } from '../../elements/StyledTextArea'
import { ConfirmationModal } from '../../patterns/ConfirmationModal'
import { DotsThree } from 'phosphor-react'

View File

@ -2,13 +2,7 @@ import { ArticleAttributes } from '../../../lib/networking/queries/useGetArticle
import { Box } from '../../elements/LayoutPrimitives'
import { v4 as uuidv4 } from 'uuid'
import { nanoid } from 'nanoid'
import {
useState,
useEffect,
useCallback,
useRef,
ReactComponentElement,
} from 'react'
import { useState, useEffect, useCallback, useRef } from 'react'
import { isDarkTheme } from '../../../lib/themeUpdater'
import PSPDFKit from 'pspdfkit'
import { Instance, HighlightAnnotation, List, Annotation, Rect } from 'pspdfkit'

View File

@ -1,14 +1,13 @@
import { HStack, VStack, SpanBox, Box } from '../../elements/LayoutPrimitives'
import { HStack, VStack, SpanBox } from '../../elements/LayoutPrimitives'
import { Button } from '../../elements/Button'
import { StyledText } from '../../elements/StyledText'
import { styled, theme } from '../../tokens/stitches.config'
import { useEffect, useState } from 'react'
import { useState } from 'react'
import {
AlignCenterHorizontalSimple,
ArrowsInLineHorizontal,
ArrowsOutLineHorizontal,
CaretRight,
Cursor,
} from 'phosphor-react'
import { TickedRangeSlider } from '../../elements/TickedRangeSlider'
import { showSuccessToast } from '../../../lib/toastHelpers'

View File

@ -275,7 +275,7 @@ export function SetLabelsControl(props: SetLabelsControlProps): JSX.Element {
revalidate()
},
[isSelected, props]
[isSelected, props, revalidate]
)
const filteredLabels = useMemo(() => {
@ -295,6 +295,23 @@ export function SetLabelsControl(props: SetLabelsControlProps): JSX.Element {
const [focusedIndex, setFocusedIndex] = useState<number | undefined>(
undefined
)
const createLabelFromFilterText = useCallback(async () => {
const label = await createLabelMutation(
filterText,
randomLabelColorHex(),
''
)
if (label) {
showSuccessToast(`Created label ${label.name}`, {
position: 'bottom-right',
})
toggleLabel(label)
} else {
showErrorToast('Failed to create label', { position: 'bottom-right' })
}
}, [filterText, toggleLabel])
const handleKeyDown = useCallback(
async (event: React.KeyboardEvent<HTMLInputElement>) => {
const maxIndex = filteredLabels.length + 1
@ -346,24 +363,15 @@ export function SetLabelsControl(props: SetLabelsControlProps): JSX.Element {
}
}
},
[filterText, filteredLabels, focusedIndex, isSelected, props]
)
const createLabelFromFilterText = useCallback(async () => {
const label = await createLabelMutation(
[
filterText,
randomLabelColorHex(),
''
)
if (label) {
showSuccessToast(`Created label ${label.name}`, {
position: 'bottom-right',
})
toggleLabel(label)
} else {
showErrorToast('Failed to create label', { position: 'bottom-right' })
}
}, [filterText, props, toggleLabel])
filteredLabels,
focusedIndex,
createLabelFromFilterText,
router,
toggleLabel,
]
)
return (
<VStack

View File

@ -56,7 +56,7 @@ export function SetLabelsModal(props: SetLabelsModalProps): JSX.Element {
props.onOpenChange(open)
},
[props, selectedLabels, previousSelectedLabels, setSelectedLabels]
[props, selectedLabels, previousSelectedLabels]
)
useEffect(() => {
@ -72,7 +72,7 @@ export function SetLabelsModal(props: SetLabelsModalProps): JSX.Element {
.catch((err) => {
console.log('error saving labels: ', err)
})
}, [selectedLabels, setPreviousSelectedLabels])
}, [props, selectedLabels, previousSelectedLabels, setPreviousSelectedLabels])
return (
<ModalRoot defaultOpen onOpenChange={onOpenChange}>

View File

@ -1,5 +1,4 @@
import { Box } from '../../elements/LayoutPrimitives'
import { StyledText } from '../../elements/StyledText'
import { theme } from '../../tokens/stitches.config'
type SkeletonArticleContainerProps = {

View File

@ -5,7 +5,6 @@ import { useEffect, useState } from 'react'
import { BorderedFormInput, FormLabel } from '../../elements/FormElements'
import { fetchEndpoint } from '../../../lib/appConfig'
import { logoutMutation } from '../../../lib/networking/mutations/logoutMutation'
import { styled } from '@stitches/react'
import { useRouter } from 'next/router'
import { parseErrorCodes } from '../../../lib/queryParamParser'
import { formatMessage } from '../../../locales/en/messages'
@ -15,8 +14,9 @@ export function EmailLogin(): JSX.Element {
const router = useRouter()
const [email, setEmail] = useState<string | undefined>(undefined)
const [password, setPassword] = useState<string | undefined>(undefined)
const [errorMessage, setErrorMessage] =
useState<string | undefined>(undefined)
const [errorMessage, setErrorMessage] = useState<string | undefined>(
undefined
)
useEffect(() => {
if (!router.isReady) return

View File

@ -7,7 +7,6 @@ import { TermAndConditionsFooter } from '../LoginForm'
import { fetchEndpoint } from '../../../lib/appConfig'
import { useValidateUsernameQuery } from '../../../lib/networking/queries/useValidateUsernameQuery'
import { logoutMutation } from '../../../lib/networking/mutations/logoutMutation'
import { styled } from '@stitches/react'
import { useRouter } from 'next/router'
import { formatMessage } from '../../../locales/en/messages'
import { parseErrorCodes } from '../../../lib/queryParamParser'
@ -19,10 +18,12 @@ export function EmailSignup(): JSX.Element {
const [password, setPassword] = useState<string | undefined>(undefined)
const [fullname, setFullname] = useState<string | undefined>(undefined)
const [username, setUsername] = useState<string | undefined>(undefined)
const [debouncedUsername, setDebouncedUsername] =
useState<string | undefined>(undefined)
const [errorMessage, setErrorMessage] =
useState<string | undefined>(undefined)
const [debouncedUsername, setDebouncedUsername] = useState<
string | undefined
>(undefined)
const [errorMessage, setErrorMessage] = useState<string | undefined>(
undefined
)
useEffect(() => {
if (!router.isReady) return
@ -165,7 +166,7 @@ export function EmailSignup(): JSX.Element {
style={'ctaOutlineYellow'}
css={{ color: '$omnivoreGray', borderColor: 'rgba(0, 0, 0, 0.06)' }}
type="button"
onClick={async (event) => {
onClick={async () => {
window.localStorage.removeItem('authVerified')
window.localStorage.removeItem('authToken')
try {

View File

@ -1,7 +1,6 @@
import { Box, HStack } from '../../elements/LayoutPrimitives'
import type { LoginFormProps } from '../LoginForm'
export function ResetSent(props: LoginFormProps): JSX.Element {
export function ResetSent(): JSX.Element {
return (
<>
<HStack

View File

@ -1,7 +1,6 @@
import { Box, HStack } from '../../elements/LayoutPrimitives'
import type { LoginFormProps } from '../LoginForm'
export function VerifyEmail(props: LoginFormProps): JSX.Element {
export function VerifyEmail(): JSX.Element {
return (
<>
<HStack

View File

@ -441,9 +441,6 @@ export function HomeFeedContainer(): JSX.Element {
case 'showEditLabelsModal':
handleCardAction('set-labels', activeItem)
break
case 'shareItem':
setShareTarget(activeItem)
break
case 'sortDescending':
setQueryInputs({ ...queryInputs, sortDescending: true })
break

View File

@ -1,14 +1,21 @@
import { Highlight } from "./networking/fragments/highlightFragment"
import { ArticleReadingProgressMutationInput } from "./networking/mutations/articleReadingProgressMutation"
import { CreateHighlightInput } from "./networking/mutations/createHighlightMutation"
import { MergeHighlightInput, MergeHighlightOutput } from "./networking/mutations/mergeHighlightMutation"
import { UpdateHighlightInput } from "./networking/mutations/updateHighlightMutation"
import { Highlight } from './networking/fragments/highlightFragment'
import { ArticleReadingProgressMutationInput } from './networking/mutations/articleReadingProgressMutation'
import { CreateHighlightInput } from './networking/mutations/createHighlightMutation'
import { MergeHighlightInput } from './networking/mutations/mergeHighlightMutation'
import { UpdateHighlightInput } from './networking/mutations/updateHighlightMutation'
export type ArticleMutations = {
createHighlightMutation: (input: CreateHighlightInput) => Promise<Highlight | undefined>
createHighlightMutation: (
input: CreateHighlightInput
) => Promise<Highlight | undefined>
deleteHighlightMutation: (highlightId: string) => Promise<boolean>
mergeHighlightMutation: (input: MergeHighlightInput) => Promise<Highlight | undefined>
updateHighlightMutation: (input: UpdateHighlightInput) => Promise<string | undefined>
articleReadingProgressMutation: (input: ArticleReadingProgressMutationInput) => Promise<boolean>
mergeHighlightMutation: (
input: MergeHighlightInput
) => Promise<Highlight | undefined>
updateHighlightMutation: (
input: UpdateHighlightInput
) => Promise<string | undefined>
articleReadingProgressMutation: (
input: ArticleReadingProgressMutationInput
) => Promise<boolean>
}

View File

@ -13,48 +13,3 @@ export function formattedShortDate(rawDate: string): string {
dateStyle: 'short',
}).format(new Date(rawDate))
}
export function readableUpdatedAtMessage(
rawDate: string,
customPrefix?: string
): string {
const prefix = customPrefix || 'Updated '
const timeElapsed = Math.ceil(
new Date().valueOf() - new Date(rawDate).valueOf()
)
const secondsElapsed = timeElapsed / 1000
if (secondsElapsed < 60) {
return `${prefix} a few seconds ago`
}
if (secondsElapsed < 3600) {
return `${prefix} ${Math.floor(secondsElapsed / 60)} minutes ago`
}
if (secondsElapsed < 86400) {
return `${prefix} ${Math.floor(secondsElapsed / 3600)} hours ago`
}
if (secondsElapsed < 604800) {
return `${prefix} ${Math.floor(secondsElapsed / 86400)} days ago`
}
if (secondsElapsed < 2592000) {
return `${prefix} ${Math.floor(secondsElapsed / 604800)} weeks ago`
}
if (secondsElapsed < 31536000) {
return `${prefix} ${Math.floor(secondsElapsed / 2592000)} months ago`
}
if (secondsElapsed < 315360000) {
return `${prefix} ${Math.floor(secondsElapsed / 31536000)} years ago`
}
if (secondsElapsed < 3153600000) {
return `${prefix} ${Math.floor(secondsElapsed / 315360000)} decades ago`
}
return ''
}

View File

@ -468,19 +468,6 @@ const getSurroundingText = ({
}
}
function stringToColour(str: string): string {
let hash = 0
for (let i = 0; i < str.length; i++) {
hash = str.charCodeAt(i) + ((hash << 5) - hash)
}
let colour = '#'
for (let i = 0; i < 3; i++) {
const value = (hash >> (i * 8)) & 0xff
colour += ('00' + value.toString(16)).substr(-2)
}
return colour
}
export const isValidLength = (patch: string): boolean => {
const { highlightTextStart, highlightTextEnd } = getPrefixAndSuffix({ patch })
return highlightTextEnd - highlightTextStart < maxHighlightLength

View File

@ -158,8 +158,8 @@ export const removeItemFromCache = (
) => {
try {
const mappedCache = cache as Map<string, unknown>
mappedCache.forEach((value: unknown, key) => {
if (typeof value == 'object' && 'search' in value) {
mappedCache.forEach((value: any, key) => {
if (value && typeof value == 'object' && 'search' in value) {
const search = value.search as LibraryItems
const idx = search.edges.findIndex((edge) => edge.node.id == itemId)
if (idx > -1) {

View File

@ -3,8 +3,6 @@ import {
lighterTheme,
darkTheme,
darkerTheme,
sepiaTheme,
charcoalTheme,
} from '../components/tokens/stitches.config'
import { userPersonalizationMutation } from './networking/mutations/userPersonalizationMutation'

View File

@ -44,7 +44,6 @@
"phosphor-react": "^1.4.0",
"pspdfkit": "^2022.2.3",
"react": "^17.0.2",
"react-apple-login": "^1.1.3",
"react-colorful": "^5.5.1",
"react-dom": "^17.0.2",
"react-dropzone": "^14.2.3",

View File

@ -1,23 +0,0 @@
import { useRouter } from "next/router";
import { OnboardingAddNewsletters } from "../../components/templates/onboarding/OnboardingAddNewsletters";
import { OnboardingInstallInstructions } from "../../components/templates/onboarding/OnboardingInstallInstructions";
import { OnboardingJoinCommunity } from "../../components/templates/onboarding/OnboardingJoinCommunity";
import { OnboardingReaderPreview } from "../../components/templates/onboarding/OnboardingReaderPreview";
export default function Onboarding() {
const router = useRouter();
const { index: pageNumber } = router.query;
switch (pageNumber) {
case "01":
return <OnboardingReaderPreview pageNumber={1} />;
case "02":
return <OnboardingInstallInstructions pageNumber={2} />;
case "03":
return <OnboardingAddNewsletters pageNumber={3} />;
case "04":
return <OnboardingJoinCommunity pageNumber={4} />;
}
return <OnboardingReaderPreview pageNumber={1} />
}

View File

@ -122,7 +122,7 @@ export default function Integrations(): JSX.Element {
},
},
])
}, [deleteIntegration, readwiseConnected, router, webhooks])
}, [readwiseConnected, router, webhooks])
return (
<PrimaryLayout pageTestId={'integrations'}>

View File

@ -1,44 +0,0 @@
import { ComponentStory, ComponentMeta } from '@storybook/react'
import { OnboardingLayout } from '../components/templates/OnboardingLayout'
export default {
title: 'Components/OnboardingLayout',
component: OnboardingLayout,
argTypes: {
pageNumber: {
description: 'The current page number of the onboarding process',
},
title: {
description: 'The title of the current onboading screen',
},
subTitle: {
description: 'The subtitle of the current onboading screen',
},
description: {
description: 'The description of the current onboading screen',
},
children: {
description: 'The right column on the page',
},
image: {
description: 'The image on the left column on the page',
},
nextPage: {
description: 'The link to which the user is sent when next button is pressed'
}
},
} as ComponentMeta<typeof OnboardingLayout>
const Template: ComponentStory<typeof OnboardingLayout> = (args) => (
<OnboardingLayout {...args}>{args.children}</OnboardingLayout>
)
export const OnboardingLayoutStory = Template.bind({})
OnboardingLayoutStory.args = {
pageNumber: 2,
title: 'Save links to read later',
subTitle:
'Save any link to your library using our apps and browser extensions',
description: 'Install our apps and browser extensions',
children: <div>This is where the child is rendered.</div>
}

View File

@ -1,13 +0,0 @@
import { ComponentStory, ComponentMeta } from '@storybook/react'
import { OnboardingReaderPreview } from '../components/templates/onboarding/OnboardingReaderPreview'
export default {
title: 'Onboarding-Pages/01',
component: OnboardingReaderPreview,
} as ComponentMeta<typeof OnboardingReaderPreview>
export const OnboardingPage1Story: ComponentStory<typeof OnboardingReaderPreview> = (args: any) => {
return (
<OnboardingReaderPreview pageNumber={1} />
)
}

View File

@ -1,13 +0,0 @@
import { ComponentStory, ComponentMeta } from '@storybook/react'
import { OnboardingInstallInstructions } from '../components/templates/onboarding/OnboardingInstallInstructions'
export default {
title: 'Onboarding-Pages/02',
component: OnboardingInstallInstructions,
} as ComponentMeta<typeof OnboardingInstallInstructions>
export const OnboardingPage2Story: ComponentStory<typeof OnboardingInstallInstructions> = (args: any) => {
return (
<OnboardingInstallInstructions pageNumber={2} />
)
}

View File

@ -1,13 +0,0 @@
import { ComponentStory, ComponentMeta } from '@storybook/react'
import { OnboardingAddNewsletters } from '../components/templates/onboarding/OnboardingAddNewsletters'
export default {
title: 'Onboarding-Pages/03',
component: OnboardingAddNewsletters,
} as ComponentMeta<typeof OnboardingAddNewsletters>
export const OnboardingPage3Story: ComponentStory<typeof OnboardingAddNewsletters> = (args: any) => {
return (
<OnboardingAddNewsletters pageNumber={3} />
)
}

View File

@ -1,13 +0,0 @@
import { ComponentStory, ComponentMeta } from '@storybook/react'
import { OnboardingOrganizeInstructions } from '../components/templates/onboarding/OnboardingOrganizeInstructions'
export default {
title: 'Onboarding-Pages/04',
component: OnboardingOrganizeInstructions,
} as ComponentMeta<typeof OnboardingOrganizeInstructions>
export const OnboardingPage4Story: ComponentStory<typeof OnboardingOrganizeInstructions> = (args: any) => {
return (
<OnboardingOrganizeInstructions pageNumber={4} />
)
}

View File

@ -1,13 +0,0 @@
import { ComponentStory, ComponentMeta } from '@storybook/react'
import { OnboardingHighlightInstructions } from '../components/templates/onboarding/OnboardingHighlightInstructions'
export default {
title: 'Onboarding-Pages/05',
component: OnboardingHighlightInstructions,
} as ComponentMeta<typeof OnboardingHighlightInstructions>
export const OnboardingPage5Story: ComponentStory<typeof OnboardingHighlightInstructions> = (args: any) => {
return (
<OnboardingHighlightInstructions pageNumber={5} />
)
}

View File

@ -1,13 +0,0 @@
import { ComponentStory, ComponentMeta } from '@storybook/react'
import { OnboardingJoinCommunity } from '../components/templates/onboarding/OnboardingJoinCommunity'
export default {
title: 'Onboarding-Pages/06',
component: OnboardingJoinCommunity,
} as ComponentMeta<typeof OnboardingJoinCommunity>
export const OnboardingPage6Story: ComponentStory<typeof OnboardingJoinCommunity> = (args: any) => {
return (
<OnboardingJoinCommunity pageNumber={6} />
)
}

View File

@ -22886,11 +22886,6 @@ rc@^1.2.8:
minimist "^1.2.0"
strip-json-comments "~2.0.1"
react-apple-login@^1.1.3:
version "1.1.3"
resolved "https://registry.yarnpkg.com/react-apple-login/-/react-apple-login-1.1.3.tgz#5cb047a52a251fc52d920c7b4d9151d411994997"
integrity sha512-I6/2WQEfum9QGowHs9Maea5JhzsOjl8dMCqFP5got+jnnNZRimLE6wGambAvDXdiOuLr+gwMQx5W4JeBGKJHTA==
react-colorful@^5.1.2, react-colorful@^5.5.1:
version "5.5.1"
resolved "https://registry.yarnpkg.com/react-colorful/-/react-colorful-5.5.1.tgz#29d9c4e496f2ca784dd2bb5053a3a4340cfaf784"