Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions ui/src/useRoomID.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,7 @@ export const getRoomFromURL = (): string | undefined => getFromURL('room');
export const getFromURL = (
key: string,
search: string = window.location.search
): string | undefined =>
search
.slice(1)
.split('&')
.find((param) => param.startsWith(`${key}=`))
?.split('=')[1];
): string | undefined => new URLSearchParams(search).get(key) ?? undefined;

export const useRoomID = (): [string | undefined, (v?: string) => void] => {
const [state, setState] = React.useState<string | undefined>(() => getRoomFromURL());
Expand All @@ -25,7 +20,12 @@ export const useRoomID = (): [string | undefined, (v?: string) => void] => {
(id) =>
setState((oldId?: string) => {
if (oldId !== id) {
window.history.pushState({roomId: id}, '', id ? `?room=${id}` : '?');
const params = new URLSearchParams();
if (id) {
params.set('room', id);
}
const query = params.toString();
window.history.pushState({roomId: id}, '', query ? `?${query}` : '?');
}
return id;
}),
Expand Down
Loading