Skip to content

Commit

Permalink
Extract updateAuthentication function
Browse files Browse the repository at this point in the history
  • Loading branch information
Elscrux committed Jan 23, 2024
1 parent 4b5b6b5 commit 48bbcba
Showing 1 changed file with 16 additions and 14 deletions.
30 changes: 16 additions & 14 deletions src/components/solvers/SolverPicker.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@ import {
Textarea,
Tooltip,
} from "@chakra-ui/react";
import React, { ChangeEvent, useEffect, useState } from "react";
import { ChangeEvent, useEffect, useState } from "react";
import { AuthenticationOptions } from "../../api/data-model/AuthenticationOptions";
import { fetchSolvers, fetchSubRoutines } from "../../api/ToolboxAPI";
import { SubRoutineDefinition } from "../../api/data-model/SubRoutineDefinition";
import { ProblemSolver } from "../../api/data-model/ProblemSolver";
import { SolverChoice } from "../../api/data-model/SolveRequest";
import { SubRoutineDefinition } from "../../api/data-model/SubRoutineDefinition";
import { fetchSolvers, fetchSubRoutines } from "../../api/ToolboxAPI";
import TextWithLinks from "../TextWithLink";
import { SettingsView } from "./SettingsView";

Expand Down Expand Up @@ -75,22 +75,24 @@ export const SolverPicker = (props: SolverPickerProps) => {
}

const Authentication = (authenticationOptions: AuthenticationOptions) => {
function updateAuthentication(token: string) {
let newSolverChoice: SolverChoice = {
...solverChoice,
authentication: {
token: token,
},
};

setSolverChoice(newSolverChoice);
props.setSolverChoice?.(newSolverChoice);
}

return (
<Container>
<Text>This solver requires authentication</Text>
{authenticationOptions.supportsToken ? (
<Textarea
onChange={(e) => {
let newSolverChoice: SolverChoice = {
...solverChoice,
authentication: {
token: e.target.value,
},
};

setSolverChoice(newSolverChoice);
props.setSolverChoice?.(newSolverChoice);
}}
onChange={(e) => updateAuthentication(e.target.value)}
placeholder={`Enter your token for ${authenticationOptions.authenticationAgent} here`}
/>
) : null}
Expand Down

0 comments on commit 48bbcba

Please sign in to comment.