diff --git a/packages/core/models/index.ts b/packages/core/models/index.ts new file mode 100644 index 0000000..5ccfc6e --- /dev/null +++ b/packages/core/models/index.ts @@ -0,0 +1 @@ +export * from "./userInfo.model"; diff --git a/packages/core/models/userInfo.model.ts b/packages/core/models/userInfo.model.ts new file mode 100644 index 0000000..33652b1 --- /dev/null +++ b/packages/core/models/userInfo.model.ts @@ -0,0 +1,12 @@ +export class UserInfo { + constructor( + public id: string, + public email: string, + public verifiedEmail: boolean, + public name: string, + public given_name: string, + public family_name: string, + public picture: string, + public locale: string + ) {} +} diff --git a/packages/desktop/electron/electron.js b/packages/desktop/electron/electron.js index 52e4caa..cf5cf14 100644 --- a/packages/desktop/electron/electron.js +++ b/packages/desktop/electron/electron.js @@ -25,7 +25,8 @@ const myApiOauth = new ElectronGoogleOAuth2( function createWindow() { // Create the browser window. win = new BrowserWindow({ - width: 800, + title: "Nirvana", + width: 600, height: 800, webPreferences: { nodeIntegration: false, // is default value after Electron v5 @@ -44,7 +45,7 @@ function createWindow() { ); // Open the DevTools. if (isDev) { - win.webContents.openDevTools({ mode: "attach" }); + win.webContents.openDevTools({ mode: "detach" }); } // End of the file @@ -83,9 +84,9 @@ async function handleLogin() { // read saved refresh token if any // todo: fix this...should be working const refreshToken = await store.get("refresh_token"); - console.log(refreshToken); - if (refreshToken) { + // todo: remove this when I have way of getting access token from a refresh token + if (refreshToken && false) { console.log("have a refresh token from user auth previously", refreshToken); myApiOauth.setTokens({ refresh_token: refreshToken }); diff --git a/packages/desktop/package.json b/packages/desktop/package.json index 792512e..2fcb511 100644 --- a/packages/desktop/package.json +++ b/packages/desktop/package.json @@ -8,6 +8,7 @@ "@getstation/electron-google-oauth2": "^2.1.0", "@mui/icons-material": "^5.5.0", "@mui/material": "^5.5.0", + "@nirvana/core": "*", "@testing-library/jest-dom": "^5.16.2", "@testing-library/react": "^12.1.4", "@testing-library/user-event": "^13.5.0", @@ -19,6 +20,7 @@ "react": "^17.0.2", "react-dom": "^17.0.2", "react-query": "^3.34.16", + "react-router-dom": "6", "react-scripts": "5.0.0", "typescript": "^4.6.2", "web-vitals": "^2.1.4" diff --git a/packages/desktop/public/index.html b/packages/desktop/public/index.html index aa069f2..3d3d049 100644 --- a/packages/desktop/public/index.html +++ b/packages/desktop/public/index.html @@ -24,7 +24,7 @@ work correctly both with client-side routing and a non-root public URL. Learn how to configure a non-root public URL by running `npm run build`. --> - React App + Nirvana diff --git a/packages/desktop/public/logos/small.svg b/packages/desktop/public/logos/small.svg new file mode 100644 index 0000000..7975eec --- /dev/null +++ b/packages/desktop/public/logos/small.svg @@ -0,0 +1,5 @@ + + + + + diff --git a/packages/desktop/src/App.tsx b/packages/desktop/src/App.tsx index 126dc7f..9a84ae7 100644 --- a/packages/desktop/src/App.tsx +++ b/packages/desktop/src/App.tsx @@ -1,6 +1,9 @@ import "./App.css"; +import { HashRouter, Route, Routes } from "react-router-dom"; + import { Button } from "@mui/material"; +import Home from "./pages/Home"; import Login from "./pages/Login"; import Logo from "./components/Logo"; import React from "react"; @@ -12,7 +15,16 @@ testConnection(); function App() { return ( <> - + +
+ + } /> + } /> + {/* + */} + +
+
); } diff --git a/packages/desktop/src/components/Logo/index.tsx b/packages/desktop/src/components/Logo/index.tsx index fe4fb52..0f615a5 100644 --- a/packages/desktop/src/components/Logo/index.tsx +++ b/packages/desktop/src/components/Logo/index.tsx @@ -1,4 +1,40 @@ -export default function Logo({ className }: { className: string }) { +export enum LogoType { + primary = "primary", + small = "small", +} + +export default function Logo({ + className, + type, +}: { + className: string; + type?: LogoType; +}) { + if (type === LogoType.small) { + return ( + + + + + + ); + } return ( + {/* header */} +
+ + + + + + + cannot find + + +
+ + {/* actions navbar */} +
+ + + + + + + + + + + + + + +
+ + {/* pinned conversations */} +
+ + + + Pinned + + +
+ + ); +} diff --git a/packages/desktop/src/pages/Login/index.tsx b/packages/desktop/src/pages/Login/index.tsx index 6bc075f..a9cae4c 100644 --- a/packages/desktop/src/pages/Login/index.tsx +++ b/packages/desktop/src/pages/Login/index.tsx @@ -1,17 +1,37 @@ -import { Button } from "@mui/material"; +import { Button, CircularProgress } from "@mui/material"; +import { useEffect, useState } from "react"; + import Logo from "../../components/Logo"; +import { UserInfo } from "@nirvana/core/models"; import { channels } from "../../shared/constants"; -import { useEffect } from "react"; +import { useNavigate } from "react-router-dom"; export default function Login() { + let navigate = useNavigate(); + const logIn = () => { // send to main process window.API.send(channels.ACTIVATE_LOG_IN); }; useEffect(() => { - window.API.receive(channels.AUTH_TOKEN, (data: any) => { - console.log(data); + window.API.receive(channels.AUTH_TOKEN, async (accessToken: string) => { + console.log(accessToken); + + // get user info from access token + const userInfo: UserInfo = await ( + await fetch( + `https://www.googleapis.com/oauth2/v1/userinfo?access_token=${accessToken}` + ) + ).json(); + + console.log("user data: "); + console.log(userInfo); + + // if user is a user, then continue to next route + navigate("/home"); + + // if user is not an existing user, then show create account page }); // return () => { @@ -22,6 +42,8 @@ export default function Login() { return (
+ + diff --git a/packages/desktop/src/pages/Profile/index.tsx b/packages/desktop/src/pages/Profile/index.tsx new file mode 100644 index 0000000..3f0ea80 --- /dev/null +++ b/packages/desktop/src/pages/Profile/index.tsx @@ -0,0 +1,3 @@ +export default function Profile() { + return this is the profile page; +} diff --git a/yarn.lock b/yarn.lock index f8b3852..43e3be6 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1024,7 +1024,7 @@ core-js-pure "^3.20.2" regenerator-runtime "^0.13.4" -"@babel/runtime@^7.10.2", "@babel/runtime@^7.11.2", "@babel/runtime@^7.12.5", "@babel/runtime@^7.13.10", "@babel/runtime@^7.16.3", "@babel/runtime@^7.17.2", "@babel/runtime@^7.5.5", "@babel/runtime@^7.6.2", "@babel/runtime@^7.7.2", "@babel/runtime@^7.8.4", "@babel/runtime@^7.8.7", "@babel/runtime@^7.9.2": +"@babel/runtime@^7.10.2", "@babel/runtime@^7.11.2", "@babel/runtime@^7.12.5", "@babel/runtime@^7.13.10", "@babel/runtime@^7.16.3", "@babel/runtime@^7.17.2", "@babel/runtime@^7.5.5", "@babel/runtime@^7.6.2", "@babel/runtime@^7.7.2", "@babel/runtime@^7.7.6", "@babel/runtime@^7.8.4", "@babel/runtime@^7.8.7", "@babel/runtime@^7.9.2": version "7.17.2" resolved "https://registry.yarnpkg.com/@babel/runtime/-/runtime-7.17.2.tgz#66f68591605e59da47523c631416b18508779941" integrity sha512-hzeyJyMA1YGdJTuWU0e/j4wKXrU4OMFvY2MSlaI9B7VQb0r5cxTE3EAIS2Q7Tn2RIcDkRvTA/v2JsAEhxe99uw== @@ -6292,6 +6292,13 @@ he@^1.2.0: resolved "https://registry.yarnpkg.com/he/-/he-1.2.0.tgz#84ae65fa7eafb165fddb61566ae14baf05664f0f" integrity sha512-F/1DnUGPopORZi0ni+CvrCgHQ5FyEAHRLSApuYWMmrbSwoN2Mn/7k+Gl38gJnR7yyDZk6WLXwiGod1JOWNDKGw== +history@^5.2.0: + version "5.3.0" + resolved "https://registry.yarnpkg.com/history/-/history-5.3.0.tgz#1548abaa245ba47992f063a0783db91ef201c73b" + integrity sha512-ZqaKwjjrAYUYfLG+htGaIIZ4nioX2L70ZUMIFysS3xvBsSG4x/n1V6TXV3N8ZYNuFGlDirFg32T7B6WOUPDYcQ== + dependencies: + "@babel/runtime" "^7.7.6" + hoist-non-react-statics@^3.3.1, hoist-non-react-statics@^3.3.2: version "3.3.2" resolved "https://registry.yarnpkg.com/hoist-non-react-statics/-/hoist-non-react-statics-3.3.2.tgz#ece0acaf71d62c2969c2ec59feff42a4b1a85b45" @@ -9640,6 +9647,21 @@ react-refresh@^0.11.0: resolved "https://registry.yarnpkg.com/react-refresh/-/react-refresh-0.11.0.tgz#77198b944733f0f1f1a90e791de4541f9f074046" integrity sha512-F27qZr8uUqwhWZboondsPx8tnC3Ct3SxZA3V5WyEvujRyyNv0VYPhoBg1gZ8/MV5tubQp76Trw8lTv9hzRBa+A== +react-router-dom@6: + version "6.2.2" + resolved "https://registry.yarnpkg.com/react-router-dom/-/react-router-dom-6.2.2.tgz#f1a2c88365593c76b9612ae80154a13fcb72e442" + integrity sha512-AtYEsAST7bDD4dLSQHDnk/qxWLJdad5t1HFa1qJyUrCeGgEuCSw0VB/27ARbF9Fi/W5598ujvJOm3ujUCVzuYQ== + dependencies: + history "^5.2.0" + react-router "6.2.2" + +react-router@6.2.2: + version "6.2.2" + resolved "https://registry.yarnpkg.com/react-router/-/react-router-6.2.2.tgz#495e683a0c04461eeb3d705fe445d6cf42f0c249" + integrity sha512-/MbxyLzd7Q7amp4gDOGaYvXwhEojkJD5BtExkuKmj39VEE0m3l/zipf6h2WIB2jyAO0lI6NGETh4RDcktRm4AQ== + dependencies: + history "^5.2.0" + react-scripts@5.0.0: version "5.0.0" resolved "https://registry.yarnpkg.com/react-scripts/-/react-scripts-5.0.0.tgz#6547a6d7f8b64364ef95273767466cc577cb4b60"