This commit is contained in:
2022-02-28 00:39:52 +08:00
parent 1d44a7eca4
commit c5868a8ebf
9 changed files with 149 additions and 31 deletions
+11 -2
View File
@@ -9,7 +9,12 @@ enum Status {
receive,
}
export function HomeButton() {
interface Props {
isSignIn: boolean;
onNotSignIn: () => void;
}
export function HomeButton(props: Props) {
let [status, setStatus] = useState(Status.normal);
let [boxStyle, setBoxStyle] = useState([style.box]);
let [isReceive, setIsReceive] = useState(false);
@@ -54,7 +59,11 @@ export function HomeButton() {
onMouseEnter={onReceive}
onMouseLeave={onNormal}
onClick={() => {
setIsReceive(true);
if (props.isSignIn) {
setIsReceive(true);
} else {
props.onNotSignIn();
}
}}
>
+1 -1
View File
@@ -1,3 +1,3 @@
.text {
color: #252525;
color: #252525 !important;
}
+90 -21
View File
@@ -1,10 +1,39 @@
import { Button, Paper, TextField } from "@mui/material";
import style from "./style.module.css";
import CountriesInput, { Country } from "../signin/countriesInput";
import { useState } from "react";
import { useMemo, useState } from "react";
import telegram, { sendSignInCode, signIn } from "../../telegram/telegram";
export function HomeSignIn() {
let [country, setCountry] = useState({} as Country | null);
let [phone, setPhone] = useState("");
let [phoneCode, setPhoneCode] = useState("");
const phoneNumber = useMemo(
() => (country ? country.country_code : "") + phone,
[country, phone]
);
let [codeHash, setCodeHash] = useState("");
let onSendCode = () => {
sendSignInCode(phoneNumber)
.then((phone_code_hash: string) => {
setCodeHash(phone_code_hash);
})
.catch((error: any) => {
console.log("error", error);
});
};
let onSignIn = () => {
signIn(phoneNumber, phoneCode, codeHash)
.then((user: any) => {
console.log("user", user);
})
.catch((error: any) => {
console.log("error", error);
});
};
return (
<Paper
@@ -21,26 +50,66 @@ export function HomeSignIn() {
>
<h1 className={style.h1}> / </h1>
<div className={style.describe}>/</div>
<div className={style.signInInput}>
<CountriesInput
onChange={(value) => {
setCountry(value);
}}
/>
<TextField
label="Phone Number"
className={style.phone}
variant="standard"
placeholder={"手机号码"}
/>
</div>
<Button
size={"large"}
style={{ alignSelf: "flex-end", marginRight: "50px" }}
variant="contained"
>
</Button>
{codeHash === "" ? (
<>
<div className={style.signInInput}>
<CountriesInput
onChange={(value) => {
setCountry(value);
}}
/>
<TextField
style={{ marginTop: "10px" }}
label="Phone Number"
className={style.phone}
placeholder={"手机号码"}
value={phone}
onChange={(e) => setPhone(e.target.value)}
/>
</div>
<Button
size={"large"}
style={{ alignSelf: "flex-end", marginRight: "50px" }}
variant="contained"
onClick={onSendCode}
>
</Button>
</>
) : (
<>
<div className={style.signInInput}>
<TextField
style={{ marginTop: "10px" }}
label="Auth Code"
className={style.phone}
placeholder={"验证码"}
value={phoneCode}
onChange={(e) => setPhoneCode(e.target.value)}
/>
</div>
<div style={{ display: "flex", flexDirection: "row" }}>
<Button
size={"large"}
style={{ alignSelf: "flex-end", marginRight: "50px" }}
variant="contained"
onClick={() => {
setCodeHash("");
}}
>
</Button>
<Button
size={"large"}
style={{ alignSelf: "flex-end", marginRight: "50px" }}
variant="contained"
onClick={onSignIn}
>
</Button>
</div>
</>
)}
<div className={style.explain}>
<h1 className={style.h1}></h1>
+2 -1
View File
@@ -13,9 +13,10 @@
.signInInput {
display: flex;
flex-direction: row;
flex-direction: column;
margin-top: 30px;
margin-bottom: 30px;
width: 300px;
}
.phone {
+1 -1
View File
@@ -52,7 +52,7 @@ function CountriesInput(props: {
// names must be equal
return 0;
})}
sx={{ width: 200 }}
sx={{ width: 300 }}
onChange={(_event, value) => {
props.onChange(value as Country);
}}