Skip to content

Commit

Permalink
Replace ApiAutocomplete with ApiAutoCompleteV2 (#382)
Browse files Browse the repository at this point in the history
* Convert MainSearchBox to ApiAutoCompleteV2
* Convert WritTitleAutocomplete to ApiAutoCompleteV2
* Convert PersorgNameAutocomplete to ApiAutoCompleteV2

---------

Signed-off-by: Carl Gieringer <78054+carlgieringer@users.noreply.github.com>
  • Loading branch information
carlgieringer authored Apr 17, 2023
1 parent e11d9b1 commit b0fcb5b
Show file tree
Hide file tree
Showing 22 changed files with 197 additions and 785 deletions.
27 changes: 26 additions & 1 deletion howdju-client-common/lib/models.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import merge from "lodash/merge";
import { SetOptional } from "type-fest";
import { cloneDeep } from "lodash";
import { cloneDeep, pick } from "lodash";

import {
JustificationPolarity,
Expand All @@ -17,6 +17,10 @@ import {
JustificationRef,
JustificationOut,
negateRootPolarity,
CreatePersorgInput,
PropositionOut,
UpdatePropositionInput,
PersorgOut,
} from "howdju-common";

export function isPropositionRootTarget(
Expand Down Expand Up @@ -106,3 +110,24 @@ export const makeCreateContentReportInput = (
},
fields
);

/** Remove the fields that are circular, unserializable, or not part of the API update model. */
export function toUpdatePropositionInput(
proposition: PropositionOut
): UpdatePropositionInput {
return {
id: proposition.id,
text: proposition.text,
};
}

export function toCreatePersorgInput(persorg: PersorgOut): CreatePersorgInput {
return pick(persorg, [
"name",
"isOrganization",
"knownFor",
"websiteUrl",
"wikipediaUrl",
"twitterUrl",
]);
}
3 changes: 3 additions & 0 deletions howdju-common/lib/apiModels.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import {
Entity,
JustificationRef,
JustificationVote,
Persorg,
PicRegion,
Proposition,
PropositionCompound,
Expand Down Expand Up @@ -128,3 +129,5 @@ export interface SortDescription {
/** For continuations, the sort should filter out this value and any before it according to `direction`. */
value?: string;
}

export type PersorgOut = Persorg;
8 changes: 4 additions & 4 deletions howdju-common/lib/zodSchemas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -229,13 +229,13 @@ export const CreateStatement: z.ZodType<CreateStatement> = z.lazy(() =>
z.discriminatedUnion("sentenceType", [
Entity.extend({
sentenceType: z.literal(sentenceTypes.Enum.PROPOSITION),
sentence: Proposition,
speaker: Persorg,
sentence: CreateProposition,
speaker: CreatePersorg,
}).strict(),
Entity.extend({
sentenceType: z.literal(sentenceTypes.Enum.STATEMENT),
sentence: Statement,
speaker: Persorg,
sentence: CreateStatement,
speaker: CreatePersorg,
}).strict(),
])
);
Expand Down
4 changes: 4 additions & 0 deletions premiser-ui/src/ApiAutoComplete.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
.rmd-floating-label {
// TODO(17) figure out the source of this (.md-text--secondary?)
color: rgba(0, 0, 0, 0.54);
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import React, {
} from "react";
import { PayloadAction } from "@reduxjs/toolkit";
import { AutoComplete, AutoCompleteResult } from "@react-md/autocomplete";
import { FormMessage } from "@react-md/form";
import { useDebouncedCallback } from "use-debounce";
import { denormalize, Schema } from "normalizr";

Expand All @@ -20,7 +21,8 @@ import {
} from "./types";
import { useAppDispatch, useAppSelector } from "./hooks";
import { autocompletes } from "./actions";
import { FormMessage } from "@react-md/form";

import "./ApiAutoComplete.scss";

export type FetchSuggestionsActionCreator = (
value: string,
Expand Down Expand Up @@ -56,7 +58,7 @@ export interface Props<T>
onAutoComplete?: (suggestion: T) => void;
}

export default function ApiAutocompleteV2({
export default function ApiAutoComplete({
id,
name,
autocompleteThrottleMs = 250,
Expand Down Expand Up @@ -144,6 +146,7 @@ export default function ApiAutocompleteV2({
disableShowOnFocus
style={{ flexGrow: 1 }}
theme="underline"
filter="none"
/>
{rightControls}
</div>
Expand Down
133 changes: 0 additions & 133 deletions premiser-ui/src/ApiAutocomplete.test.tsx

This file was deleted.

Loading

0 comments on commit b0fcb5b

Please sign in to comment.