Skip to content

Commit

Permalink
Trim names/aliases/descriptions (#288)
Browse files Browse the repository at this point in the history
  • Loading branch information
peolic authored Feb 6, 2022
1 parent 141e582 commit 5184039
Show file tree
Hide file tree
Showing 9 changed files with 29 additions and 23 deletions.
16 changes: 8 additions & 8 deletions frontend/src/pages/performers/performerForm/PerformerForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -177,8 +177,8 @@ const PerformerForm: FC<PerformerProps> = ({

const changedName =
!!performer.id &&
fieldData.name !== undefined &&
performer.name !== fieldData.name;
newChanges.name !== null &&
performer.name.trim() !== newChanges.name;

useEffect(() => {
setUpdateAliases(changedName);
Expand All @@ -189,7 +189,7 @@ const PerformerForm: FC<PerformerProps> = ({
fieldData.gender !== GenderEnum.TRANSGENDER_MALE;
// Update breast type based on gender
useEffect(() => {
if (!showBreastType) setValue("boobJob", BreastTypeEnum.NA);
if (!showBreastType) setValue("breastType", BreastTypeEnum.NA);
}, [showBreastType, setValue]);

const enumOptions = (enums: OptionEnum[]) =>
Expand Down Expand Up @@ -218,7 +218,7 @@ const PerformerForm: FC<PerformerProps> = ({
piercings: data.piercings ?? [],
tattoos: data.tattoos ?? [],
breast_type:
BreastTypeEnum[data.boobJob as keyof typeof BreastTypeEnum] || null,
BreastTypeEnum[data.breastType as keyof typeof BreastTypeEnum] || null,
image_ids: data.images.map((i) => i.id),
urls: data.urls.map((u) => ({
url: u.url,
Expand Down Expand Up @@ -438,21 +438,21 @@ const PerformerForm: FC<PerformerProps> = ({

{fieldData.gender !== "MALE" &&
fieldData.gender !== "TRANSGENDER_MALE" && (
<Form.Group controlId="boobJob" className="col-6 mb-3">
<Form.Group controlId="breastType" className="col-6 mb-3">
<Form.Label>Breast type</Form.Label>
<Form.Select
className={cx({ "is-invalid": errors.boobJob })}
className={cx({ "is-invalid": errors.breastType })}
defaultValue={
performer.breast_type
? getEnumValue(BREAST, performer.breast_type)
: ""
}
{...register("boobJob")}
{...register("breastType")}
>
{enumOptions(BREAST)}
</Form.Select>
<Form.Control.Feedback type="invalid">
{errors?.boobJob?.message}
{errors?.breastType?.message}
</Form.Control.Feedback>
</Form.Group>
)}
Expand Down
4 changes: 2 additions & 2 deletions frontend/src/pages/performers/performerForm/diff.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ const selectPerformerDetails = (
cup_size: diffValue(original.measurements.cup_size, newCupSize),
waist_size: diffValue(original.measurements.waist, data.waistSize),
hip_size: diffValue(original.measurements.hip, data.hipSize),
breast_type: diffValue(original.breast_type, breastType(data.boobJob)),
breast_type: diffValue(original.breast_type, breastType(data.breastType)),
country: diffValue(original.country, data.country),
ethnicity: diffValue(original.ethnicity, ethnicityEnum(data.ethnicity)),
eye_color: diffValue(original.eye_color, data.eye_color),
Expand Down Expand Up @@ -116,7 +116,7 @@ const selectPerformerDetails = (
cup_size: diffValue(newCupSize, original.measurements.cup_size),
waist_size: diffValue(data.waistSize, original.measurements.waist),
hip_size: diffValue(data.hipSize, original.measurements.hip),
breast_type: diffValue(breastType(data.boobJob), original.breast_type),
breast_type: diffValue(breastType(data.breastType), original.breast_type),
country: diffValue(data.country, original.country),
ethnicity: diffValue(ethnicityEnum(data.ethnicity), original.ethnicity),
eye_color: diffValue(data.eye_color, original.eye_color),
Expand Down
4 changes: 2 additions & 2 deletions frontend/src/pages/performers/performerForm/schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ const zeroCheck = (input: number | null) =>

export const PerformerSchema = yup.object({
id: yup.string(),
name: yup.string().required("Name is required"),
name: yup.string().trim().required("Name is required"),
gender: yup
.string()
.transform(nullCheck)
Expand Down Expand Up @@ -64,7 +64,7 @@ export const PerformerSchema = yup.object({
.max(50, "Invalid waist size")
.nullable(),
hipSize: yup.number().transform(zeroCheck).nullable(),
boobJob: yup
breastType: yup
.string()
.transform(nullCheck)
.nullable()
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/pages/scenes/sceneForm/schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ const nullCheck = (input: string | null) =>
input === "" || input === "null" ? null : input;

export const SceneSchema = yup.object({
title: yup.string().required("Title is required"),
title: yup.string().trim().required("Title is required"),
details: yup.string().trim(),
date: yup
.string()
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/pages/studios/studioForm/schema.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import * as yup from "yup";

export const StudioSchema = yup.object({
name: yup.string().required("Name is required"),
name: yup.string().trim().required("Name is required"),
urls: yup
.array()
.of(
Expand Down
6 changes: 3 additions & 3 deletions frontend/src/pages/tags/tagForm/TagForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ import { createHref, tagHref } from "src/utils";
import { ROUTE_TAGS } from "src/constants/route";

const schema = yup.object({
name: yup.string().required("Name is required"),
description: yup.string(),
aliases: yup.array().of(yup.string().required()),
name: yup.string().trim().required("Name is required"),
description: yup.string().trim(),
aliases: yup.array().of(yup.string().trim().required()),
categoryId: yup.string().nullable().defined(),
note: yup.string().required("Edit note is required"),
});
Expand Down
7 changes: 3 additions & 4 deletions frontend/src/utils/transforms.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,9 @@ export const formatMeasurements = (val?: Measurements): string | undefined => {
};

export const getBraSize = (measurements: Measurements): string | undefined =>
(measurements.cup_size &&
measurements.cup_size &&
`${measurements.band_size}${measurements.cup_size}`) ??
undefined;
measurements.band_size && measurements.cup_size
? `${measurements.band_size}${measurements.cup_size}`
: undefined;

export const sortImageURLs = (
urls: ImageFragment[],
Expand Down
9 changes: 8 additions & 1 deletion pkg/models/model_edit.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package models
import (
"bytes"
"encoding/json"
"strings"
"time"

"github.com/gofrs/uuid"
Expand Down Expand Up @@ -168,7 +169,13 @@ func (e *Edit) IsDestructive() bool {
// When renaming a performer and not updating the performance aliases
if (e.Operation == OperationEnumModify.String() || e.Operation == OperationEnumMerge.String()) && e.TargetType == TargetTypeEnumPerformer.String() {
data, _ := e.GetPerformerData()
return data.New.Name != nil && !data.SetModifyAliases
if data.New.Name != nil {
oldName := ""
if data.Old.Name != nil {
oldName = strings.TrimSpace(*data.Old.Name)
}
return oldName != *data.New.Name && !data.SetModifyAliases
}
}
return false
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/sqlx/querybuilder_performer.go
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,7 @@ func (qb *performerQueryBuilder) buildQuery(performerFilter *models.PerformerFil
handleStringCriterion("eye_color", performerFilter.EyeColor, &query)
handleStringCriterion("height", performerFilter.Height, &query)
handleStringCriterion("measurements", performerFilter.Measurements, &query)
handleStringCriterion("fake_tits", performerFilter.FakeTits, &query)
handleStringCriterion("breast_type", performerFilter.BreastType, &query)
handleStringCriterion("career_length", performerFilter.CareerLength, &query)
handleStringCriterion("tattoos", performerFilter.Tattoos, &query)
handleStringCriterion("piercings", performerFilter.Piercings, &query)
Expand Down

0 comments on commit 5184039

Please sign in to comment.