♻️(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 { useLang } from 'hoofd'
|
||||||
import { Route, Switch } from 'wouter'
|
import { Route, Switch } from 'wouter'
|
||||||
import { HomeRoute } from '@/features/home'
|
import { HomeRoute } from '@/features/home'
|
||||||
import { RoomRoute, roomIdRegex } from '@/features/rooms'
|
import { RoomRoute, roomRouteRegex } from '@/features/rooms'
|
||||||
import { NotFound } from './routes/NotFound'
|
import { NotFound } from './routes/NotFound'
|
||||||
import './i18n/init'
|
import './i18n/init'
|
||||||
import { RenderIfUserFetched } from './features/auth'
|
import { RenderIfUserFetched } from './features/auth'
|
||||||
@@ -23,7 +23,7 @@ function App() {
|
|||||||
<RenderIfUserFetched>
|
<RenderIfUserFetched>
|
||||||
<Switch>
|
<Switch>
|
||||||
<Route path="/" component={HomeRoute} />
|
<Route path="/" component={HomeRoute} />
|
||||||
<Route path={roomIdRegex} component={RoomRoute} />
|
<Route path={roomRouteRegex} component={RoomRoute} />
|
||||||
<Route component={NotFound} />
|
<Route component={NotFound} />
|
||||||
</Switch>
|
</Switch>
|
||||||
</RenderIfUserFetched>
|
</RenderIfUserFetched>
|
||||||
|
|||||||
@@ -1,3 +1,3 @@
|
|||||||
export { navigateToNewRoom } from './navigation/navigateToNewRoom'
|
export { navigateToNewRoom } from './navigation/navigateToNewRoom'
|
||||||
export { Room as RoomRoute } from './routes/Room'
|
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
|
// Generates a unique room identifier following the Google Meet format
|
||||||
export const generateRoomId = () =>
|
export const generateRoomId = () =>
|
||||||
[generateSegment(3), generateSegment(4), generateSegment(3)].join('-')
|
[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