Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(flat-pages): add region code #1968

Merged
merged 2 commits into from
Jul 20, 2023
Merged
Show file tree
Hide file tree
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
9 changes: 5 additions & 4 deletions packages/flat-components/src/utils/room.ts
Original file line number Diff line number Diff line change
Expand Up @@ -190,10 +190,11 @@ export function roomStatusToI18nKey(
}
}

export const formatInviteCode = (uuid: string, inviteCode?: string): string => {
if (inviteCode && /^\d{10}$/.test(inviteCode)) {
// 123456789 -> 123 456 7890
return inviteCode.slice(0, 3) + " " + inviteCode.slice(3, 6) + " " + inviteCode.slice(6);
export const formatInviteCode = (uuid: string, code?: string): string => {
if (code) {
// 1234567890 -> 123 456 7890
// X1234567890 -> X123 456 7890
return code.replace(/^(\d+)(\d{3})(\d{4})$/, "$1 $2 $3");
}
return uuid;
};
9 changes: 4 additions & 5 deletions packages/flat-pages/src/HomePage/MainRoomMenu/JoinRoomBox.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import "./JoinRoomBox.less";
import React, { KeyboardEvent, useContext, useEffect, useRef, useState } from "react";
import { observer } from "mobx-react-lite";
import { Button, Input, Modal, Checkbox, Form, InputRef } from "antd";
import { validate, version } from "uuid";
import { PreferencesStoreContext } from "../../components/StoreProvider";
import { useSafePromise } from "../../utils/hooks/lifecycle";
import { useTranslate } from "@netless/flat-i18n";
Expand All @@ -19,8 +18,8 @@ export interface JoinRoomBoxProps {
onJoinRoom: (roomUUID: string) => Promise<void>;
}

const uuidRE =
/(?:[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}|00000000-0000-0000-0000-000000000000)/i;
const ROOM_UUID_RE =
/(?:[A-Z]{2}-)?(?:[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}|00000000-0000-0000-0000-000000000000)/i;

export const JoinRoomBox = observer<JoinRoomBoxProps>(function JoinRoomBox({ onJoinRoom }) {
const t = useTranslate();
Expand Down Expand Up @@ -116,14 +115,14 @@ export const JoinRoomBox = observer<JoinRoomBoxProps>(function JoinRoomBox({ onJ

async function extractUUIDFromClipboard(): Promise<string | undefined> {
const text = await navigator.clipboard.readText();
const m = uuidRE.exec(text);
const m = ROOM_UUID_RE.exec(text);
return m?.[0];
}

async function handleShowModal(): Promise<void> {
try {
const roomUUID = await extractUUIDFromClipboard();
if (roomUUID && validate(roomUUID) && version(roomUUID) === 4) {
if (roomUUID) {
form.setFieldsValue({ roomUUID });
setIsFormValidated(true);
}
Expand Down
1 change: 1 addition & 0 deletions packages/flat-server-api/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ export async function requestFlatServer<TPayload, TResult>(
headers.set("authorization", "Bearer " + token);
}

// TODO: if payload.roomUUID has '{REGION}-' prefix, select another server
const response = await fetch(
`${
enableFlatServerV2 === true ? FLAT_SERVER_BASE_URL_V2 : FLAT_SERVER_BASE_URL_V1
Expand Down