Skip to content

Commit

Permalink
Remix: fix loader data not updating (#4916)
Browse files Browse the repository at this point in the history
* fix loader data not updating

* rename store

* dark mode hook

* split components, drop useEffects
  • Loading branch information
ruggi authored Feb 16, 2024
1 parent 0ef0ba7 commit 9cdc033
Show file tree
Hide file tree
Showing 4 changed files with 372 additions and 313 deletions.
4 changes: 2 additions & 2 deletions utopia-remix/app/components/projectActionContextMenu.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import * as DropdownMenu from '@radix-ui/react-dropdown-menu'
import { useFetcher } from '@remix-run/react'
import React from 'react'
import { useStore } from '../store'
import { useProjectsStore } from '../store'
import { contextMenuItem } from '../styles/contextMenuItem.css'
import { colors } from '../styles/sprinkles.css'
import { ProjectWithoutContent } from '../types'
Expand All @@ -17,7 +17,7 @@ type ContextMenuEntry =

export const ProjectContextMenu = React.memo(({ project }: { project: ProjectWithoutContent }) => {
const fetcher = useFetcher()
const selectedCategory = useStore((store) => store.selectedCategory)
const selectedCategory = useProjectsStore((store) => store.selectedCategory)

const deleteProject = React.useCallback(
(projectId: string) => {
Expand Down
23 changes: 23 additions & 0 deletions utopia-remix/app/hooks/useIsDarkMode.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import React from 'react'

export function useIsDarkMode() {
const [isDarkMode, setIsDarkMode] = React.useState<boolean>(false)

React.useEffect(() => {
const handleColorSchemeChange = (event: {
matches: boolean | ((prevState: boolean) => boolean)
}) => {
setIsDarkMode(event.matches)
}

const mediaQuery = window.matchMedia('(prefers-color-scheme: dark)')
setIsDarkMode(mediaQuery.matches)
mediaQuery.addListener(handleColorSchemeChange)

return () => {
mediaQuery.removeListener(handleColorSchemeChange)
}
}, [])

return isDarkMode
}
Loading

0 comments on commit 9cdc033

Please sign in to comment.