diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..ebcc2a1 --- /dev/null +++ b/.gitignore @@ -0,0 +1,27 @@ +# Logs +logs +*.log +npm-debug.log* +yarn-debug.log* +yarn-error.log* +pnpm-debug.log* +lerna-debug.log* + +node_modules +dist +dist-ssr +*.local + +# Editor directories and files +.vscode/* +!.vscode/extensions.json +.idea +.DS_Store +*.suo +*.ntvs* +*.njsproj +*.sln +*.sw? + +# Sentry Config File +.env.sentry-build-plugin diff --git a/README.md b/README.md new file mode 100644 index 0000000..74872fd --- /dev/null +++ b/README.md @@ -0,0 +1,50 @@ +# React + TypeScript + Vite + +This template provides a minimal setup to get React working in Vite with HMR and some ESLint rules. + +Currently, two official plugins are available: + +- [@vitejs/plugin-react](https://github.com/vitejs/vite-plugin-react/blob/main/packages/plugin-react/README.md) uses [Babel](https://babeljs.io/) for Fast Refresh +- [@vitejs/plugin-react-swc](https://github.com/vitejs/vite-plugin-react-swc) uses [SWC](https://swc.rs/) for Fast Refresh + +## Expanding the ESLint configuration + +If you are developing a production application, we recommend updating the configuration to enable type aware lint rules: + +- Configure the top-level `parserOptions` property like this: + +```js +export default tseslint.config({ + languageOptions: { + // other options... + parserOptions: { + project: ['./tsconfig.node.json', './tsconfig.app.json'], + tsconfigRootDir: import.meta.dirname, + }, + }, +}) +``` + +- Replace `tseslint.configs.recommended` to `tseslint.configs.recommendedTypeChecked` or `tseslint.configs.strictTypeChecked` +- Optionally add `...tseslint.configs.stylisticTypeChecked` +- Install [eslint-plugin-react](https://github.com/jsx-eslint/eslint-plugin-react) and update the config: + +```js +// eslint.config.js +import react from 'eslint-plugin-react' + +export default tseslint.config({ + // Set the react version + settings: { react: { version: '18.3' } }, + plugins: { + // Add the react plugin + react, + }, + rules: { + // other rules... + // Enable its recommended rules + ...react.configs.recommended.rules, + ...react.configs['jsx-runtime'].rules, + }, +}) +``` diff --git a/eslint.config.js b/eslint.config.js new file mode 100644 index 0000000..092408a --- /dev/null +++ b/eslint.config.js @@ -0,0 +1,28 @@ +import js from '@eslint/js' +import globals from 'globals' +import reactHooks from 'eslint-plugin-react-hooks' +import reactRefresh from 'eslint-plugin-react-refresh' +import tseslint from 'typescript-eslint' + +export default tseslint.config( + { ignores: ['dist'] }, + { + extends: [js.configs.recommended, ...tseslint.configs.recommended], + files: ['**/*.{ts,tsx}'], + languageOptions: { + ecmaVersion: 2020, + globals: globals.browser, + }, + plugins: { + 'react-hooks': reactHooks, + 'react-refresh': reactRefresh, + }, + rules: { + ...reactHooks.configs.recommended.rules, + 'react-refresh/only-export-components': [ + 'warn', + { allowConstantExport: true }, + ], + }, + }, +) diff --git a/index.html b/index.html new file mode 100644 index 0000000..5ba7d85 --- /dev/null +++ b/index.html @@ -0,0 +1,13 @@ + + + + + + + flipdot apps + + +
+ + + diff --git a/package.json b/package.json new file mode 100644 index 0000000..b393373 --- /dev/null +++ b/package.json @@ -0,0 +1,35 @@ +{ + "name": "apps", + "private": true, + "version": "0.0.0", + "type": "module", + "scripts": { + "dev": "vite", + "dev-public": "vite --host 0.0.0.0", + "build": "tsc -b && vite build", + "lint": "eslint .", + "preview": "vite preview" + }, + "dependencies": { + "@sentry/integrations": "^7.114.0", + "@sentry/react": "^8.36.0", + "@sentry/vite-plugin": "^2.22.6", + "oidc-client-ts": "^3.1.0", + "react": "^18.3.1", + "react-dom": "^18.3.1", + "react-router-dom": "^6.27.0" + }, + "devDependencies": { + "@eslint/js": "^9.13.0", + "@types/react": "^18.3.12", + "@types/react-dom": "^18.3.1", + "@vitejs/plugin-react-swc": "^3.5.0", + "eslint": "^9.13.0", + "eslint-plugin-react-hooks": "^5.0.0", + "eslint-plugin-react-refresh": "^0.4.14", + "globals": "^15.11.0", + "typescript": "~5.6.2", + "typescript-eslint": "^8.11.0", + "vite": "^5.4.10" + } +} diff --git a/public/fd.svg b/public/fd.svg new file mode 100644 index 0000000..ad7b7a6 --- /dev/null +++ b/public/fd.svg @@ -0,0 +1,12 @@ + + + + + + + + + + + + \ No newline at end of file diff --git a/src/App.css b/src/App.css new file mode 100644 index 0000000..2c78065 --- /dev/null +++ b/src/App.css @@ -0,0 +1,48 @@ +body { + margin: 0; + /*display: flex;*/ + /*flex-direction: column;*/ + /*justify-content: flex-start;*/ + /*place-items: center;*/ + /*min-width: 320px;*/ + /*min-height: 100vh;*/ +} + +#root { + margin: 0; + display: flex; + flex-direction: column; + place-items: flex-start; + /*min-width: 320px;*/ + /*min-height: 100vh;*/ +} + +#content { + max-width: 1280px; + margin: 0 auto; + padding: 2rem; + text-align: center; +} + +/*.xlogo:hover {*/ +/* filter: drop-shadow(0 0 2em #f5c600);*/ +/*}*/ + +@keyframes logo-spin { + from { + transform: rotate(0deg); + } + to { + transform: rotate(360deg); + } +} + +@media (prefers-reduced-motion: no-preference) { + a:nth-of-type(2) .logo { + animation: logo-spin infinite 20s linear; + } +} + +.card { + padding: 2em; +} diff --git a/src/App.tsx b/src/App.tsx new file mode 100644 index 0000000..7f48ba3 --- /dev/null +++ b/src/App.tsx @@ -0,0 +1,52 @@ +import flipdotLogo from './assets/flipdot.svg' +import './App.css' +// import { Navigate, useLocation, useNavigate } from "react-router-dom"; +import Login from "./Login.tsx"; +import {AuthProvider, useAuth} from "./AuthContext.tsx"; +import React from "react"; +import {Route, Routes} from "react-router-dom"; +import Home from "./Home.tsx"; +import RequireAuth from "./RequireAuth.tsx"; +import LoginCallback from "./LoginCallback.tsx"; +import NavBar from "./NavBar.tsx"; + + +function App() { + + return + +
+ + }> + }/> + + }/> + }/> + +
+
+ + // const auth = useAuth(); + // // let navigate = useNavigate(); + // + // if (!auth.user) { + // return + // } + // + // + // return ( + // <> + //
+ // flipdot logo + //
+ //

flipdot app dashboard

+ //
+ //

+ // TODO: List of apps go here + //

+ //
+ // + // ) +} + +export default App diff --git a/src/AuthContext.tsx b/src/AuthContext.tsx new file mode 100644 index 0000000..bc29baa --- /dev/null +++ b/src/AuthContext.tsx @@ -0,0 +1,56 @@ +import './App.css' +import {User} from 'oidc-client-ts' +// import { Navigate, useLocation, useNavigate } from "react-router-dom"; +import {createContext, useContext, useState} from "react"; +import AuthService from "./AuthService.ts"; + +interface AuthContextType { + user: null | User; + login: () => void; + logout: () => void; + loginCallback: () => Promise; +} + +const AuthContext = createContext({ + user: null, + login: () => { + console.error("login not implemented. Did you forget to wrap your app in an AuthProvider?"); + }, + logout: () => { + console.error("logout not implemented. Did you forget to wrap your app in an AuthProvider?"); + }, + loginCallback: async () => { + console.error("loginCallback not implemented. Did you forget to wrap your app in an AuthProvider?"); + return null; + } +}); + +const useAuth = () => useContext(AuthContext); + +function AuthProvider({children}: { children: React.ReactNode }) { + const [user, setUser] = useState( + JSON.parse( + sessionStorage.getItem("session") || "null" + ) || undefined + ); + + const authService = new AuthService(); + + const loginCallback = async () => { + const authedUser = await authService.loginCallback(); + setUser(authedUser); + return authedUser; + }; + + const login = () => authService.login(); + const logout = async () => { + await authService.logout(); + setUser(null); + } + + const value = {user, login, logout, loginCallback}; + + return {children}; +} + +export {useAuth, AuthProvider}; diff --git a/src/AuthService.ts b/src/AuthService.ts new file mode 100644 index 0000000..56fc6ab --- /dev/null +++ b/src/AuthService.ts @@ -0,0 +1,33 @@ +import {UserManager} from "oidc-client-ts"; + +export default class AuthService { + private userManager: UserManager; + + constructor() { + this.userManager = new UserManager({ + authority: "https://login.flipdot.org/realms/flipdot", + client_id: "flipdot-app-dashboard", + redirect_uri: window.location.origin + "/login/callback", + response_type: "code", + }) + } + + getUser() { + return this.userManager.getUser(); + } + + login() { + return this.userManager.signinRedirect(); + } + + loginCallback() { + return this.userManager.signinRedirectCallback(); + } + + logout() { + // only logout in this application, not on the oidc server + return this.userManager.revokeTokens().then(() => { + return this.userManager.removeUser(); + }); + } +} diff --git a/src/Home.tsx b/src/Home.tsx new file mode 100644 index 0000000..c1696a4 --- /dev/null +++ b/src/Home.tsx @@ -0,0 +1,26 @@ +import flipdotLogo from './assets/flipdot.svg' +import './App.css' +// import { Navigate, useLocation, useNavigate } from "react-router-dom"; +import React from "react"; + + +function Home() { + + // const auth = useAuth(); + + return ( + <> +
+ flipdot logo +
+

flipdot app dashboard

+
+

+ TODO: List of apps go here +

+
+ + ) +} + +export default Home diff --git a/src/Login.tsx b/src/Login.tsx new file mode 100644 index 0000000..7d9cd68 --- /dev/null +++ b/src/Login.tsx @@ -0,0 +1,25 @@ +import flipdotLogo from './assets/flipdot.svg' +import './App.css' +import {useAuth} from "./AuthContext.tsx"; + + +function Login() { + const auth = useAuth(); + + return ( + <> +
+ flipdot logo +
+

flipdot app dashboard

+
+

+ Schnellzugriff auf alle flipdot Apps für Mitglieder +

+ +
+ + ) +} + +export default Login diff --git a/src/LoginCallback.tsx b/src/LoginCallback.tsx new file mode 100644 index 0000000..9309461 --- /dev/null +++ b/src/LoginCallback.tsx @@ -0,0 +1,22 @@ +import {useAuth} from "./AuthContext.tsx"; +import {useState} from "react"; + +function LoginCallback() { + const auth = useAuth(); + const [error, setError] = useState(null); + auth.loginCallback().then(() => { + console.log("logged in"); + } + ).catch( + (e) => { + // console.error(e); + setError(`Error: ${e.message}`); + } + ); + return
+

Logging in…

+
{error}
+
; +} + +export default LoginCallback; \ No newline at end of file diff --git a/src/NavBar.css b/src/NavBar.css new file mode 100644 index 0000000..2f8dcfa --- /dev/null +++ b/src/NavBar.css @@ -0,0 +1,109 @@ + +.navbar { + background-color: #333; + display: flex; + width: 100%; + height: 4em; + align-items: center; + /*gap: 1em;*/ + box-shadow: 0 0 10px rgba(0, 0, 0, 0.5); +} + +.navbar .logo { + font-size: 1.5rem; + font-weight: bold; + line-height: 0; + color: #fff; + text-decoration: none; + padding: 0.5em; +} + +.navbar ul.nav-links { + display: flex; + list-style: none; + width: 100%; + padding: 0; + margin: 0 1em 0 0; + height: 100%; + /*gap: 1rem;*/ +} + +.navbar .nav-links a { + color: #fff; + text-decoration: none; + padding: 0.5rem 1rem; + transition: background-color 0.3s; +} + +.navbar .nav-links a:hover { + background-color: #555; + border-radius: 5px; +} + +.navbar ul.nav-links > li { + align-self: center; + height: 100%; + display: flex; + align-items: center; + padding: 0; + user-select: none; +} + +.navbar ul.nav-links li ul { + display: none; + position: absolute; + background-color: #333; + border-radius: 0 0 5px 5px; + padding: 0.5em; + list-style: none; + box-shadow: 0 11px 10px rgba(0, 0, 0, 0.5); + /*border: 1px solid #000;*/ + border-top: 0; + top: 4em; +} + +.navbar ul.nav-links li > .title::after { + content: ' ▼'; +} + +.navbar ul.nav-links li:hover ul, +.navbar ul.nav-links li:active ul { + display: block; +} + +.navbar ul.nav-links li:last-child { + margin: 0 0 0 auto; +} + +.navbar ul.nav-links li:last-child ul { + right: 0; +} + +/*.navbar .login-button, .navbar .user-menu {*/ +/* margin: 0.5em 0.5em 0.5em auto;*/ +/* display: flex;*/ +/* align-items: center;*/ +/* gap: 1em;*/ +/*}*/ + +@media (prefers-color-scheme: light) { + .navbar { + background-color: #f9f9f9; + } + + .navbar .logo { + color: #000; + } + + .navbar .nav-links a { + color: #000; + } + + .navbar .nav-links a:hover { + background-color: #ccc; + } + + .navbar ul.nav-links li ul { + background-color: #f9f9f9; + } +} \ No newline at end of file diff --git a/src/NavBar.tsx b/src/NavBar.tsx new file mode 100644 index 0000000..b35d5a5 --- /dev/null +++ b/src/NavBar.tsx @@ -0,0 +1,31 @@ +import {useAuth} from "./AuthContext.tsx"; +import fdLogo from './assets/fd.svg'; +import "./NavBar.css"; +import {Link} from "react-router-dom"; + +function NavBar() { + const auth = useAuth(); + const loginButton =
  • + +
  • ; + const userMenu =
  • + {auth.user?.profile.preferred_username} +
      +
    • + +
    • +
    +
  • + const rightItem = auth.user ? userMenu : loginButton; + return ( + + ) +} + +export default NavBar; \ No newline at end of file diff --git a/src/RequireAuth.tsx b/src/RequireAuth.tsx new file mode 100644 index 0000000..6aac403 --- /dev/null +++ b/src/RequireAuth.tsx @@ -0,0 +1,9 @@ +import {useAuth} from "./AuthContext.tsx"; +import {Navigate} from "react-router-dom"; + +function RequireAuth({children: children}: { children: React.ReactNode }) { + const auth = useAuth(); + return auth.user === undefined ? : children; +} + +export default RequireAuth \ No newline at end of file diff --git a/src/assets/fd.svg b/src/assets/fd.svg new file mode 100644 index 0000000..ad7b7a6 --- /dev/null +++ b/src/assets/fd.svg @@ -0,0 +1,12 @@ + + + + + + + + + + + + \ No newline at end of file diff --git a/src/assets/flipdot.svg b/src/assets/flipdot.svg new file mode 100644 index 0000000..89e0334 --- /dev/null +++ b/src/assets/flipdot.svg @@ -0,0 +1,159 @@ + + + +image/svg+xml \ No newline at end of file diff --git a/src/assets/react.svg b/src/assets/react.svg new file mode 100644 index 0000000..6c87de9 --- /dev/null +++ b/src/assets/react.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/src/index.css b/src/index.css new file mode 100644 index 0000000..31091e1 --- /dev/null +++ b/src/index.css @@ -0,0 +1,65 @@ +:root { + font-family: Inter, system-ui, Avenir, Helvetica, Arial, sans-serif; + line-height: 1.5; + font-weight: 400; + + color-scheme: light dark; + color: rgba(255, 255, 255, 0.87); + background-color: #242424; + + font-synthesis: none; + text-rendering: optimizeLegibility; + -webkit-font-smoothing: antialiased; + -moz-osx-font-smoothing: grayscale; +} + +a { + font-weight: 500; + color: #646cff; + text-decoration: inherit; +} + +a:hover { + color: #535bf2; +} + +h1 { + font-size: 3.2em; + line-height: 1.1; +} + +button { + border-radius: 8px; + border: 1px solid transparent; + padding: 0.6em 1.2em; + font-size: 1em; + font-weight: 500; + font-family: inherit; + background-color: #1a1a1a; + cursor: pointer; + transition: border-color 0.25s; +} + +button:hover { + border-color: #646cff; +} + +button:focus, +button:focus-visible { + outline: 4px auto -webkit-focus-ring-color; +} + +@media (prefers-color-scheme: light) { + :root { + color: #213547; + background-color: #ffffff; + } + + a:hover { + color: #747bff; + } + + button { + background-color: #f9f9f9; + } +} diff --git a/src/main.tsx b/src/main.tsx new file mode 100644 index 0000000..8245553 --- /dev/null +++ b/src/main.tsx @@ -0,0 +1,21 @@ +import React, {StrictMode} from 'react' +import {createRoot} from 'react-dom/client' +import './index.css' +import App from './App.tsx' + +import * as Sentry from "@sentry/react"; +import {BrowserRouter} from "react-router-dom"; + +Sentry.init({ + dsn: "https://7976fc906df26e2865ad329d909f52f5@sentry.flipdot.org/6", + allowUrls: [/https:\/\/apps\.flipdot\.org/], + integrations: [Sentry.captureConsoleIntegration()], +}); + +createRoot(document.getElementById('root')!).render( + + + + + , +) diff --git a/src/vite-env.d.ts b/src/vite-env.d.ts new file mode 100644 index 0000000..11f02fe --- /dev/null +++ b/src/vite-env.d.ts @@ -0,0 +1 @@ +/// diff --git a/tsconfig.app.json b/tsconfig.app.json new file mode 100644 index 0000000..f867de0 --- /dev/null +++ b/tsconfig.app.json @@ -0,0 +1,26 @@ +{ + "compilerOptions": { + "tsBuildInfoFile": "./node_modules/.tmp/tsconfig.app.tsbuildinfo", + "target": "ES2020", + "useDefineForClassFields": true, + "lib": ["ES2020", "DOM", "DOM.Iterable"], + "module": "ESNext", + "skipLibCheck": true, + + /* Bundler mode */ + "moduleResolution": "Bundler", + "allowImportingTsExtensions": true, + "isolatedModules": true, + "moduleDetection": "force", + "noEmit": true, + "jsx": "react-jsx", + + /* Linting */ + "strict": true, + "noUnusedLocals": true, + "noUnusedParameters": true, + "noFallthroughCasesInSwitch": true, + "noUncheckedSideEffectImports": true + }, + "include": ["src"] +} diff --git a/tsconfig.json b/tsconfig.json new file mode 100644 index 0000000..1ffef60 --- /dev/null +++ b/tsconfig.json @@ -0,0 +1,7 @@ +{ + "files": [], + "references": [ + { "path": "./tsconfig.app.json" }, + { "path": "./tsconfig.node.json" } + ] +} diff --git a/tsconfig.node.json b/tsconfig.node.json new file mode 100644 index 0000000..abcd7f0 --- /dev/null +++ b/tsconfig.node.json @@ -0,0 +1,24 @@ +{ + "compilerOptions": { + "tsBuildInfoFile": "./node_modules/.tmp/tsconfig.node.tsbuildinfo", + "target": "ES2022", + "lib": ["ES2023"], + "module": "ESNext", + "skipLibCheck": true, + + /* Bundler mode */ + "moduleResolution": "Bundler", + "allowImportingTsExtensions": true, + "isolatedModules": true, + "moduleDetection": "force", + "noEmit": true, + + /* Linting */ + "strict": true, + "noUnusedLocals": true, + "noUnusedParameters": true, + "noFallthroughCasesInSwitch": true, + "noUncheckedSideEffectImports": true + }, + "include": ["vite.config.ts"] +} diff --git a/vite.config.ts b/vite.config.ts new file mode 100644 index 0000000..a7f0968 --- /dev/null +++ b/vite.config.ts @@ -0,0 +1,16 @@ +import { sentryVitePlugin } from "@sentry/vite-plugin"; +import { defineConfig } from 'vite' +import react from '@vitejs/plugin-react-swc' + +// https://vite.dev/config/ +export default defineConfig({ + plugins: [react(), sentryVitePlugin({ + org: "flipdot", + project: "app-dashboard", + url: "https://sentry.flipdot.org" + })], + + build: { + sourcemap: true + } +}) \ No newline at end of file