♻️(frontend) tiny cleanup of the room regex related stuff
since this is used for the routing *and* for common validation, split a few things
This commit is contained in:
@@ -7,7 +7,7 @@ import { useTranslation } from 'react-i18next'
|
||||
import { useLang } from 'hoofd'
|
||||
import { Route, Switch } from 'wouter'
|
||||
import { HomeRoute } from '@/features/home'
|
||||
import { RoomRoute, roomIdRegex } from '@/features/rooms'
|
||||
import { RoomRoute, roomRouteRegex } from '@/features/rooms'
|
||||
import { NotFound } from './routes/NotFound'
|
||||
import './i18n/init'
|
||||
import { RenderIfUserFetched } from './features/auth'
|
||||
@@ -23,7 +23,7 @@ function App() {
|
||||
<RenderIfUserFetched>
|
||||
<Switch>
|
||||
<Route path="/" component={HomeRoute} />
|
||||
<Route path={roomIdRegex} component={RoomRoute} />
|
||||
<Route path={roomRouteRegex} component={RoomRoute} />
|
||||
<Route component={NotFound} />
|
||||
</Switch>
|
||||
</RenderIfUserFetched>
|
||||
|
||||
@@ -1,3 +1,3 @@
|
||||
export { navigateToNewRoom } from './navigation/navigateToNewRoom'
|
||||
export { Room as RoomRoute } from './routes/Room'
|
||||
export { roomIdRegex } from './utils/generateRoomId'
|
||||
export { roomRouteRegex, isRoomValid } from './utils/isRoomValid'
|
||||
|
||||
@@ -12,5 +12,3 @@ const generateSegment = (length: number): string =>
|
||||
// Generates a unique room identifier following the Google Meet format
|
||||
export const generateRoomId = () =>
|
||||
[generateSegment(3), generateSegment(4), generateSegment(3)].join('-')
|
||||
|
||||
export const roomIdRegex = /^[/](?<roomId>[a-z]{3}-[a-z]{4}-[a-z]{3})$/
|
||||
|
||||
5
src/frontend/src/features/rooms/utils/isRoomValid.ts
Normal file
5
src/frontend/src/features/rooms/utils/isRoomValid.ts
Normal file
@@ -0,0 +1,5 @@
|
||||
const roomIdPattern = '[a-z]{3}-[a-z]{4}-[a-z]{3}'
|
||||
export const roomRouteRegex = new RegExp(`^[/](?<roomId>${roomIdPattern})$`)
|
||||
|
||||
export const isRoomValid = (roomId: string) =>
|
||||
new RegExp(`^${roomIdPattern}$`).test(roomId)
|
||||
Reference in New Issue
Block a user