Skip to content

Commit

Permalink
Switch to Vite and ESM (#1405)
Browse files Browse the repository at this point in the history
* Switch to Vite

* Use standard Vite CSS import

* Switch to ESM
  • Loading branch information
stephenwade authored Apr 1, 2024
1 parent 00e8238 commit d497148
Show file tree
Hide file tree
Showing 32 changed files with 154 additions and 155 deletions.
2 changes: 1 addition & 1 deletion .eslintrc.js → .eslintrc.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ module.exports = {

overrides: [
{
files: ['.eslintrc.js', 'remix.config.js', 'stylelint.config.js'],
files: ['.eslintrc.cjs', 'stylelint.config.js'],

env: {
node: true,
Expand Down
1 change: 0 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@ COPY --from=production-deps /app/node_modules /app/node_modules
COPY --from=build /app/node_modules/.prisma /app/node_modules/.prisma

COPY --from=build /app/build /app/build
COPY --from=build /app/public /app/public
COPY --from=build /app/package.json /app/package.json
COPY --from=build /app/start.sh /app/start.sh
COPY --from=build /app/prisma /app/prisma
Expand Down
9 changes: 2 additions & 7 deletions app/components/ShowEnded/ShowEnded.tsx
Original file line number Diff line number Diff line change
@@ -1,14 +1,9 @@
import type { LinksFunction } from '@remix-run/node';
import '~/styles/show-ended.css';

import type { FC } from 'react';
import { useEffect } from 'react';
import { toast } from 'react-toastify';

import stylesUrl from '~/styles/show-ended.css';

export const links: LinksFunction = () => [
{ rel: 'stylesheet', href: stylesUrl },
];

interface ShowEndedProps {
logoUrl: string;
}
Expand Down
9 changes: 2 additions & 7 deletions app/components/ShowIntro/ShowIntro.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,6 @@
import type { LinksFunction } from '@remix-run/node';
import type { FC } from 'react';

import stylesUrl from '~/styles/show-intro.css';
import '~/styles/show-intro.css';

export const links: LinksFunction = () => [
{ rel: 'stylesheet', href: stylesUrl },
];
import type { FC } from 'react';

interface ShowIntroProps {
logoUrl: string;
Expand Down
19 changes: 4 additions & 15 deletions app/components/ShowPlaying/ShowPlaying.tsx
Original file line number Diff line number Diff line change
@@ -1,28 +1,17 @@
import type { LinksFunction } from '@remix-run/node';
import '~/styles/show-playing.css';

import type { FC } from 'react';
import { useEffect } from 'react';
import { toast } from 'react-toastify';

import { links as spinnerLinks } from '~/components/Spinner';
import {
links as toastLinks,
ToastContainer,
} from '~/components/ToastContainer';
import { links as volumeLinks, VolumeFab } from '~/components/VolumeFab';
import stylesUrl from '~/styles/show-playing.css';
import { ToastContainer } from '~/components/ToastContainer';
import { VolumeFab } from '~/components/VolumeFab';
import type { AudioStatus } from '~/types/AudioStatus';
import type { ShowInfo } from '~/types/ShowInfo';

import { AudioCanvas } from './AudioCanvas';
import { CurrentTime } from './CurrentTime';

export const links: LinksFunction = () => [
...spinnerLinks(),
...volumeLinks(),
...toastLinks(),
{ rel: 'stylesheet', href: stylesUrl },
];

export interface ShowPlayingProps {
volume: number;
audioStatus: AudioStatus;
Expand Down
9 changes: 2 additions & 7 deletions app/components/Spinner/Spinner.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,6 @@
import type { LinksFunction } from '@remix-run/node';
import type { FC } from 'react';

import stylesUrl from './spinner.css';
import './spinner.css';

export const links: LinksFunction = () => [
{ rel: 'stylesheet', href: stylesUrl },
];
import type { FC } from 'react';

export const Spinner: FC = () => (
<div className="spinner-container">
Expand Down
12 changes: 3 additions & 9 deletions app/components/ToastContainer/ToastContainer.tsx
Original file line number Diff line number Diff line change
@@ -1,15 +1,9 @@
import type { LinksFunction } from '@remix-run/node';
import 'react-toastify/dist/ReactToastify.min.css';
import './toast.css';

import type { CloseButtonProps } from 'node_modules/react-toastify/dist/components';
import type { FC } from 'react';
import { cssTransition, ToastContainer as Container } from 'react-toastify';
import toastStylesUrl from 'react-toastify/dist/ReactToastify.min.css';

import stylesUrl from './toast.css';

export const links: LinksFunction = () => [
{ rel: 'stylesheet', href: toastStylesUrl },
{ rel: 'stylesheet', href: stylesUrl },
];

const ToastClose: FC<CloseButtonProps> = ({ type, closeToast }) => {
return (
Expand Down
8 changes: 2 additions & 6 deletions app/components/VolumeFab/VolumeFab.tsx
Original file line number Diff line number Diff line change
@@ -1,19 +1,15 @@
import type { LinksFunction } from '@remix-run/node';
import './volume-fab.css';

import type { FC, KeyboardEventHandler } from 'react';
import { memo, useCallback, useRef, useState } from 'react';
import { useOnClickOutside } from 'usehooks-ts';

import { VolumeDownIcon, VolumeMuteIcon, VolumeUpIcon } from './icons';
import stylesUrl from './volume-fab.css';

const INPUT_MIN = 0;
const INPUT_MAX = 100;
const INPUT_STEP = 5;

export const links: LinksFunction = () => [
{ rel: 'stylesheet', href: stylesUrl },
];

export interface VolumeFabProps {
volume: number;
onVolumeInput: (volume: number) => void;
Expand Down
2 changes: 1 addition & 1 deletion app/components/admin/AudioFileUpload.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ import { useControlField, useField } from 'remix-validated-form';
import { UPLOAD_AUDIO_FORM_KEY } from '~/forms/upload-audio';
import { useSse } from '~/hooks/useSse';
import type { loader as audioUploadLoader } from '~/routes/admin.audio-upload.$id';
import type { AudioFileUploadEvent } from '~/routes/admin.audio-upload.events';
import type { action as newAudioUploadAction } from '~/routes/admin.audio-upload.new';
import type { AudioFileUploadEvent } from '~/sse.server/audio-file-events';

type PutFormResponse = SerializeFrom<typeof newAudioUploadAction>;

Expand Down
4 changes: 2 additions & 2 deletions app/forms/show/forms.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ import { InputDateTime } from '~/components/admin/InputDateTime';
import { SaveButton } from '~/components/admin/SaveButton';
import { useOrigin } from '~/hooks/useOrigin';

import type { schema, setSchema } from './validators';
import { clientValidator } from './validators';
import type { schema, setSchema } from './validator';
import { clientValidator } from './validator';

const SHOW_FORM_ID = 'show-form';

Expand Down
2 changes: 0 additions & 2 deletions app/forms/show/index.ts

This file was deleted.

23 changes: 23 additions & 0 deletions app/forms/show/validator.server.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import { withZod } from '@remix-validated-form/with-zod';

import { db } from '~/db/db.server';

import { schema } from './validator';

export function makeServerValidator({
previousId,
}: { previousId?: string } = {}) {
return withZod(
schema.refine(
async ({ id }) => {
if (id === previousId) return true;
const existingShow = await db.show.findUnique({ where: { id } });
return !existingShow;
},
{
path: ['id'],
message: 'A show already exists with that URL.',
},
),
);
}
19 changes: 0 additions & 19 deletions app/forms/show/validators.ts → app/forms/show/validator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@ import { withZod } from '@remix-validated-form/with-zod';
import { z } from 'zod';
import { zfd } from 'zod-form-data';

import { db } from '~/db/db.server';

export const setSchema = z.object({
id: zfd.text(),
artist: zfd.text(),
Expand All @@ -30,20 +28,3 @@ export const schema = zfd.formData({
});

export const clientValidator = withZod(schema);

export const makeServerValidator = ({
previousId,
}: { previousId?: string } = {}) =>
withZod(
schema.refine(
async ({ id }) => {
if (id === previousId) return true;
const existingShow = await db.show.findUnique({ where: { id } });
return !existingShow;
},
{
path: ['id'],
message: 'A show already exists with that URL.',
},
),
);
2 changes: 0 additions & 2 deletions app/root.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import { rootAuthLoader } from '@clerk/remix/ssr.server';
import type { LoaderFunction, MetaFunction } from '@remix-run/node';
import {
Links,
LiveReload,
Meta,
Outlet,
redirect,
Expand Down Expand Up @@ -51,7 +50,6 @@ function App() {
<Outlet />
<ScrollRestoration />
<Scripts />
<LiveReload />
</body>
</html>
);
Expand Down
25 changes: 7 additions & 18 deletions app/routes/$show.tsx
Original file line number Diff line number Diff line change
@@ -1,22 +1,19 @@
import type {
LinksFunction,
LoaderFunction,
MetaFunction,
} from '@remix-run/node';
import '~/styles/elevation.css';
import '~/styles/show.css';

import type { LoaderFunction, MetaFunction } from '@remix-run/node';
import { json, redirect } from '@remix-run/node';
import { useLoaderData } from '@remix-run/react';
import { addSeconds, formatISO } from 'date-fns';
import type { FC } from 'react';
import useLocalStorageState from 'use-local-storage-state';

import { AudioController } from '~/components/AudioController';
import { links as endedLinks, ShowEnded } from '~/components/ShowEnded';
import { links as introLinks, ShowIntro } from '~/components/ShowIntro';
import { links as playingLinks, ShowPlaying } from '~/components/ShowPlaying';
import { ShowEnded } from '~/components/ShowEnded';
import { ShowIntro } from '~/components/ShowIntro';
import { ShowPlaying } from '~/components/ShowPlaying';
import { db } from '~/db/db.server';
import { useShowInfo } from '~/hooks/useShowInfo';
import elevationStylesUrl from '~/styles/elevation.css';
import showStylesUrl from '~/styles/show.css';
import type { ShowData } from '~/types/ShowData';

export const meta: MetaFunction<typeof loader> = ({ data, params }) => {
Expand All @@ -29,14 +26,6 @@ export const meta: MetaFunction<typeof loader> = ({ data, params }) => {
];
};

export const links: LinksFunction = () => [
{ rel: 'stylesheet', href: elevationStylesUrl },
{ rel: 'stylesheet', href: showStylesUrl },
...introLinks(),
...playingLinks(),
...endedLinks(),
];

export const loader = (async ({ params }) => {
const id = params.show!;

Expand Down
23 changes: 4 additions & 19 deletions app/routes/admin.audio-upload.events.ts
Original file line number Diff line number Diff line change
@@ -1,26 +1,11 @@
import type { Prisma } from '@prisma/client';
import type { LoaderFunction, SerializeFrom } from '@remix-run/node';
import type { LoaderFunction } from '@remix-run/node';

import { redirectToLogin } from '~/auth/redirect-to-login.server';
import {
adminEventStream,
dispatchAdminEvent,
} from '~/sse/admin-events.server';

export type AudioFileUploadEvent = SerializeFrom<
Prisma.AudioFileUploadGetPayload<{
include: { audioFile: true };
}>
>;

const EVENT_TYPE = 'audio file processing';

export function emitAudioFileProcessingEvent(data: AudioFileUploadEvent) {
dispatchAdminEvent(EVENT_TYPE, data);
}
import { adminEventStream } from '~/sse.server/admin-events';
import { AUDIO_FILE_EVENT_TYPE } from '~/sse.server/audio-file-events';

export const loader = (async (args) => {
await redirectToLogin(args);

return adminEventStream(args.request, EVENT_TYPE);
return adminEventStream(args.request, AUDIO_FILE_EVENT_TYPE);
}) satisfies LoaderFunction;
2 changes: 1 addition & 1 deletion app/routes/admin.audio-upload.new.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import { ffmpeg } from '~/ffmpeg/ffmpeg.server';
import type { FFprobeOutput } from '~/ffmpeg/ffprobe.server';
import { ffprobe } from '~/ffmpeg/ffprobe.server';
import { UPLOAD_AUDIO_FORM_KEY } from '~/forms/upload-audio';
import { emitAudioFileProcessingEvent } from '~/routes/admin.audio-upload.events';
import { emitAudioFileProcessingEvent } from '~/sse.server/audio-file-events';

const GIGABYTE = 1_000_000_000;
const MICROSECONDS = 1 / 1_000_000;
Expand Down
3 changes: 2 additions & 1 deletion app/routes/admin.shows.$show_.edit.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ import { validationError } from 'remix-validated-form';

import { redirectToLogin } from '~/auth/redirect-to-login.server';
import { db } from '~/db/db.server';
import { EditShowForm, makeServerValidator } from '~/forms/show';
import { EditShowForm } from '~/forms/show/forms';
import { makeServerValidator } from '~/forms/show/validator.server';
import { replaceNullsWithUndefined } from '~/forms/utils/replaceNullsWithUndefined';
import { replaceUndefinedsWithNull } from '~/forms/utils/replaceUndefinedsWithNull';

Expand Down
3 changes: 2 additions & 1 deletion app/routes/admin.shows.new.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ import { validationError } from 'remix-validated-form';

import { redirectToLogin } from '~/auth/redirect-to-login.server';
import { db } from '~/db/db.server';
import { makeServerValidator, NewShowForm } from '~/forms/show';
import { NewShowForm } from '~/forms/show/forms';
import { makeServerValidator } from '~/forms/show/validator.server';

export const meta: MetaFunction = () => [
{ title: 'New show | Festival admin' },
Expand Down
10 changes: 3 additions & 7 deletions app/routes/admin.tsx
Original file line number Diff line number Diff line change
@@ -1,16 +1,12 @@
import '~/styles/admin.css';

import { UserButton } from '@clerk/remix';
import type { LinksFunction, MetaFunction } from '@remix-run/node';
import type { MetaFunction } from '@remix-run/node';
import { Outlet } from '@remix-run/react';
import type { FC } from 'react';

import adminStylesUrl from '~/styles/admin.css';

export const meta: MetaFunction = () => [{ title: 'Festival admin' }];

export const links: LinksFunction = () => [
{ rel: 'stylesheet', href: adminStylesUrl },
];

const Admin: FC = () => {
return (
<>
Expand Down
File renamed without changes.
16 changes: 16 additions & 0 deletions app/sse.server/audio-file-events.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import type { Prisma } from '@prisma/client';
import type { SerializeFrom } from '@remix-run/node';

import { dispatchAdminEvent } from './admin-events';

export type AudioFileUploadEvent = SerializeFrom<
Prisma.AudioFileUploadGetPayload<{
include: { audioFile: true };
}>
>;

export const AUDIO_FILE_EVENT_TYPE = 'audio file processing';

export function emitAudioFileProcessingEvent(data: AudioFileUploadEvent) {
dispatchAdminEvent(AUDIO_FILE_EVENT_TYPE, data);
}
1 change: 1 addition & 0 deletions env.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/// <reference types="vite/client" />
Loading

0 comments on commit d497148

Please sign in to comment.