Skip to content

Commit

Permalink
feat: add a setting page
Browse files Browse the repository at this point in the history
  • Loading branch information
arianrhodsandlot committed Mar 10, 2024
1 parent 6f8c111 commit f8c6d06
Show file tree
Hide file tree
Showing 7 changed files with 63 additions and 5 deletions.
3 changes: 3 additions & 0 deletions src/views/components/app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ export default function App() {
<Route path={routes.rom}>
<UniversalHomeRoute />
</Route>
<Route path={routes.settings}>
<UniversalHomeRoute />
</Route>

<Route path='/auth/onedrive'>
<AuthOnedrive />
Expand Down
2 changes: 2 additions & 0 deletions src/views/components/hooks/use-router-helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ export function useRouterHelpers() {
const [isHomeRoute] = useRoute(routes.home)
const [isPlatformRoute] = useRoute(routes.platform)
const [isRomRoute] = useRoute(routes.rom)
const [isSettingsRoute] = useRoute(routes.settings)

const wouter = { location, setLocation, router, params, useRoute }

Expand Down Expand Up @@ -86,6 +87,7 @@ export function useRouterHelpers() {
isHomeRoute,
isPlatformRoute,
isRomRoute,
isSettingsRoute,
linkToLibrary,
linkToPlatform,
linkToRom,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export function HomeScreenLayout({ children }: { children: ReactNode }) {
>
<TopBar />
<div className='flex-1 overflow-hidden'>
<div className='flex h-full items-center justify-center '>{children}</div>
<div className='flex h-full items-center justify-center'>{children}</div>
</div>
</div>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import { GameLaunching } from './game-launching'
import { HomeScreenLayout } from './home-screen-layout'
import { useCurrentPlatformName } from './hooks/use-current-platform'
import { InputTips } from './input-tips'
import { Settings } from './settings'

function getColumnCount(width: number) {
const idealItemWidth = innerWidth > 800 ? 200 : 150
Expand Down Expand Up @@ -52,7 +53,7 @@ async function getRoms(platform: string) {
export function HomeScreen() {
const [roms, setRoms] = useAtom(romsAtom)
const setPlatforms = useSetAtom(platformsAtom)
const { params, isPlatformRoute, isRomRoute, redirectToPlatform } = useRouterHelpers()
const { params, isPlatformRoute, isRomRoute, isSettingsRoute, redirectToPlatform } = useRouterHelpers()
const [measurements = { width: 0, height: 0 }, gridContainerRef] = useMeasure<HTMLDivElement>()
const [isRetrying, setIsRetrying] = useState(false)
const currentPlatformName = useCurrentPlatformName()
Expand Down Expand Up @@ -169,6 +170,14 @@ export function HomeScreen() {
})()
}, [params.library, currentPlatformName, isRomRoute, loadPlatformsAndRomsFromCache, loadPlatformsAndRomsFromRemote])

if (isSettingsRoute) {
return (
<HomeScreenLayout>
<Settings />
</HomeScreenLayout>
)
}

const isRomsEmpty = !roms?.length
const showLoading = romsState.status === 'loading' && peekRomsState.status !== 'loading' && isRomsEmpty

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
export function Settings() {
return (
<div className='inset-0 h-full w-full bg-white p-20'>
<div className='container m-auto'>
<h2 className='text-3xl'>Settings</h2>

<div className='mt-10'>
<button className='flex w-full items-center gap-2 border p-4'>
<span className='icon-[mdi--palette] text-xl' />
<div className='flex-1 text-left'>Apparence</div>
<span className='icon-[mdi--chevron-right]' />
</button>

<button className='flex w-full items-center gap-2 border border-t-0 p-4'>
<span className='icon-[mdi--controller] text-xl' />
<div className='flex-1 text-left'>Input</div>
<span className='icon-[mdi--chevron-right]' />
</button>

<button className='flex w-full items-center gap-2 border border-t-0 p-4'>
<span className='icon-[mdi--monitor-shimmer] text-xl' />
<div className='flex-1 text-left'>Emulation</div>
<span className='icon-[mdi--chevron-right]' />
</button>

<button className='flex w-full items-center gap-2 border border-t-0 p-4'>
<span className='icon-[mdi--about] text-xl' />
<div className='flex-1 text-left'>About</div>
<span className='icon-[mdi--chevron-right]' />
</button>
</div>
</div>
</div>
)
}
14 changes: 11 additions & 3 deletions src/views/components/routes/universal-home-route/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,16 @@ import { HomeScreen } from '../library/platform/home-screen'
import { GameAddons } from '../library/rom/game-addons'

export function UniversalHomeRoute() {
const { params, isHomeRoute, isPlatformRoute, isRomRoute, navigateToLibrary, navigateToPlatform, redirectToHome } =
useRouterHelpers()
const {
params,
isHomeRoute,
isPlatformRoute,
isRomRoute,
isSettingsRoute,
navigateToLibrary,
navigateToPlatform,
redirectToHome,
} = useRouterHelpers()
const [started, setStarted] = useState(false)

const [, { execute }] = useAsync(async () => {
Expand Down Expand Up @@ -51,7 +59,7 @@ export function UniversalHomeRoute() {
)
}

if (isPlatformRoute) {
if (isPlatformRoute || isSettingsRoute) {
return (
<>
<Helmet>
Expand Down
1 change: 1 addition & 0 deletions src/views/lib/routes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@ export const routes = {
home: '/',
platform: '/library/:library/platform/:platform?',
rom: '/library/:library/platform/:platform/rom/:rom',
settings: '/library/:library/settings',
}

0 comments on commit f8c6d06

Please sign in to comment.