Skip to content

Commit

Permalink
tooling: fix two more spots where vite complains it can't HMR (#2341)
Browse files Browse the repository at this point in the history
fix two more spots where vite complains it can't HMR
  • Loading branch information
david-crespo authored Jul 25, 2024
1 parent 6615cb6 commit 84a1501
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 18 deletions.
7 changes: 1 addition & 6 deletions app/forms/image-upload.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ import { readBlobAsBase64 } from '~/util/file'
import { invariant } from '~/util/invariant'
import { links } from '~/util/links'
import { pb } from '~/util/path-builder'
import { isAllZeros } from '~/util/str'
import { GiB, KiB } from '~/util/units'

/** Format file size with two decimal points */
Expand Down Expand Up @@ -113,12 +114,6 @@ function Step({ children, state, label, className }: StepProps) {
)
}

/**
* Does a base64 string represent underlying data that's all zeros, i.e., does
* it look like `AAAAAAAAAAAAAAAA==`?
*/
export const isAllZeros = (base64Data: string) => /^A*=*$/.test(base64Data)

const randInt = () => Math.floor(Math.random() * 100000000)

function getTmpDiskName(imageName: string) {
Expand Down
7 changes: 2 additions & 5 deletions app/ui/lib/Modal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,15 @@
*/
import * as Dialog from '@radix-ui/react-dialog'
import { animated, useTransition } from '@react-spring/web'
import React, { createContext, forwardRef, useContext, useId } from 'react'
import React, { forwardRef, useId } from 'react'

import { Close12Icon } from '@oxide/design-system/icons/react'

import { classed } from '~/util/classed'

import { Button } from './Button'
import { DialogOverlay } from './DialogOverlay'

const ModalContext = createContext(false)

export const useIsInModal = () => useContext(ModalContext)
import { ModalContext } from './modal-context'

export type ModalProps = {
title?: string
Expand Down
8 changes: 2 additions & 6 deletions app/ui/lib/SideModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,16 @@
import * as Dialog from '@radix-ui/react-dialog'
import { animated, useTransition } from '@react-spring/web'
import cn from 'classnames'
import React, { createContext, useContext, useRef, type ReactNode } from 'react'
import React, { useRef, type ReactNode } from 'react'

import { Close12Icon, Error12Icon } from '@oxide/design-system/icons/react'

import { useIsOverflow } from '~/hooks'
import { Message } from '~/ui/lib/Message'
import { useIsInModal } from '~/ui/lib/Modal'
import { classed } from '~/util/classed'

import { DialogOverlay } from './DialogOverlay'

const SideModalContext = createContext(false)

export const useIsInSideModal = () => useContext(SideModalContext)
import { SideModalContext, useIsInModal, useIsInSideModal } from './modal-context'

export function usePopoverZIndex() {
const isInModal = useIsInModal()
Expand Down
15 changes: 15 additions & 0 deletions app/ui/lib/modal-context.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
/*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, you can obtain one at https://mozilla.org/MPL/2.0/.
*
* Copyright Oxide Computer Company
*/

import { createContext, useContext } from 'react'

export const ModalContext = createContext(false)
export const useIsInModal = () => useContext(ModalContext)

export const SideModalContext = createContext(false)
export const useIsInSideModal = () => useContext(SideModalContext)
2 changes: 1 addition & 1 deletion app/forms/all-zeros.spec.ts → app/util/all-zeros.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
*/
import { expect, test } from 'vitest'

import { isAllZeros } from './image-upload'
import { isAllZeros } from '~/util/str'

function numberToUint8Array(num: number) {
const bytes = []
Expand Down
6 changes: 6 additions & 0 deletions app/util/str.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,3 +65,9 @@ export const validateIp = (ip: string) => {
const isv6 = !isv4 && IPV6_REGEX.test(ip)
return { isv4, isv6, valid: isv4 || isv6 }
}

/**
* Does a base64 string represent underlying data that's all zeros, i.e., does
* it look like `AAAAAAAAAAAAAAAA==`?
*/
export const isAllZeros = (base64Data: string) => /^A*=*$/.test(base64Data)

0 comments on commit 84a1501

Please sign in to comment.