Skip to content

Commit

Permalink
Huge set of changes to updated deps, simplify some implemenations, an…
Browse files Browse the repository at this point in the history
…d fix bugs...
  • Loading branch information
jeffdc committed Mar 25, 2024
1 parent 58e85fc commit ed5e377
Show file tree
Hide file tree
Showing 8 changed files with 98 additions and 102 deletions.
28 changes: 12 additions & 16 deletions components/images.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import * as O from 'fp-ts/lib/Option';
import { constant, pipe } from 'fp-ts/lib/function';
import { useSession } from 'next-auth/react';
import Image from 'next/image.js';
import Link from 'next/link';
Expand Down Expand Up @@ -157,20 +155,18 @@ const Images = ({ sp }: Props): JSX.Element => {
<Row>
<Col>
<b>Source:</b>{' '}
{pipe(
currentImage ? currentImage.source : O.none,
O.fold(
constant(
<a href={currentImage?.sourcelink} target="_blank" rel="noreferrer">
{currentImage?.sourcelink}
</a>,
),
(s) => (
<Link href={`/source/${s.id}`} target="_blank" rel="noreferrer">
{s.title}
</Link>
),
),
{currentImage ? (
currentImage.source ? (
<Link href={`/source/${currentImage.source.id}`} target="_blank" rel="noreferrer">
{currentImage.source.title}
</Link>
) : (
<a href={currentImage.sourcelink} target="_blank" rel="noreferrer">
{currentImage.sourcelink}
</a>
)
) : (
<></>
)}
</Col>
</Row>
Expand Down
23 changes: 1 addition & 22 deletions libs/api/apitypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,6 @@ export enum TaxonCodeValues {
PLANT = 'plant',
}

// export const TaxonCodeSchema = fromEnum<TaxonCodeValues>('TaxonCodeValues', TaxonCodeValues);
/** Given a string value, look up the proper TaxonCode. If the value is not one of the valid values then an error will be thrown. */
export const taxonCodeAsStringToValue = (tc?: string | null): TaxonCodeValues => {
if (tc === TaxonCodeValues.GALL) {
Expand All @@ -160,12 +159,6 @@ export const taxonCodeAsStringToValue = (tc?: string | null): TaxonCodeValues =>
}
};

// export const SimpleSpeciesSchema = t.type({
// id: t.number,
// taxoncode: TaxonCodeSchema,
// name: t.string, //.matches(SPECIES_NAME_REGEX).required(),
// });
// export type SimpleSpecies = t.TypeOf<typeof SimpleSpeciesSchema>;
export type SimpleSpecies = {
id: number;
taxoncode: TaxonCodeValues;
Expand All @@ -174,20 +167,6 @@ export type SimpleSpecies = {

////////////////////////////////////////////////////////////////////
// Source Schemas and Types
// export const SourceApiSchema = t.type({
// id: t.number,
// title: t.string,
// author: t.string,
// pubyear: t.string,
// link: t.string,
// citation: t.string,
// datacomplete: t.boolean,
// license: t.string,
// licenselink: t.string,
// });

// export type SourceApi = t.TypeOf<typeof SourceApiSchema>;

export type SourceApi = {
id: number;
title: string;
Expand Down Expand Up @@ -342,7 +321,7 @@ export type ImageSource = {
licenselink: string;
sourcelink: string;
// source: Option<SourceWithSpeciesSourceApi>;
source: SourceWithSpeciesSourceApi | undefined;
source: SourceWithSpeciesSourceApi | null;
source_id: number | null;
};

Expand Down
4 changes: 2 additions & 2 deletions libs/db/images.ts
Original file line number Diff line number Diff line change
Expand Up @@ -134,14 +134,14 @@ export const updateImage = (theImage: ImageApi): TaskEither<Error, readonly Imag

export const adaptImage = <T extends ImageWithSource>(img: T): ImageApi => ({
...img,
source_id: img.source,
source_id: img.source ? img.source.id : null,
speciesid: img.species_id,
small: makePath(img.path, SMALL),
medium: makePath(img.path, MEDIUM),
large: makePath(img.path, LARGE),
xlarge: makePath(img.path, XLARGE),
original: makePath(img.path, ORIGINAL),
source: img.source ? img.source : undefined,
source: img.source ? img.source : null,
license: asImageLicense(img.license),
});

Expand Down
3 changes: 1 addition & 2 deletions libs/pages/admin.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import EditName, { RenameEvent } from '../../components/editname';
import { DeleteResult, TaxonCodeValues } from '../api/apitypes';
import { WithID } from '../utils/types';
import { pluralize } from '../utils/util';
import { DevTool } from '@hookform/devtools';

export type AdminTypes =
| 'Taxonomy'
Expand Down Expand Up @@ -188,7 +187,7 @@ const Admin = <T extends AdminType, V extends FieldValues>(props: AdminProps<T,

{props.form && (
<>
<DevTool control={props.form.control} placement="top-right" />
{/* <DevTool control={props.form.control} placement="top-right" /> */}
<ul>
<li>
<code>{`IsValid: ${props.form.formState.isValid} -- isDirty: ${props.form.formState.isDirty}`}</code>
Expand Down
75 changes: 46 additions & 29 deletions pages/_app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,40 +10,57 @@ import { ConfirmationServiceProvider } from '../hooks/useConfirmation';
import Footer from '../layouts/footer';
import Header from '../layouts/header';
import './style.scss';
import { StyleSheetManager } from 'styled-components';
import isPropValid from '@emotion/is-prop-valid';

// This implements the default behavior from styled-components v5
function shouldForwardProp(propName: string, target: unknown) {
if (typeof target === 'string') {
// For HTML elements, forward the prop if it is a valid HTML attribute
return isPropValid(propName);
}
// For other elements, forward all props
return true;
}

function Gallformers({ Component, pageProps }: AppProps): JSX.Element {
return (
<SessionProvider session={pageProps.session}>
<Container fluid className="p-0 m-0">
<Head>
{/* <script type="text/javascript"> */}
{/* Fix for Firefox autofocus CSS bug See:
<StyleSheetManager shouldForwardProp={shouldForwardProp}>
<SessionProvider session={pageProps.session}>
<Container fluid className="p-0 m-0">
<Head>
{/* <script type="text/javascript"> */}
{/* Fix for Firefox autofocus CSS bug See:
http://stackoverflow.com/questions/18943276/html-5-autofocus-messes-up-css-loading/18945951#18945951 */}
{/* </script> */}
{/* </script> */}

<title>Gallformers</title>
<link rel="icon" href="/favicon.ico" />
<meta name="description" content="The place to ID and learn about galls on plants in the US and Canada." />
</Head>
<Row>
<Col className="m-0 p-0">
<Header />
</Col>
</Row>
<Row>
<Col className="m-3 mb-5 p-2">
<ConfirmationServiceProvider>
<Component {...pageProps} />
</ConfirmationServiceProvider>
</Col>
</Row>
<Row>
<Col className="m-0 p-0">
<Footer />
</Col>
</Row>
</Container>
</SessionProvider>
<title>Gallformers</title>
<link rel="icon" href="/favicon.ico" />
<meta
name="description"
content="The place to ID and learn about galls on plants in the US and Canada."
/>
</Head>
<Row>
<Col className="m-0 p-0">
<Header />
</Col>
</Row>
<Row>
<Col className="m-3 mb-5 p-2">
<ConfirmationServiceProvider>
<Component {...pageProps} />
</ConfirmationServiceProvider>
</Col>
</Row>
<Row>
<Col className="m-0 p-0">
<Footer />
</Col>
</Row>
</Container>
</SessionProvider>
</StyleSheetManager>
);
}

Expand Down
60 changes: 29 additions & 31 deletions pages/admin/section.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { GetServerSideProps } from 'next';
import { ParsedUrlQuery } from 'querystring';
import { useCallback, useEffect, useState } from 'react';
import { Button, Col, Row } from 'react-bootstrap';
import { Path } from 'react-hook-form';
import { Controller, Path } from 'react-hook-form';
import { RenameEvent } from '../../components/editname';
import useAdmin, { AdminFormFields } from '../../hooks/useadmin';
import { extractQueryParam } from '../../libs/api/apipage';
Expand All @@ -22,18 +22,6 @@ import Admin from '../../libs/pages/admin';
import { extractGenus, hasProp, mightFailWithArray } from '../../libs/utils/util';
import { AsyncTypeahead } from 'react-bootstrap-typeahead';

// const schema = yup.object().shape({
// mainField: yup.array().required('A name is required.'),
// description: yup.string().required('A description is required.'),
// species: yup
// .array()
// .required('At least one species must be selected.')
// .of(SpeciesSchema)
// .test('same genus', 'You must select at least one species and all selected species must be of the same genus', (v) => {
// return new Set(v?.map((s) => (s.name ? extractGenus(s?.name) : undefined))).size === 1;
// }),
// });

type Props = {
id: string;
sections: TaxonomyEntry[];
Expand Down Expand Up @@ -210,28 +198,38 @@ const Section = ({ id, sections, genera }: Props): JSX.Element => {
<Row className="my-1">
<Col>
Species (required):
<AsyncTypeahead
id="species"
options={hosts}
labelKey="name"
placeholder="Mapped Species"
clearButton
multiple
{...adminForm.form.register('species', {
required: 'You must provide at least one species.',
disabled: !selected,
})}
onChange={(s) => {
setSpecies(s as SimpleSpecies[]);
adminForm.form.setValue('species' as Path<FormFields>, s as SimpleSpecies[]);
<Controller
control={adminForm.form.control}
name="species"
rules={{
validate: (s) => {
console.log(`JDC: ${JSON.stringify(s, null, ' ')}`);
return s.length > 0 ? true : 'At least one species is required.';
},
}}
selected={species ? species : []}
isLoading={isLoading}
onSearch={handleSearch}
// rules={ minLength: { value: 1, message: 'At least one species is required.' } }
render={() => (
<AsyncTypeahead
id="species"
options={hosts}
labelKey="name"
placeholder="Mapped Species"
clearButton
disabled={!selected}
multiple
onChange={(s) => {
setSpecies(s as SimpleSpecies[]);
adminForm.form.setValue('species' as Path<FormFields>, s as SimpleSpecies[]);
}}
selected={species ? species : []}
isLoading={isLoading}
onSearch={handleSearch}
/>
)}
/>
{adminForm.form.formState.errors.species &&
hasProp(adminForm.form.formState.errors.species, 'message') && (
<span className="text-danger">{adminForm.form.formState.errors.species.message as string}</span>
<span className="text-danger">{adminForm.form.formState.errors.species.message}</span>
)}
<p>
The species that you add should all be from the same genus. If they are not then you will not be able
Expand Down
7 changes: 7 additions & 0 deletions pages/id.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,7 @@ const IDGall = (props: Props): JSX.Element => {
// this is the search form on species or genus
const {
formState: { errors },
control: taxonControl,
} = useForm<SearchFormFields>({
mode: 'onBlur',
// resolver: yupResolver(Schema),
Expand Down Expand Up @@ -346,6 +347,7 @@ const IDGall = (props: Props): JSX.Element => {
<Form.Label>Host:</Form.Label>
<Controller
name="host"
control={taxonControl}
render={() => (
<Typeahead
id="host"
Expand Down Expand Up @@ -406,6 +408,7 @@ const IDGall = (props: Props): JSX.Element => {
<Form.Label>Genus / Section:</Form.Label>
<Controller
name="genus"
control={taxonControl}
render={() => (
<Typeahead
id="genus"
Expand Down Expand Up @@ -510,6 +513,7 @@ const IDGall = (props: Props): JSX.Element => {
</Form.Label>
<Controller
name="locations"
control={filterControl}
render={() => (
<Typeahead
id="locations"
Expand Down Expand Up @@ -560,6 +564,7 @@ const IDGall = (props: Props): JSX.Element => {
</Form.Label>
<Controller
name="detachable"
control={filterControl}
render={() => (
<Typeahead
id="detachable"
Expand Down Expand Up @@ -602,6 +607,7 @@ const IDGall = (props: Props): JSX.Element => {
</Form.Label>
<Controller
name="place"
control={filterControl}
render={() => (
<Typeahead
id="place"
Expand Down Expand Up @@ -642,6 +648,7 @@ const IDGall = (props: Props): JSX.Element => {
</Form.Label>
<Controller
name="family"
control={filterControl}
render={() => (
<Typeahead
id="family"
Expand Down
Binary file modified prisma/gallformers.sqlite
Binary file not shown.

0 comments on commit ed5e377

Please sign in to comment.