Skip to content

Commit

Permalink
🎨 Fix up code
Browse files Browse the repository at this point in the history
  • Loading branch information
MathiasGruber committed Feb 21, 2025
1 parent 7e8db24 commit 91b57cf
Show file tree
Hide file tree
Showing 7 changed files with 43 additions and 41 deletions.
1 change: 1 addition & 0 deletions app/drizzle/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,7 @@ export const JutsuTypes = [
"EVENT",
"AI",
] as const;
export type JutsuType = (typeof JutsuTypes)[number];

export const UserStatNames = [
"ninjutsuOffence",
Expand Down
50 changes: 23 additions & 27 deletions app/src/app/jutsus/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,6 @@ import { MAX_EXTRA_JUTSU_SLOTS } from "@/drizzle/constants";
import { JUTSU_TRANSFER_COST } from "@/drizzle/constants";
import { JUTSU_TRANSFER_MAX_LEVEL } from "@/drizzle/constants";
import { JUTSU_TRANSFER_DAYS } from "@/drizzle/constants";
import {
JUTSU_TRANSFER_FREE_GOLD,
JUTSU_TRANSFER_FREE_SILVER,
JUTSU_TRANSFER_FREE_NORMAL,
JUTSU_TRANSFER_FREE_AMOUNT,
} from "@/drizzle/constants";
import { getFreeTransfers } from "@/libs/jutsu";
import JutsuFiltering, { useFiltering, getFilter } from "@/layout/JutsuFiltering";
import type { Jutsu, UserJutsu } from "@/drizzle/schema";
Expand Down Expand Up @@ -373,33 +367,16 @@ export default function MyJutsu() {
proceed_label={
transferTarget ? "Confirm Transfer" : "Select Target"
}
onClose={() => {
setTransferTarget(undefined);
}}
onAccept={(e) => {
e.preventDefault();
if (transferTarget) {
transferLevel({
fromJutsuId: userjutsu.jutsuId,
toJutsuId: transferTarget.jutsuId,
});
} else {
setIsOpen(false);
const filteredJutsus = allJutsu?.filter(
(j) =>
j.jutsuId !== userjutsu.jutsuId &&
j.jutsuType === userjutsu.jutsuType &&
j.jutsuRank === userjutsu.jutsuRank,
);
if (filteredJutsus?.length) {
setTransferTarget(undefined);
setUserJutsu(userjutsu);
const targetJutsu = filteredJutsus[0];
setTransferTarget(targetJutsu);
setIsOpen(true);
} else {
showMutationToast({
success: false,
message: "No compatible jutsu found for transfer",
});
}
}
}}
>
Expand All @@ -421,7 +398,26 @@ export default function MyJutsu() {
</p>
</>
) : (
<p>Select a jutsu to transfer the level to.</p>
<div className="flex flex-col gap-2">
<p>Select a jutsu to transfer the level to.</p>
<ActionSelector
items={allJutsu?.filter(
(jutsu) =>
jutsu.jutsuType === userjutsu.jutsuType &&
jutsu.jutsuRank === userjutsu.jutsuRank &&
jutsu.id !== userjutsu.id,
)}
counts={userJutsuCounts}
labelSingles={true}
showBgColor={false}
showLabels={true}
onClick={(id) => {
setTransferTarget(
allJutsu?.find((jutsu) => jutsu.id === id),
);
}}
/>
</div>
)}
</Confirm>
)}
Expand Down
2 changes: 2 additions & 0 deletions app/src/layout/Confirm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ interface ConfirmProps {
| React.MouseEvent<HTMLButtonElement, MouseEvent>
| React.KeyboardEvent<KeyboardEvent>,
) => void;
onClose?: () => void;
}

const Confirm: React.FC<ConfirmProps> = (props) => {
Expand All @@ -29,6 +30,7 @@ const Confirm: React.FC<ConfirmProps> = (props) => {
onAccept={props.onAccept}
className={props.className}
isValid={props.isValid}
onClose={props.onClose}
>
{props.children}
</Modal>
Expand Down
22 changes: 11 additions & 11 deletions app/src/layout/JutsuFiltering.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ import type {
ElementName,
UserRank,
StatType,
JutsuType,
AttackMethod,
AttackTarget,
} from "@/drizzle/constants";
Expand Down Expand Up @@ -197,7 +198,7 @@ export const useFiltering = () => {
const [classification, setClassification] = useState<StatType | None>("None");
const [effect, setEffect] = useState<string[]>([]);
const [element, setElement] = useState<string[]>([]);
const [jutsuType, setJutsuType] = useState<string>("None");
const [jutsuType, setJutsuType] = useState<JutsuType[]>([]);
const [method, setMethod] = useState<AttackMethod | None>("None");
const [name, setName] = useState<string>("");
const [rank, setRank] = useState<UserRank>("NONE");
Expand Down Expand Up @@ -652,15 +653,14 @@ const JutsuFiltering: React.FC<JutsuFilteringProps> = (props) => {
/>

{/* Jutsu Type */}
<FilterSelect
label="Jutsu Type"
value={jutsuType}
onValueChange={setJutsuType}
options={JutsuTypes.map((type) => ({
value: type,
label: type,
}))}
/>
<div>
<Label>Jutsu Type</Label>
<MultiSelect
selected={jutsuType}
options={JutsuTypes.map((type) => ({ value: type, label: type }))}
onChange={(e) => setJutsuType(e as JutsuType[])}
/>
</div>

{/* Target */}
<FilterSelect
Expand Down Expand Up @@ -870,7 +870,7 @@ export const getFilter = (state: JutsuFilteringState) => {
disappear: state.removeAnim === "None" ? undefined : state.removeAnim,
effect: processArray(state.effect as EffectType[]),
element: processArray(state.element as ElementName[]),
jutsuType: state.jutsuType === "None" ? undefined : state.jutsuType,
jutsuType: processArray(state.jutsuType),
method: state.method === "None" ? undefined : state.method,
name: state.name || undefined,
rank: state.rank === "NONE" ? undefined : state.rank,
Expand Down
3 changes: 3 additions & 0 deletions app/src/layout/Modal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ interface ModalProps {
| React.MouseEvent<HTMLButtonElement, MouseEvent>
| React.KeyboardEvent<KeyboardEvent>,
) => void;
onClose?: () => void;
}

const Modal: React.FC<ModalProps> = (props) => {
Expand Down Expand Up @@ -62,6 +63,7 @@ const Modal: React.FC<ModalProps> = (props) => {
onClick={(e) => {
e.preventDefault();
e.stopPropagation();
if (props.onClose) props.onClose();
props.setIsOpen(false);
}}
>
Expand Down Expand Up @@ -92,6 +94,7 @@ const Modal: React.FC<ModalProps> = (props) => {
onClick={(e) => {
e.preventDefault();
e.stopPropagation();
if (props.onClose) props.onClose();
props.setIsOpen(false);
}}
className="z-30 rounded-lg border border-gray-500 bg-gray-700 text-sm font-medium text-gray-300 hover:bg-gray-600 hover:text-white"
Expand Down
4 changes: 2 additions & 2 deletions app/src/server/api/routers/jutsu.ts
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ export const jutsuRouter = createTRPCRouter({
.where(eq(userJutsu.id, toUserJutsu.id)),
ctx.drizzle
.update(userJutsu)
.set({ level: toUserJutsu.level })
.set({ level: 1 })
.where(eq(userJutsu.id, fromUserJutsu.id)),
ctx.drizzle.insert(actionLog).values({
id: nanoid(),
Expand Down Expand Up @@ -826,7 +826,7 @@ export const jutsuDatabaseFilter = (input?: JutsuFilteringSchema) => {
// -----------------------------
...(input?.name ? [like(jutsu.name, `%${input.name}%`)] : []),
...(input?.bloodline ? [eq(jutsu.bloodlineId, input.bloodline)] : []),
...(input?.jutsuType ? [eq(jutsu.jutsuType, input.jutsuType)] : []),
...(input?.jutsuType ? [inArray(jutsu.jutsuType, input.jutsuType)] : []),
...(input?.requiredLevel ? [gte(jutsu.requiredLevel, input.requiredLevel)] : []),
...(input?.rank ? [eq(jutsu.requiredRank, input.rank)] : []),
...(input?.rarity ? [eq(jutsu.jutsuRank, input.rarity)] : []),
Expand Down
2 changes: 1 addition & 1 deletion app/src/validators/jutsu.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export const jutsuFilteringSchema = z.object({
disappear: z.string().optional(),
effect: z.array(z.string()).optional(),
element: z.array(z.string()).optional(),
jutsuType: z.enum(JutsuTypes).optional(),
jutsuType: z.array(z.enum(JutsuTypes)).optional(),
method: z.enum(AttackMethods).optional(),
name: z.string().min(0).max(256).optional(),
rank: z.enum(UserRanks).optional(),
Expand Down

0 comments on commit 91b57cf

Please sign in to comment.