Skip to content

Commit

Permalink
Upgrade to Remix v2
Browse files Browse the repository at this point in the history
  • Loading branch information
benjaminleonard committed Oct 18, 2024
1 parent 2644f58 commit c365d34
Show file tree
Hide file tree
Showing 26 changed files with 13,667 additions and 27,109 deletions.
30 changes: 30 additions & 0 deletions app/components/ClientOnly.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import { useHydrated } from '~/hooks/use-hydrated'

type Props = {
/**
* You are encouraged to add a fallback that is the same dimensions
* as the client rendered children. This will avoid content layout
* shift which is disgusting
*/
children(): React.ReactNode
fallback?: React.ReactNode
}

/**
* Render the children only after the JS has loaded client-side. Use an optional
* fallback component if the JS is not yet loaded.
*
* Example: Render a Chart component if JS loads, renders a simple FakeChart
* component server-side or if there is no JS. The FakeChart can have only the
* UI without the behavior or be a loading spinner or skeleton.
* ```tsx
* return (
* <ClientOnly fallback={<FakeChart />}>
* {() => <Chart />}
* </ClientOnly>
* );
* ```
*/
export function ClientOnly({ children, fallback = null }: Props) {
return useHydrated() ? <>{children()}</> : <>{fallback}</>
}
50 changes: 0 additions & 50 deletions app/components/NotFound.tsx

This file was deleted.

19 changes: 10 additions & 9 deletions app/components/Search.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import {
type AlgoliaMultipleQueriesQuery,
type InstantMeiliSearchInstance,
} from '@meilisearch/instant-meilisearch'
import { Link } from '@remix-run/react'
import { Link, useNavigate } from '@remix-run/react'
import { useQuery } from '@tanstack/react-query'
import cn from 'classnames'
import dayjs from 'dayjs'
Expand All @@ -26,7 +26,6 @@ import {
useHits,
useSearchBox,
} from 'react-instantsearch-hooks-web'
import { useNavigate } from 'react-router-dom'

import Icon from '~/components/Icon'
import StatusBadge from '~/components/StatusBadge'
Expand Down Expand Up @@ -78,11 +77,13 @@ const Search = ({ open, onClose }: { open: boolean; onClose: () => void }) => {
// the RFD API backend
const request = requests[0]
return fetch(
`/search?q=${request.params
?.query}&attributes_to_crop=${request.params?.attributesToSnippet?.join(
`/search?q=${
request.params?.query
}&attributes_to_crop=${request.params?.attributesToSnippet?.join(
',',
)}&highlight_post_tag=${request.params
?.highlightPostTag}&highlight_pre_tag=${request.params?.highlightPreTag}`,
)}&highlight_post_tag=${
request.params?.highlightPostTag
}&highlight_pre_tag=${request.params?.highlightPreTag}`,
).then(async (resp) => {
const data = await resp.json()
return data
Expand All @@ -97,7 +98,7 @@ const Search = ({ open, onClose }: { open: boolean; onClose: () => void }) => {
<Dialog
open={open}
onClose={onClose}
className="overlay-shadow fixed top-4 left-1/2 z-20 w-[calc(100%-2.5rem)] -translate-x-1/2 rounded-lg border p-0 bg-raise border-secondary 600:top-[calc(10%+var(--header-height))] 600:w-[calc(100%-5rem)] 1000:w-[820px]"
className="overlay-shadow fixed left-1/2 top-4 z-20 w-[calc(100%-2.5rem)] -translate-x-1/2 rounded-lg border p-0 bg-raise border-secondary 600:top-[calc(10%+var(--header-height))] 600:w-[calc(100%-5rem)] 1000:w-[820px]"
aria-label="Jump to"
backdrop={<div className="backdrop" />}
>
Expand Down Expand Up @@ -344,7 +345,7 @@ const Hits = ({ data, selectedIdx }: { data: RFDHit[]; selectedIdx: number }) =>
{isNewSection && (
<h3
className={cn(
'h-6 rounded-t-sm px-3 !leading-6 text-mono-xs text-tertiary bg-tertiary line-clamp-1',
'line-clamp-1 h-6 rounded-t-sm px-3 !leading-6 text-mono-xs text-tertiary bg-tertiary',
sectionIsSelected && '600:!text-inverse 600:!bg-accent',
)}
>
Expand Down Expand Up @@ -509,7 +510,7 @@ export const ActionMenuHotkey = ({ keys, action }: ActionMenuHotkeyProps) => (
{keys.map((hotkey) => (
<kbd
key={hotkey}
className="mr-1 inline-block rounded py-1 px-2 text-mono-xs text-secondary bg-secondary"
className="mr-1 inline-block rounded px-2 py-1 text-mono-xs text-secondary bg-secondary"
>
{hotkey}
</kbd>
Expand Down
7 changes: 3 additions & 4 deletions app/components/SelectRfdCombobox.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,10 @@
* Copyright Oxide Computer Company
*/

import { Link } from '@remix-run/react'
import { Link, useNavigate } from '@remix-run/react'
import cn from 'classnames'
import fuzzysort from 'fuzzysort'
import { useCallback, useEffect, useRef, useState } from 'react'
import { useNavigate } from 'react-router-dom'

import Icon from '~/components/Icon'
import { useKey } from '~/hooks/use-key'
Expand Down Expand Up @@ -120,13 +119,13 @@ const ComboboxWrapper = ({
<div className={open ? 'visible' : 'pointer-events-none invisible'}>
<div
className={cn(
'fixed top-0 left-0 right-0 bottom-0 bg-default 600:bg-transparent',
'fixed bottom-0 left-0 right-0 top-0 bg-default 600:bg-transparent',
open ? 'opacity-80 ' : 'opacity-0',
)}
onClick={() => handleDismiss()}
/>
<div
className="group absolute top-4 left-4 right-4 600:top-[calc(var(--header-height)+8px)] 600:right-auto 600:w-[16rem]"
className="group absolute left-4 right-4 top-4 600:right-auto 600:top-[calc(var(--header-height)+8px)] 600:w-[16rem]"
onKeyDown={(e) => {
const lastIdx = matchedItems.length - 1
if (e.key === 'Enter') {
Expand Down
38 changes: 0 additions & 38 deletions app/entry.client.tsx

This file was deleted.

128 changes: 0 additions & 128 deletions app/entry.server.tsx

This file was deleted.

30 changes: 30 additions & 0 deletions app/hooks/use-hydrated.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import { useSyncExternalStore } from 'react'

function subscribe() {
return () => {}
}

/**
* Return a boolean indicating if the JS has been hydrated already.
* When doing Server-Side Rendering, the result will always be false.
* When doing Client-Side Rendering, the result will always be false on the
* first render and true from then on. Even if a new component renders it will
* always start with true.
*
* Example: Disable a button that needs JS to work.
* ```tsx
* let hydrated = useHydrated();
* return (
* <button type="button" disabled={!hydrated} onClick={doSomethingCustom}>
* Click me
* </button>
* );
* ```
*/
export function useHydrated() {
return useSyncExternalStore(
subscribe,
() => true,
() => false,
)
}
Loading

0 comments on commit c365d34

Please # to comment.