Skip to content

Commit

Permalink
[Monorepo] move a bit more code to UI (#421)
Browse files Browse the repository at this point in the history
Closes DG-134

## What changed? Why?
Moves a bit more code out to UI/shared-core around helpers and
formatting. Also fixes caching weirdness with eslint since turbo caching
is plenty
  • Loading branch information
dgattey committed Dec 28, 2023
1 parent 0dc1125 commit ff7cf64
Show file tree
Hide file tree
Showing 34 changed files with 44 additions and 48 deletions.
3 changes: 1 addition & 2 deletions apps/web/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"build:analyze": "ANALYZE=true next build",
"build:serve": "next start",
"format": "prettier --write .",
"lint": "eslint . --cache --fix",
"lint": "eslint . --fix",
"lint:types": "tsc",
"clean": "rm -rf .next"
},
Expand Down Expand Up @@ -40,7 +40,6 @@
"sharp": "0.33.1",
"swr": "2.2.4",
"ui": "workspace:*",
"use-breakpoint": "4.0.1",
"webpack": "5.89.0"
},
"devDependencies": {
Expand Down
4 changes: 2 additions & 2 deletions apps/web/src/components/ColorSchemeIcon.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { Moon, Sun, RefreshCw } from 'lucide-react';
import type { Theme } from '@mui/material';
import { Box, IconButton, Tooltip } from '@mui/material';
import { useColorScheme } from 'hooks/useColorScheme';
import type { ColorSchemeMode } from 'hooks/useColorScheme';
import { useColorScheme } from 'ui/theme/useColorScheme';
import type { ColorSchemeMode } from 'ui/theme/useColorScheme';

type ColorSchemeIconProps = {
/**
Expand Down
2 changes: 1 addition & 1 deletion apps/web/src/components/ColorSchemeToggle.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Stack, Switch, switchClasses } from '@mui/material';
import { useColorScheme } from 'ui/theme/useColorScheme';
import { ColorSchemeIcon } from 'components/ColorSchemeIcon';
import { useColorScheme } from 'hooks/useColorScheme';

const HEIGHT_PX = 24;
const WIDTH_PX = 48;
Expand Down
2 changes: 1 addition & 1 deletion apps/web/src/components/ContentCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ import type { Theme } from '@mui/material';
import { Card, Typography } from '@mui/material';
import { mixinSx } from 'ui/helpers/mixinSx';
import type { SxProps } from 'ui/theme';
import { truncated } from 'ui/helpers/truncated';
import type { Link } from 'api/types/generated/contentfulApi.generated';
import { truncated } from 'helpers/truncated';
import { ContentWrappingLink } from './ContentWrappingLink';

export type ContentCardProps = Pick<
Expand Down
2 changes: 1 addition & 1 deletion apps/web/src/components/ContentWrappingLink.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { SxProps } from 'ui/theme';
import type { Link as LinkType } from 'api/types/generated/contentfulApi.generated';
import { Link } from 'components/Link';
import type { SxProps } from 'ui/theme';

type ContentWrappingLinkProps = Pick<React.ComponentProps<'div'>, 'children'> & {
/**
Expand Down
2 changes: 1 addition & 1 deletion apps/web/src/components/Header.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ import { Box, alpha } from '@mui/material';
import { Section } from 'ui/core/Section';
import { Nav, NavGroup, NavItem } from 'ui/core/Nav';
import type { SxProps } from 'ui/theme';
import { useColorScheme } from 'ui/theme/useColorScheme';
import { ScrollIndicatorContext } from 'components/ScrollIndicatorContext';
import { ScrollUpButton } from 'components/ScrollUpButton';
import { ColorSchemeToggle } from 'components/ColorSchemeToggle';
import { useColorScheme } from 'hooks/useColorScheme';
import { Logo } from './Logo';

type HeaderProps = {
Expand Down
2 changes: 1 addition & 1 deletion apps/web/src/components/Image.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { styled } from '@mui/material';
import NextImage from 'next/image';
import { BREAKPOINT_MAX_SIZES } from 'appConstants/imageSizes';
import { BREAKPOINT_MAX_SIZES } from 'ui/helpers/imageSizes';
import type { Asset } from 'api/types/generated/contentfulApi.generated';

type ImageProps = Partial<Asset> & {
Expand Down
2 changes: 1 addition & 1 deletion apps/web/src/components/Link.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ import { faQuestion } from '@fortawesome/free-solid-svg-icons/faQuestion';
import NextLink from 'next/link';
import type { LinkProps as MuiLinkProps, ButtonProps } from '@mui/material';
import { Link as MuiLink, Tooltip, Button } from '@mui/material';
import { FaIcon } from 'components/FaIcon';
import type { SxProps } from 'ui/theme';
import { FaIcon } from 'components/FaIcon';

type BaseLinkProps = {
title?: string;
Expand Down
4 changes: 2 additions & 2 deletions apps/web/src/components/RichText.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@ import type { Document, NodeData } from '@contentful/rich-text-types';
import { BLOCKS, INLINES } from '@contentful/rich-text-types';
import { Divider, Stack, Typography } from '@mui/material';
import { isNotNullish } from 'shared-core/helpers/typeguards';
import { PROJECT_MAX_IMAGE_DIMENSION } from 'appConstants/imageSizes';
import type { SxProps } from 'ui/theme';
import { PROJECT_MAX_IMAGE_DIMENSION } from 'ui/helpers/imageSizes';
import { isLink, isProject } from 'api/parsers';
import type { Asset, Entry, TextBlockContent } from 'api/types/generated/contentfulApi.generated';
import { ProjectCard } from 'components/homepage/ProjectCard';
import type { SxProps } from 'ui/theme';
import { Image } from './Image';
import { Link } from './Link';

Expand Down
2 changes: 1 addition & 1 deletion apps/web/src/components/homepage/IntroCard.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { useState } from 'react';
import { useCurrentImageSizes } from 'ui/helpers/useCurrentImageSizes';
import { useData } from 'api/useData';
import { ContentCard } from 'components/ContentCard';
import { HoverableContainer } from 'components/HoverableContainer';
import { Image } from 'components/Image';
import { RichText } from 'components/RichText';
import { useLinkWithName } from 'hooks/useLinkWithName';
import { useCurrentImageSizes } from 'hooks/useCurrentImageSizes';

/**
* Width of the intro image on small screens
Expand Down
2 changes: 1 addition & 1 deletion apps/web/src/components/homepage/MapPreviewCard.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { Suspense, useState } from 'react';
import dynamic from 'next/dynamic';
import { useColorScheme } from 'ui/theme/useColorScheme';
import { useData } from 'api/useData';
import type { ContentCardProps } from 'components/ContentCard';
import { MapContentCard } from 'components/maps/MapContentCard';
import { useColorScheme } from 'hooks/useColorScheme';

type MapPreviewCardProps = Pick<ContentCardProps, 'turnOnAnimation'>;

Expand Down
2 changes: 1 addition & 1 deletion apps/web/src/components/homepage/ProjectCard.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { useState } from 'react';
import { useCurrentImageSizes } from 'ui/helpers/useCurrentImageSizes';
import type { Project } from 'api/types/generated/contentfulApi.generated';
import type { ContentCardProps } from 'components/ContentCard';
import { ContentCard } from 'components/ContentCard';
import { HoverableContainer } from 'components/HoverableContainer';
import { Image } from 'components/Image';
import { useCurrentImageSizes } from 'hooks/useCurrentImageSizes';

type ProjectCardProps = Project & Pick<ContentCardProps, 'turnOnAnimation'>;

Expand Down
2 changes: 1 addition & 1 deletion apps/web/src/components/maps/Map.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ import { useEffect, useMemo, useRef } from 'react';
import type { MapRef } from 'react-map-gl';
import { AttributionControl, Map as MapGL } from 'react-map-gl';
import { Box, useTheme } from '@mui/material';
import { useColorScheme } from 'ui/theme/useColorScheme';
import type { MapLocation } from 'api/types/MapLocation';
import { useColorScheme } from 'hooks/useColorScheme';
import { StandardControls } from './StandardControls';

export type MapProps = {
Expand Down
2 changes: 1 addition & 1 deletion apps/web/src/components/maps/MapContentCard.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import type { CardProps } from '@mui/material';
import { mixinSx } from 'ui/helpers/mixinSx';
import type { ContentCardProps } from 'components/ContentCard';
import { ContentCard } from 'components/ContentCard';
import { mixinSx } from 'ui/helpers/mixinSx';

// In px, the min/max size of the card - matches standard size
const MIN_DIMENSION = 297;
Expand Down
2 changes: 1 addition & 1 deletion apps/web/src/components/maps/Marker.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Marker as MapMarker } from 'react-map-gl';
import { Box } from '@mui/material';
import { MAP_MARKER_IMAGE_SIZE } from 'appConstants/imageSizes';
import { MAP_MARKER_IMAGE_SIZE } from 'ui/helpers/imageSizes';
import type { MapLocation } from 'api/types/MapLocation';
import { Image } from 'components/Image';

Expand Down
2 changes: 1 addition & 1 deletion apps/web/src/components/spotify/ArtistList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@

import { Fragment } from 'react';
import { Typography } from '@mui/material';
import { truncated } from 'ui/helpers/truncated';
import type { Artist } from 'api/types/spotify/Track';
import { Link } from 'components/Link';
import { useLinkWithName } from 'hooks/useLinkWithName';
import { truncated } from 'helpers/truncated';

type ArtistListProps = {
artists: Array<Artist>;
Expand Down
6 changes: 3 additions & 3 deletions apps/web/src/components/spotify/TrackTitle.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { Typography } from '@mui/material';
import { Link } from 'components/Link';
import { useLinkWithName } from 'hooks/useLinkWithName';
import type { SxProps } from 'ui/theme';
import { truncated } from 'helpers/truncated';
import { truncated } from 'ui/helpers/truncated';
import { mixinSx } from 'ui/helpers/mixinSx';
import { useLinkWithName } from 'hooks/useLinkWithName';
import { Link } from 'components/Link';

type TrackTitleProps = {
trackTitle: string;
Expand Down
2 changes: 1 addition & 1 deletion apps/web/src/components/strava/ActivityDescription.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { truncated } from 'ui/helpers/truncated';
import { useData } from 'api/useData';
import { truncated } from 'helpers/truncated';
import { Link } from 'components/Link';

/**
Expand Down
6 changes: 3 additions & 3 deletions apps/web/src/components/strava/ActivityName.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { useData } from 'api/useData';
import { truncated } from 'helpers/truncated';
import { Link } from 'components/Link';
import { truncated } from 'ui/helpers/truncated';
import { mixinSx } from 'ui/helpers/mixinSx';
import type { SxProps } from 'ui/theme';
import { Link } from 'components/Link';
import { useData } from 'api/useData';

/**
* Formatted link for the activity name
Expand Down
6 changes: 3 additions & 3 deletions apps/web/src/components/strava/ActivityStats.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { faStrava } from '@fortawesome/free-brands-svg-icons/faStrava';
import { Typography } from '@mui/material';
import { HorizontalStack } from 'ui/core/HorizontalStack';
import { formattedDistance } from 'shared-core/helpers/formattedDistance';
import { useData } from 'api/useData';
import { FaIcon } from 'components/FaIcon';
import { useRelativeTimeFormat } from 'hooks/useRelativeTimeFormat';
import { useFormattedDistance } from 'hooks/useFormattedDistance';

/**
* Shows a horizontal stack of stats for the latest strava activity
Expand All @@ -16,7 +16,7 @@ export function ActivityStats() {
fromDate: activity?.start_date,
capitalized: true,
});
const formattedDistance = useFormattedDistance({ distanceInMeters: activity?.distance });
const distance = formattedDistance({ distanceInMeters: activity?.distance });

if (!activity?.start_date || !activity.distance) {
return null;
Expand All @@ -36,7 +36,7 @@ export function ActivityStats() {
}}
>
<FaIcon icon={faStrava} />
<Typography variant="caption">{formattedDistance}</Typography>
<Typography variant="caption">{distance}</Typography>
</HorizontalStack>
<Typography variant="caption">{formattedDate}</Typography>
</HorizontalStack>
Expand Down
2 changes: 1 addition & 1 deletion apps/web/src/og/OpenGraphImage.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { BackgroundPattern } from 'og/BackgroundPattern';
import { COLORS } from 'ui/theme/color';
import { BackgroundPattern } from 'og/BackgroundPattern';

export const TEXT_FONT = 'SF Pro Text';
export const LOGO_FONT = 'SF Pro Text Black';
Expand Down
2 changes: 1 addition & 1 deletion packages/api/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"private": true,
"scripts": {
"format": "prettier --write .",
"lint": "eslint . --cache --fix",
"lint": "eslint . --fix",
"lint:types": "tsc"
},
"dependencies": {
Expand Down
2 changes: 1 addition & 1 deletion packages/codegen/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"scripts": {
"codegen": "graphql-codegen --config config.ts",
"format": "prettier --write .",
"lint": "eslint . --cache --fix",
"lint": "eslint . --fix",
"lint:types": "tsc"
},
"devDependencies": {
Expand Down
2 changes: 1 addition & 1 deletion packages/db/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"build:analyze": "pscale connect dg --port 3309",
"db": "sequelize",
"format": "prettier --write .",
"lint": "eslint . --cache --fix",
"lint": "eslint . --fix",
"lint:types": "tsc"
},
"dependencies": {
Expand Down
2 changes: 1 addition & 1 deletion packages/eslint-config-dg/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
],
"scripts": {
"format": "prettier --write .",
"lint": "eslint . --cache --fix",
"lint": "eslint . --fix",
"lint:types": "tsc"
},
"devDependencies": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ function metersToMiles(value: number) {
* Converts meters to miles and outputs a nicely formatted string
* for display usage.
*/
export function useFormattedDistance({
export function formattedDistance({
distanceInMeters,
}: {
distanceInMeters: number | undefined | null;
Expand Down
2 changes: 1 addition & 1 deletion packages/shared-core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"private": true,
"scripts": {
"format": "prettier --write .",
"lint": "eslint . --cache --fix",
"lint": "eslint . --fix",
"lint:types": "tsc"
},
"devDependencies": {
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { SxProps } from 'ui/theme';
import type { SxProps } from '@mui/material';

/**
* Returns styling to use to truncate to a specified number of
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
import { useBreakpoint } from 'use-breakpoint';
import {
BREAKPOINTS_MIN_SIZES,
PROJECT_2X_IMAGE_SIZES,
PROJECT_IMAGE_SIZES,
} from 'appConstants/imageSizes';
import { BREAKPOINTS_MIN_SIZES, PROJECT_2X_IMAGE_SIZES, PROJECT_IMAGE_SIZES } from './imageSizes';

/**
* Grabs the current breakpoint and returns the appropriate image sizes for the current
Expand Down
5 changes: 3 additions & 2 deletions packages/ui/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,14 @@
"private": true,
"scripts": {
"format": "prettier --write .",
"lint": "eslint . --cache --fix",
"lint": "eslint . --fix",
"lint:types": "tsc"
},
"dependencies": {
"@mui/material": "5.15.1",
"react": "18.2.0",
"shared-core": "workspace:*"
"shared-core": "workspace:*",
"use-breakpoint": "4.0.1"
},
"devDependencies": {
"@types/react": "18.2.45",
Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion packages/webhooks/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"dev": "brew upgrade cloudflared && cloudflared --loglevel fatal tunnel run dg",
"webhook": "NODE_ENV=development tsx webhookCommand.ts",
"format": "prettier --write .",
"lint": "eslint . --cache --fix",
"lint": "eslint . --fix",
"lint:types": "tsc"
},
"devDependencies": {
Expand Down
6 changes: 3 additions & 3 deletions pnpm-lock.yaml

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

1 comment on commit ff7cf64

@vercel
Copy link

@vercel vercel bot commented on ff7cf64 Dec 28, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

dg – ./

dg.vercel.app
dg-dgattey.vercel.app
dg-git-main-dgattey.vercel.app
dylangattey.com

Please sign in to comment.