Skip to content

Commit

Permalink
Merge pull request #14 from gwu-libraries/basic-interface-rework
Browse files Browse the repository at this point in the history
Basic interface rework
  • Loading branch information
alepbloyd authored Aug 26, 2024
2 parents c139080 + 1b0aadf commit 16529d3
Show file tree
Hide file tree
Showing 7 changed files with 52 additions and 45 deletions.
8 changes: 7 additions & 1 deletion rails/app/graphql/mutations/sign_in.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,13 @@ def resolve(**attributes)
if user.valid_password?(attributes[:password])
context[:current_user] = user

MutationResult.call(obj: { object: user }, success: true)
MutationResult.call(
obj: {
object: user
},
success: true,
errors: user.errors
)
else
GraphQL::ExecutionError.new('Incorrect Email/Password')
end
Expand Down
36 changes: 17 additions & 19 deletions react/src/components/pages/InvestigationPage.tsx
Original file line number Diff line number Diff line change
@@ -1,37 +1,35 @@
import { useParams } from 'react-router'
import SideBar from '../SideBar.tsx'
import InvestigationGraph from '../graph/InvestigationGraph.tsx'
import Header from '../Header.tsx'
import { useInvestigationGraph } from '../../hooks/useInvestigationGraph.tsx'
import { useParams } from "react-router";
import SideBar from "../SideBar.tsx";
import InvestigationGraph from "../graph/InvestigationGraph.tsx";
import Header from "../Header.tsx";
import { useInvestigationGraph } from "../../hooks/useInvestigationGraph.tsx";

interface Props {
name: string
created_at: string
name: string;
created_at: string;
}

type InvestigationParams = {
investigationId: string
}
investigationId: string;
};

function InvestigationPage() {
const { investigationId } = useParams<InvestigationParams>()
const { error, data, loading } = useInvestigationGraph(investigationId)

if (loading) return <div>loading....</div>
if (error) return <div>uh oh error...</div>
const { investigationId } = useParams<InvestigationParams>();
const { error, data, loading } = useInvestigationGraph(investigationId);

console.log(data)
if (loading) return <div>loading....</div>;
if (error) return <div>uh oh error...</div>;

return (
<>
<Header />
<h1>Investigation: {data.investigation.name}</h1>
<div className="border-4 border-solid border-indigo-500">
<div className="flex flex-row">
<div className="basis-1/4">
<div className="basis-1/8">
<SideBar />
</div>
<div className="basis-3/4">
<div className="basis-7/8">
<InvestigationGraph
workNodes={data.investigation.workNodes}
authorNodes={data.investigation.authorNodes}
Expand All @@ -43,7 +41,7 @@ function InvestigationPage() {
</div>
</div>
</>
)
);
}

export default InvestigationPage
export default InvestigationPage;
11 changes: 11 additions & 0 deletions react/src/components/pages/SignInPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@ import { useMutation } from "@apollo/client";

import { SetStateAction, useState } from "react";
import { SIGN_IN } from "../../hooks/SIGN_IN";
import { useNavigate } from "react-router-dom";

function SignInPage() {
const [emailInput, setEmail] = useState("");
const [passwordInput, setPassword] = useState("");
const navigate = useNavigate();

let emailInputHandler = (e: {
target: { value: SetStateAction<string> };
Expand All @@ -20,10 +22,19 @@ function SignInPage() {
};

const [signIn] = useMutation(SIGN_IN, {
errorPolicy: "ignore", // TO-DO: fix this
variables: {
email: emailInput,
password: passwordInput,
},
onCompleted: (data) => {
localStorage.setItem("token", data.signIn.authenticationToken);
localStorage.setItem("email", "SIGNED IN");
navigate("/investigations");
},
onError: (error) => {
console.log(error);
},
});

if (localStorage.getItem("email")) {
Expand Down
7 changes: 2 additions & 5 deletions react/src/hooks/SIGN_IN.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,8 @@ import { gql } from "@apollo/client";
export const SIGN_IN = gql`
mutation ($email: String!, $password: String!) {
signIn(input: { email: $email, password: $password }) {
user {
id
email
authenticationToken
}
authenticationToken
id
}
}
`;
2 changes: 1 addition & 1 deletion react/src/root.css
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#root {
max-width: 1280px;
/* max-width: 1280px; */
margin: 0 auto;
padding: 2rem;
text-align: center;
Expand Down
10 changes: 8 additions & 2 deletions react/src/root.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,15 @@
import './root.css'
import { Link } from "react-router-dom";
import "./root.css";

export default function Root() {
return (
<>
<h1>ey i'm a homepage</h1>
<Link to="/register"> Register </Link>
<br />
<Link to="/signin"> Sign In </Link>
<br />
<Link to="/investigations"> My investigations </Link>
</>
)
);
}
23 changes: 6 additions & 17 deletions react/src/signOutButton.tsx
Original file line number Diff line number Diff line change
@@ -1,25 +1,14 @@
import { useMutation, gql } from "@apollo/client";
import { useNavigate } from "react-router-dom";

const SIGN_OUT = gql`
mutation signOut {
signOut(input: {}) {
success
errors
}
}
`;

function SignOutButton() {
const navigate = useNavigate();
const [signOut] = useMutation(SIGN_OUT, {
errorPolicy: "ignore", // TO-DO: fix this
onCompleted: () => {
localStorage.setItem("token", "");
localStorage.setItem("email", "");
navigate("/");
},
});

function signOut() {
localStorage.setItem("token", "");
localStorage.setItem("email", "");
navigate("/");
}

return (
<button
Expand Down

0 comments on commit 16529d3

Please sign in to comment.