From a7bd08ec79a24c3e613d9625587a88f9d5061602 Mon Sep 17 00:00:00 2001 From: icechen Date: Tue, 22 Feb 2022 20:23:44 +0800 Subject: [PATCH] update --- package.json | 1 + src/index.tsx | 11 ++++++++++- src/pages/home/index.tsx | 15 +++++++++++++++ src/pages/login/index.tsx | 21 +++++++++++++++++++++ src/telegram/user.ts | 9 +++++++++ 5 files changed, 56 insertions(+), 1 deletion(-) create mode 100644 src/pages/home/index.tsx create mode 100644 src/pages/login/index.tsx diff --git a/package.json b/package.json index 545bc4b..dd6ca84 100644 --- a/package.json +++ b/package.json @@ -17,6 +17,7 @@ "mtproton": "6.0.0", "react": "^17.0.2", "react-dom": "^17.0.2", + "react-router-dom": "^6.2.1", "react-scripts": "5.0.0", "typescript": "^4.5.5", "web-vitals": "^2.1.4" diff --git a/src/index.tsx b/src/index.tsx index a85797d..75cf2d9 100644 --- a/src/index.tsx +++ b/src/index.tsx @@ -2,10 +2,19 @@ import React from "react"; import ReactDOM from "react-dom"; import App from "./App"; import reportWebVitals from "./reportWebVitals"; +import Login from "./pages/login"; +import { BrowserRouter, Routes, Route } from "react-router-dom"; +import Home from "./pages/home"; ReactDOM.render( - + + + } /> + } /> + } /> + + , document.getElementById("root") ); diff --git a/src/pages/home/index.tsx b/src/pages/home/index.tsx new file mode 100644 index 0000000..52c20b4 --- /dev/null +++ b/src/pages/home/index.tsx @@ -0,0 +1,15 @@ +import Telegram from "../../telegram/telegram"; + +function Home() { + Telegram.call("sendMessage", { + chat_id: "", + text: "Hello World", + }); + return ( +
+

Hello Next.js

+
+ ); +} + +export default Home; diff --git a/src/pages/login/index.tsx b/src/pages/login/index.tsx new file mode 100644 index 0000000..acddac5 --- /dev/null +++ b/src/pages/login/index.tsx @@ -0,0 +1,21 @@ +import { useEffect } from "react"; +import { getMe } from "../../telegram/user"; + +function Login() { + useEffect(function () { + getMe() + .then(function (user) { + console.log(user); + }) + .catch(function (error) { + if (error.code === 401) { + // Unauthorized + } + console.log(error); + }); + }, []); + + return
登录
; +} + +export default Login; diff --git a/src/telegram/user.ts b/src/telegram/user.ts index e69de29..f7e59a1 100644 --- a/src/telegram/user.ts +++ b/src/telegram/user.ts @@ -0,0 +1,9 @@ +import Telegram from "./telegram"; + +async function getMe() { + return await Telegram.call("users.getUsers", { + id: [{ _: "inputPeerSelf" }], + }); +} + +export { getMe };