yarn fmt
Diff
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(-)
@@ -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 (
@@ -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";
}
};
@@ -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);
}
@@ -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 @@
<div className="row">
<div className="col-12 col-md-4">
<h4>Newly Created</h4>
{recentlyCreatedError ? <div className="alert alert-danger" role="alert">
{recentlyCreatedError}
</div> : <></>}
{recentlyCreatedError ? (
<div className="alert alert-danger" role="alert">
{recentlyCreatedError}
</div>
) : (
<></>
)}
{(recentlyCreated?.crates || []).map((v) => (
<CrateCard
key={v.name}
@@ -114,9 +118,13 @@
<div className="col-12 col-md-4">
<h4>Recently Updated</h4>
{recentlyUpdatedError ? <div className="alert alert-danger" role="alert">
{recentlyUpdatedError}
</div> : <></>}
{recentlyUpdatedError ? (
<div className="alert alert-danger" role="alert">
{recentlyUpdatedError}
</div>
) : (
<></>
)}
{(recentlyUpdated?.versions || []).map((v) => (
<CrateCard
key={v.name}
@@ -130,9 +138,13 @@
<div className="col-12 col-md-4">
<h4>Most Downloaded</h4>
{mostDownloadedError ? <div className="alert alert-danger" role="alert">
{mostDownloadedError}
</div> : <></>}
{mostDownloadedError ? (
<div className="alert alert-danger" role="alert">
{mostDownloadedError}
</div>
) : (
<></>
)}
{(mostDownloaded?.crates || []).map((v) => (
<CrateCard
key={v.name}
@@ -1,4 +1,10 @@
import {useState, useEffect, useRef, SyntheticEvent, MouseEventHandler} from "react";
import {
useState,
useEffect,
useRef,
SyntheticEvent,
MouseEventHandler,
} from "react";
import { useLocation } from "react-router-dom";
import { useAuth } from "../useAuth";
@@ -37,7 +43,9 @@
}
isMountedRef.current = true;
return () => { isMountedRef.current = false };
return () => {
isMountedRef.current = false;
};
});
const handleSubmit = async (evt: SyntheticEvent) => {
@@ -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 <div className="alert alert-danger">{error}</div>;
return <div className="alert alert-danger">{error}</div>;
}
if (!results) {
@@ -125,7 +122,7 @@
const auth = useAuth();
if (!auth) {
return <></>;
return <></>;
}
const { response: results, error } =
@@ -138,7 +135,7 @@
);
if (error) {
return <div className="alert alert-danger">{error}</div>
return <div className="alert alert-danger">{error}</div>;
}
if (!results) {
@@ -175,9 +172,7 @@
className="text-decoration-none"
>
<h4 className="text-primary d-inline px-2 m-0">
<span className="text-muted">
{crate.organisation}
</span>
<span className="text-muted">{crate.organisation}</span>
/{crate.name}
</h4>
</Link>
@@ -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";
@@ -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 @@
</NavLink>
</li>
<li className="nav-item">
<NavLink to="/organisations" className="nav-link">
<NavLink
to="/organisations"
className="nav-link"
isActive={(match, location) => {
return (
location.pathname.startsWith("/organisations/") ||
location.pathname.startsWith("/crates/")
);
}}
>
Organisations
</NavLink>
</li>
@@ -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;
@@ -73,7 +73,11 @@
export default function SingleCrate() {
const auth = useAuth();
const { organisation, crate, subview: currentTab } = useParams<UrlParameters>();
const {
organisation,
crate,
subview: currentTab,
} = useParams<UrlParameters>();
if (!auth) {
return <Redirect to="/login" />;
@@ -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<CratesMembersResponse>(
@@ -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`),
@@ -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 {
@@ -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";
@@ -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";
@@ -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";
@@ -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";
@@ -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";
@@ -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<Arc<UserSession>>,
@@ -11,9 +11,7 @@
) -> Result<Json<LogoutResponse>, Error> {
session.delete(db).await?;
Ok(Json(LogoutResponse {
success: true,
}))
Ok(Json(LogoutResponse { success: true }))
}
#[derive(Debug, Serialize)]
@@ -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<Body>,
Response = Response<BoxBody>,
Error = Infallible,
Future = impl Future<Output = Result<Response<BoxBody>, Infallible>> + Send,
> + Clone
+ Send,
Request<Body>,
Response = Response<BoxBody>,
Error = Infallible,
Future = impl Future<Output = Result<Response<BoxBody>, 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<