From ac74d20d41af005f793aae778083c38d63456ade Mon Sep 17 00:00:00 2001 From: Jordan Doyle Date: Thu, 21 Oct 2021 01:01:27 +0100 Subject: [PATCH] yarn fmt --- chartered-frontend/src/index.tsx | 19 +++++++++++++------ chartered-frontend/src/overscrollColourFixer.ts | 6 ++++-- chartered-frontend/src/useAuth.tsx | 25 ++++++++++++++----------- chartered-frontend/src/pages/Dashboard.tsx | 32 +++++++++++++++++++++++++------- chartered-frontend/src/pages/Login.tsx | 12 ++++++++++-- chartered-frontend/src/pages/Search.tsx | 17 ++++++----------- chartered-frontend/src/pages/User.tsx | 7 ++----- chartered-frontend/src/sections/Nav.tsx | 13 +++++++++++-- chartered-web/src/middleware/auth.rs | 4 ++-- chartered-frontend/src/pages/crate/CrateView.tsx | 17 ++++++++++------- chartered-frontend/src/pages/crate/Members.tsx | 17 +++++++---------- chartered-frontend/src/pages/crate/OrganisationView.tsx | 2 +- chartered-frontend/src/pages/organisations/CreateOrganisation.tsx | 2 +- chartered-frontend/src/pages/organisations/ListOrganisations.tsx | 2 +- chartered-frontend/src/pages/ssh-keys/AddSshKeys.tsx | 2 +- chartered-frontend/src/pages/ssh-keys/ListSshKeys.tsx | 2 +- chartered-web/src/endpoints/web_api/auth/logout.rs | 8 +++----- chartered-web/src/endpoints/web_api/auth/mod.rs | 17 ++++++++--------- 18 files changed, 115 insertions(+), 89 deletions(-) diff --git a/chartered-frontend/src/index.tsx b/chartered-frontend/src/index.tsx index f82144d..a983d10 100644 --- a/chartered-frontend/src/index.tsx +++ a/chartered-frontend/src/index.tsx @@ -25,17 +25,22 @@ import CreateOrganisation from "./pages/organisations/CreateOrganisation"; import User from "./pages/User"; import Search from "./pages/Search"; -import {backgroundFix} from "./overscrollColourFixer"; +import { backgroundFix } from "./overscrollColourFixer"; -if (window.matchMedia && window.matchMedia('(prefers-color-scheme: dark)').matches) { +if ( + window.matchMedia && + window.matchMedia("(prefers-color-scheme: dark)").matches +) { document.querySelector("body")?.classList.add("dark"); } -window.matchMedia('(prefers-color-scheme: dark)').addEventListener('change', e => { - const body = document.querySelector("body"); - body?.classList.toggle("dark", e.matches); - backgroundFix(body); -}); +window + .matchMedia("(prefers-color-scheme: dark)") + .addEventListener("change", (e) => { + const body = document.querySelector("body"); + body?.classList.toggle("dark", e.matches); + backgroundFix(body); + }); function App() { return ( diff --git a/chartered-frontend/src/overscrollColourFixer.ts b/chartered-frontend/src/overscrollColourFixer.ts index 1cf8424..2b6a5d5 100644 --- a/chartered-frontend/src/overscrollColourFixer.ts +++ a/chartered-frontend/src/overscrollColourFixer.ts @@ -5,9 +5,11 @@ export const backgroundFix = (body: HTMLBodyElement | null) => { if (body?.classList.contains("dark")) { - document.documentElement.style.backgroundColor = window.scrollY > 70 ? "#0e1825" : "#2a3746"; + document.documentElement.style.backgroundColor = + window.scrollY > 70 ? "#0e1825" : "#2a3746"; } else { - document.documentElement.style.backgroundColor = window.scrollY > 70 ? "var(--bs-primary)" : "white"; + document.documentElement.style.backgroundColor = + window.scrollY > 70 ? "var(--bs-primary)" : "white"; } }; diff --git a/chartered-frontend/src/useAuth.tsx b/chartered-frontend/src/useAuth.tsx index cf90e5e..b64805f 100644 --- a/chartered-frontend/src/useAuth.tsx +++ a/chartered-frontend/src/useAuth.tsx @@ -1,6 +1,10 @@ import { useState, useEffect, useContext, createContext } from "react"; import { useLocation, Redirect } from "react-router-dom"; -import {authenticatedEndpoint, BASE_URL, unauthenticatedEndpoint} from "./util"; +import { + authenticatedEndpoint, + BASE_URL, + unauthenticatedEndpoint, +} from "./util"; import LoadingPage from "./pages/Loading"; export interface OAuthProviders { @@ -148,18 +152,15 @@ } try { - await fetch( - `${BASE_URL}/a/${getAuthKey()}/web/v1/auth/logout`, - { - method: "GET", - headers: { - "Content-Type": "application/json", - "User-Agent": window.navigator.userAgent, - }, - } - ); + await fetch(`${BASE_URL}/a/${getAuthKey()}/web/v1/auth/logout`, { + method: "GET", + headers: { + "Content-Type": "application/json", + "User-Agent": window.navigator.userAgent, + }, + }); } catch (e) { - console.error("Failed to fully log user out of session", e) + console.error("Failed to fully log user out of session", e); } finally { setAuth(null); } diff --git a/chartered-frontend/src/pages/Dashboard.tsx b/chartered-frontend/src/pages/Dashboard.tsx index 948355b..1c4abde 100644 --- a/chartered-frontend/src/pages/Dashboard.tsx +++ a/chartered-frontend/src/pages/Dashboard.tsx @@ -1,6 +1,6 @@ import { PropsWithChildren } from "react"; -import {Link, Redirect} from "react-router-dom"; +import { Link, Redirect } from "react-router-dom"; import { useAuth } from "../useAuth"; import Nav from "../sections/Nav"; import { Calendar3, ChevronRight, Download } from "react-bootstrap-icons"; @@ -87,9 +87,13 @@

Newly Created

- {recentlyCreatedError ?
- {recentlyCreatedError} -
: <>} + {recentlyCreatedError ? ( +
+ {recentlyCreatedError} +
+ ) : ( + <> + )} {(recentlyCreated?.crates || []).map((v) => (

Recently Updated

- {recentlyUpdatedError ?
- {recentlyUpdatedError} -
: <>} + {recentlyUpdatedError ? ( +
+ {recentlyUpdatedError} +
+ ) : ( + <> + )} {(recentlyUpdated?.versions || []).map((v) => (

Most Downloaded

- {mostDownloadedError ?
- {mostDownloadedError} -
: <>} + {mostDownloadedError ? ( +
+ {mostDownloadedError} +
+ ) : ( + <> + )} {(mostDownloaded?.crates || []).map((v) => ( { isMountedRef.current = false }; + return () => { + isMountedRef.current = false; + }; }); const handleSubmit = async (evt: SyntheticEvent) => { diff --git a/chartered-frontend/src/pages/Search.tsx b/chartered-frontend/src/pages/Search.tsx index 92350a8..561a5da 100644 --- a/chartered-frontend/src/pages/Search.tsx +++ a/chartered-frontend/src/pages/Search.tsx @@ -1,11 +1,8 @@ import { Link, useLocation } from "react-router-dom"; import Nav from "../sections/Nav"; import { useAuth } from "../useAuth"; -import { - ProfilePicture, - useAuthenticatedRequest, -} from "../util"; +import { ProfilePicture, useAuthenticatedRequest } from "../util"; import { BoxSeam } from "react-bootstrap-icons"; import { LoadingSpinner } from "./Loading"; @@ -46,7 +43,7 @@ const auth = useAuth(); if (!auth) { - return <>; + return <>; } const { response: results, error } = @@ -59,7 +56,7 @@ ); if (error) { - return
{error}
; + return
{error}
; } if (!results) { @@ -125,7 +122,7 @@ const auth = useAuth(); if (!auth) { - return <>; + return <>; } const { response: results, error } = @@ -138,7 +135,7 @@ ); if (error) { - return
{error}
+ return
{error}
; } if (!results) { @@ -175,9 +172,7 @@ className="text-decoration-none" >

- - {crate.organisation} - + {crate.organisation} /{crate.name}

diff --git a/chartered-frontend/src/pages/User.tsx b/chartered-frontend/src/pages/User.tsx index e1bc288..0e9e7e9 100644 --- a/chartered-frontend/src/pages/User.tsx +++ a/chartered-frontend/src/pages/User.tsx @@ -1,9 +1,6 @@ -import {Redirect, useParams} from "react-router-dom"; +import { Redirect, useParams } from "react-router-dom"; import { useAuth } from "../useAuth"; -import { - ProfilePicture, - useAuthenticatedRequest, -} from "../util"; +import { ProfilePicture, useAuthenticatedRequest } from "../util"; import Nav from "../sections/Nav"; import ErrorPage from "./ErrorPage"; import ReactPlaceholder from "react-placeholder/lib"; diff --git a/chartered-frontend/src/sections/Nav.tsx b/chartered-frontend/src/sections/Nav.tsx index ed6a58f..a8d7bad 100644 --- a/chartered-frontend/src/sections/Nav.tsx +++ a/chartered-frontend/src/sections/Nav.tsx @@ -1,4 +1,4 @@ -import {SyntheticEvent, useState} from "react"; +import { SyntheticEvent, useState } from "react"; import { useHistory, useLocation } from "react-router-dom"; import { NavLink, Link } from "react-router-dom"; @@ -51,7 +51,16 @@
  • - + { + return ( + location.pathname.startsWith("/organisations/") || + location.pathname.startsWith("/crates/") + ); + }} + > Organisations
  • diff --git a/chartered-web/src/middleware/auth.rs b/chartered-web/src/middleware/auth.rs index 2544106..4c66dbf 100644 --- a/chartered-web/src/middleware/auth.rs +++ a/chartered-web/src/middleware/auth.rs @@ -1,17 +1,17 @@ use axum::{ body::{box_body, Body, BoxBody}, extract::{self, FromRequest, RequestParts}, http::{Request, Response, StatusCode}, }; +use chartered_db::users::User; use chartered_db::ConnectionPool; use futures::future::BoxFuture; +use std::sync::Arc; use std::{ collections::HashMap, task::{Context, Poll}, }; -use std::sync::Arc; use tower::Service; -use chartered_db::users::User; use crate::endpoints::ErrorResponse; diff --git a/chartered-frontend/src/pages/crate/CrateView.tsx b/chartered-frontend/src/pages/crate/CrateView.tsx index bb45286..697609f 100644 --- a/chartered-frontend/src/pages/crate/CrateView.tsx +++ a/chartered-frontend/src/pages/crate/CrateView.tsx @@ -73,7 +73,11 @@ export default function SingleCrate() { const auth = useAuth(); - const { organisation, crate, subview: currentTab } = useParams(); + const { + organisation, + crate, + subview: currentTab, + } = useParams(); if (!auth) { return ; @@ -315,13 +319,12 @@ crate: string; } -function Members({ - organisation, - crate, -}: MembersProps) { +function Members({ organisation, crate }: MembersProps) { const auth = useAuth(); - if (!auth) { return <>; } + if (!auth) { + return <>; + } const [reload, setReload] = useState(0); const { response, error } = useAuthenticatedRequest( @@ -349,7 +352,7 @@ const saveMemberPermissions = async ( prospectiveMember: boolean, uuid: string, - selectedPermissions: string[], + selectedPermissions: string[] ) => { let res = await fetch( authenticatedEndpoint(auth, `crates/${organisation}/${crate}/members`), diff --git a/chartered-frontend/src/pages/crate/Members.tsx b/chartered-frontend/src/pages/crate/Members.tsx index 6f9613f..a671ede 100644 --- a/chartered-frontend/src/pages/crate/Members.tsx +++ a/chartered-frontend/src/pages/crate/Members.tsx @@ -1,14 +1,7 @@ import { useState, useEffect, useRef } from "react"; import { Link } from "react-router-dom"; -import { - Trash, - CheckLg, - PlusLg, PersonPlusFill, -} from "react-bootstrap-icons"; -import { - authenticatedEndpoint, - ProfilePicture, -} from "../../util"; +import { Trash, CheckLg, PlusLg, PersonPlusFill } from "react-bootstrap-icons"; +import { authenticatedEndpoint, ProfilePicture } from "../../util"; import { useAuth } from "../../useAuth"; import { Button, Modal } from "react-bootstrap"; import { AsyncTypeahead } from "react-bootstrap-typeahead"; @@ -250,7 +243,11 @@ interface MemberListInserterProps { existingMembers: Member[]; - onInsert: (username: string, user_uuid: string, picture_url: string | null) => any; + onInsert: ( + username: string, + user_uuid: string, + picture_url: string | null + ) => any; } interface SearchOption { diff --git a/chartered-frontend/src/pages/crate/OrganisationView.tsx b/chartered-frontend/src/pages/crate/OrganisationView.tsx index 138e59f..e14faa6 100644 --- a/chartered-frontend/src/pages/crate/OrganisationView.tsx +++ a/chartered-frontend/src/pages/crate/OrganisationView.tsx @@ -1,5 +1,5 @@ import { useState } from "react"; -import {Link, Redirect, useParams} from "react-router-dom"; +import { Link, Redirect, useParams } from "react-router-dom"; import Nav from "../../sections/Nav"; import { useAuth } from "../../useAuth"; diff --git a/chartered-frontend/src/pages/organisations/CreateOrganisation.tsx b/chartered-frontend/src/pages/organisations/CreateOrganisation.tsx index d8feeac..c53968a 100644 --- a/chartered-frontend/src/pages/organisations/CreateOrganisation.tsx +++ a/chartered-frontend/src/pages/organisations/CreateOrganisation.tsx @@ -1,4 +1,4 @@ -import {SyntheticEvent, useState} from "react"; +import { SyntheticEvent, useState } from "react"; import { Link, useHistory } from "react-router-dom"; import Nav from "../../sections/Nav"; diff --git a/chartered-frontend/src/pages/organisations/ListOrganisations.tsx b/chartered-frontend/src/pages/organisations/ListOrganisations.tsx index 9ef34dc..8859099 100644 --- a/chartered-frontend/src/pages/organisations/ListOrganisations.tsx +++ a/chartered-frontend/src/pages/organisations/ListOrganisations.tsx @@ -1,5 +1,5 @@ import { Plus } from "react-bootstrap-icons"; -import {Link, Redirect} from "react-router-dom"; +import { Link, Redirect } from "react-router-dom"; import Nav from "../../sections/Nav"; import { useAuth } from "../../useAuth"; diff --git a/chartered-frontend/src/pages/ssh-keys/AddSshKeys.tsx b/chartered-frontend/src/pages/ssh-keys/AddSshKeys.tsx index cf15065..f213501 100644 --- a/chartered-frontend/src/pages/ssh-keys/AddSshKeys.tsx +++ a/chartered-frontend/src/pages/ssh-keys/AddSshKeys.tsx @@ -1,4 +1,4 @@ -import {SyntheticEvent, useState} from "react"; +import { SyntheticEvent, useState } from "react"; import { Link, useHistory } from "react-router-dom"; import Nav from "../../sections/Nav"; diff --git a/chartered-frontend/src/pages/ssh-keys/ListSshKeys.tsx b/chartered-frontend/src/pages/ssh-keys/ListSshKeys.tsx index bbce0bd..d4603f8 100644 --- a/chartered-frontend/src/pages/ssh-keys/ListSshKeys.tsx +++ a/chartered-frontend/src/pages/ssh-keys/ListSshKeys.tsx @@ -1,5 +1,5 @@ import { useState } from "react"; -import {Link, Redirect} from "react-router-dom"; +import { Link, Redirect } from "react-router-dom"; import Nav from "../../sections/Nav"; import { useAuth } from "../../useAuth"; diff --git a/chartered-web/src/endpoints/web_api/auth/logout.rs b/chartered-web/src/endpoints/web_api/auth/logout.rs index 3d0696e..85d0526 100644 --- a/chartered-web/src/endpoints/web_api/auth/logout.rs +++ a/chartered-web/src/endpoints/web_api/auth/logout.rs @@ -1,9 +1,9 @@ -use std::sync::Arc; use axum::{extract, Json}; +use chartered_db::users::UserSession; use chartered_db::ConnectionPool; use serde::Serialize; +use std::sync::Arc; use thiserror::Error; -use chartered_db::users::UserSession; pub async fn handle( extract::Extension(session): extract::Extension>, @@ -11,9 +11,7 @@ ) -> Result, Error> { session.delete(db).await?; - Ok(Json(LogoutResponse { - success: true, - })) + Ok(Json(LogoutResponse { success: true })) } #[derive(Debug, Serialize)] diff --git a/chartered-web/src/endpoints/web_api/auth/mod.rs b/chartered-web/src/endpoints/web_api/auth/mod.rs index 1445227..094ecbb 100644 --- a/chartered-web/src/endpoints/web_api/auth/mod.rs +++ a/chartered-web/src/endpoints/web_api/auth/mod.rs @@ -14,21 +14,20 @@ use serde::Serialize; use std::convert::Infallible; +pub mod logout; pub mod openid; pub mod password; -pub mod logout; pub fn authenticated_routes() -> Router< impl tower::Service< - Request, - Response = Response, - Error = Infallible, - Future = impl Future, Infallible>> + Send, - > + Clone - + Send, + Request, + Response = Response, + Error = Infallible, + Future = impl Future, Infallible>> + Send, + > + Clone + + Send, > { - crate::axum_box_after_every_route!(Router::new() - .route("/logout", get(logout::handle))) + crate::axum_box_after_every_route!(Router::new().route("/logout", get(logout::handle))) } pub fn unauthenticated_routes() -> Router< -- rgit 0.1.3