Merge 0b1516e930 into 44be36b501
|
|
@ -0,0 +1,9 @@
|
||||||
|
-- CreateEnum
|
||||||
|
CREATE TYPE "public"."MiiPlatform" AS ENUM ('SWITCH', 'THREE_DS');
|
||||||
|
|
||||||
|
-- AlterTable
|
||||||
|
ALTER TABLE "public"."miis" ADD COLUMN "platform" "public"."MiiPlatform" NOT NULL DEFAULT 'THREE_DS',
|
||||||
|
ALTER COLUMN "firstName" DROP NOT NULL,
|
||||||
|
ALTER COLUMN "lastName" DROP NOT NULL,
|
||||||
|
ALTER COLUMN "islandName" DROP NOT NULL,
|
||||||
|
ALTER COLUMN "allowedCopying" DROP NOT NULL;
|
||||||
|
|
@ -69,17 +69,19 @@ model Session {
|
||||||
}
|
}
|
||||||
|
|
||||||
model Mii {
|
model Mii {
|
||||||
id Int @id @default(autoincrement())
|
id Int @id @default(autoincrement())
|
||||||
userId Int
|
userId Int
|
||||||
name String @db.VarChar(64)
|
|
||||||
imageCount Int @default(0)
|
|
||||||
tags String[]
|
|
||||||
description String? @db.VarChar(256)
|
|
||||||
|
|
||||||
firstName String
|
name String @db.VarChar(64)
|
||||||
lastName String
|
imageCount Int @default(0)
|
||||||
|
tags String[]
|
||||||
|
description String? @db.VarChar(256)
|
||||||
|
platform MiiPlatform @default(THREE_DS)
|
||||||
|
|
||||||
|
firstName String?
|
||||||
|
lastName String?
|
||||||
gender MiiGender?
|
gender MiiGender?
|
||||||
islandName String
|
islandName String?
|
||||||
allowedCopying Boolean?
|
allowedCopying Boolean?
|
||||||
|
|
||||||
createdAt DateTime @default(now())
|
createdAt DateTime @default(now())
|
||||||
|
|
@ -154,6 +156,11 @@ model Punishment {
|
||||||
@@map("punishments")
|
@@map("punishments")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
enum MiiPlatform {
|
||||||
|
SWITCH
|
||||||
|
THREE_DS // can't start with a number
|
||||||
|
}
|
||||||
|
|
||||||
enum MiiGender {
|
enum MiiGender {
|
||||||
MALE
|
MALE
|
||||||
FEMALE
|
FEMALE
|
||||||
|
|
|
||||||
|
Before Width: | Height: | Size: 86 KiB |
|
Before Width: | Height: | Size: 106 KiB |
|
Before Width: | Height: | Size: 118 KiB |
|
Before Width: | Height: | Size: 228 KiB |
|
Before Width: | Height: | Size: 85 KiB |
|
Before Width: | Height: | Size: 76 KiB |
|
Before Width: | Height: | Size: 100 KiB |
|
Before Width: | Height: | Size: 83 KiB |
|
Before Width: | Height: | Size: 108 KiB |
|
Before Width: | Height: | Size: 81 KiB |
|
Before Width: | Height: | Size: 24 KiB |
|
Before Width: | Height: | Size: 86 KiB |
|
Before Width: | Height: | Size: 107 KiB |
|
Before Width: | Height: | Size: 74 KiB |
|
Before Width: | Height: | Size: 121 KiB |
|
Before Width: | Height: | Size: 139 KiB |
|
Before Width: | Height: | Size: 48 KiB |
|
Before Width: | Height: | Size: 192 KiB |
|
|
@ -139,7 +139,12 @@ export async function PATCH(request: NextRequest, { params }: { params: Promise<
|
||||||
}
|
}
|
||||||
} else if (description === undefined) {
|
} else if (description === undefined) {
|
||||||
// If images or description were not changed, regenerate the metadata image
|
// If images or description were not changed, regenerate the metadata image
|
||||||
await generateMetadataImage(updatedMii, updatedMii.user.name!);
|
try {
|
||||||
|
await generateMetadataImage(updatedMii, updatedMii.user.name!);
|
||||||
|
} catch (error) {
|
||||||
|
console.error(error);
|
||||||
|
return rateLimit.sendResponse({ error: `Failed to generate 'metadata' type image for mii ${miiId}` }, 500);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return rateLimit.sendResponse({ success: true });
|
return rateLimit.sendResponse({ success: true });
|
||||||
|
|
|
||||||
|
|
@ -8,7 +8,7 @@ import sharp from "sharp";
|
||||||
|
|
||||||
import qrcode from "qrcode-generator";
|
import qrcode from "qrcode-generator";
|
||||||
import { profanity } from "@2toad/profanity";
|
import { profanity } from "@2toad/profanity";
|
||||||
import { MiiGender } from "@prisma/client";
|
import { MiiGender, MiiPlatform } from "@prisma/client";
|
||||||
|
|
||||||
import { auth } from "@/lib/auth";
|
import { auth } from "@/lib/auth";
|
||||||
import { prisma } from "@/lib/prisma";
|
import { prisma } from "@/lib/prisma";
|
||||||
|
|
@ -22,32 +22,57 @@ import { TomodachiLifeMii } from "@/lib/tomodachi-life-mii";
|
||||||
|
|
||||||
const uploadsDirectory = path.join(process.cwd(), "uploads", "mii");
|
const uploadsDirectory = path.join(process.cwd(), "uploads", "mii");
|
||||||
|
|
||||||
const submitSchema = z.object({
|
const submitSchema = z
|
||||||
name: nameSchema,
|
.object({
|
||||||
tags: tagsSchema,
|
platform: z.enum(MiiPlatform).default("THREE_DS"),
|
||||||
description: z.string().trim().max(256).optional(),
|
name: nameSchema,
|
||||||
qrBytesRaw: z.array(z.number(), { error: "A QR code is required" }).length(372, {
|
tags: tagsSchema,
|
||||||
error: "QR code size is not a valid Tomodachi Life QR code",
|
description: z.string().trim().max(256).optional(),
|
||||||
}),
|
|
||||||
image1: z.union([z.instanceof(File), z.any()]).optional(),
|
// Switch
|
||||||
image2: z.union([z.instanceof(File), z.any()]).optional(),
|
gender: z.enum(MiiGender).default("MALE"),
|
||||||
image3: z.union([z.instanceof(File), z.any()]).optional(),
|
miiPortraitImage: z.union([z.instanceof(File), z.any()]).optional(),
|
||||||
});
|
|
||||||
|
// QR code
|
||||||
|
qrBytesRaw: z.array(z.number(), { error: "A QR code is required" }).length(372, {
|
||||||
|
error: "QR code size is not a valid Tomodachi Life QR code",
|
||||||
|
}),
|
||||||
|
|
||||||
|
// Custom images
|
||||||
|
image1: z.union([z.instanceof(File), z.any()]).optional(),
|
||||||
|
image2: z.union([z.instanceof(File), z.any()]).optional(),
|
||||||
|
image3: z.union([z.instanceof(File), z.any()]).optional(),
|
||||||
|
})
|
||||||
|
// This refine function is probably useless
|
||||||
|
.refine(
|
||||||
|
(data) => {
|
||||||
|
// If platform is Switch, gender and miiPortraitImage must be present
|
||||||
|
if (data.platform === "SWITCH") {
|
||||||
|
return data.gender !== undefined && data.miiPortraitImage !== undefined;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
},
|
||||||
|
{
|
||||||
|
message: "Gender and Mii portrait image are required for Switch platform",
|
||||||
|
path: ["gender", "miiPortraitImage"],
|
||||||
|
},
|
||||||
|
);
|
||||||
|
|
||||||
export async function POST(request: NextRequest) {
|
export async function POST(request: NextRequest) {
|
||||||
const session = await auth();
|
const session = await auth();
|
||||||
if (!session) return NextResponse.json({ error: "Unauthorized" }, { status: 401 });
|
if (!session) return NextResponse.json({ error: "Unauthorized" }, { status: 401 });
|
||||||
Sentry.setUser({ id: session.user.id, username: session.user.username });
|
Sentry.setUser({ id: session.user.id, username: session.user.username });
|
||||||
|
|
||||||
const rateLimit = new RateLimit(request, 2);
|
const rateLimit = new RateLimit(request, 3);
|
||||||
const check = await rateLimit.handle();
|
const check = await rateLimit.handle();
|
||||||
if (check) return check;
|
if (check) return check;
|
||||||
|
|
||||||
|
const response = await fetch(`${process.env.NEXT_PUBLIC_BASE_URL}/api/admin/can-submit`);
|
||||||
const response = await fetch(`${process.env.NEXT_PUBLIC_BASE_URL}/api/admin/can-submit`);
|
const response = await fetch(`${process.env.NEXT_PUBLIC_BASE_URL}/api/admin/can-submit`);
|
||||||
const { value } = await response.json();
|
const { value } = await response.json();
|
||||||
if (!value) return rateLimit.sendResponse({ error: "Submissions are disabled" }, 409);
|
if (!value) return rateLimit.sendResponse({ error: "Submissions are temporarily disabled" }, 503);
|
||||||
|
|
||||||
// Parse data
|
// Parse tags and QR code as JSON
|
||||||
const formData = await request.formData();
|
const formData = await request.formData();
|
||||||
|
|
||||||
let rawTags: string[];
|
let rawTags: string[];
|
||||||
|
|
@ -62,18 +87,36 @@ export async function POST(request: NextRequest) {
|
||||||
return rateLimit.sendResponse({ error: "Invalid JSON in tags or QR code data" }, 400);
|
return rateLimit.sendResponse({ error: "Invalid JSON in tags or QR code data" }, 400);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Parse and check all submission info
|
||||||
const parsed = submitSchema.safeParse({
|
const parsed = submitSchema.safeParse({
|
||||||
|
platform: formData.get("platform"),
|
||||||
name: formData.get("name"),
|
name: formData.get("name"),
|
||||||
tags: rawTags,
|
tags: rawTags,
|
||||||
description: formData.get("description"),
|
description: formData.get("description"),
|
||||||
|
|
||||||
|
gender: formData.get("gender") ?? undefined, // ZOD MOMENT
|
||||||
|
miiPortraitImage: formData.get("miiPortraitImage"),
|
||||||
|
|
||||||
qrBytesRaw: rawQrBytesRaw,
|
qrBytesRaw: rawQrBytesRaw,
|
||||||
|
|
||||||
image1: formData.get("image1"),
|
image1: formData.get("image1"),
|
||||||
image2: formData.get("image2"),
|
image2: formData.get("image2"),
|
||||||
image3: formData.get("image3"),
|
image3: formData.get("image3"),
|
||||||
});
|
});
|
||||||
|
|
||||||
if (!parsed.success) return rateLimit.sendResponse({ error: parsed.error.issues[0].message }, 400);
|
if (!parsed.success) return rateLimit.sendResponse({ error: parsed.error.issues[0].message }, 400);
|
||||||
const { name: uncensoredName, tags: uncensoredTags, description: uncensoredDescription, qrBytesRaw, image1, image2, image3 } = parsed.data;
|
const {
|
||||||
|
platform,
|
||||||
|
name: uncensoredName,
|
||||||
|
tags: uncensoredTags,
|
||||||
|
description: uncensoredDescription,
|
||||||
|
qrBytesRaw,
|
||||||
|
gender,
|
||||||
|
miiPortraitImage,
|
||||||
|
image1,
|
||||||
|
image2,
|
||||||
|
image3,
|
||||||
|
} = parsed.data;
|
||||||
|
|
||||||
// Censor potential inappropriate words
|
// Censor potential inappropriate words
|
||||||
const name = profanity.censor(uncensoredName);
|
const name = profanity.censor(uncensoredName);
|
||||||
|
|
@ -81,43 +124,57 @@ export async function POST(request: NextRequest) {
|
||||||
const description = uncensoredDescription && profanity.censor(uncensoredDescription);
|
const description = uncensoredDescription && profanity.censor(uncensoredDescription);
|
||||||
|
|
||||||
// Validate image files
|
// Validate image files
|
||||||
const images: File[] = [];
|
const customImages: File[] = [];
|
||||||
|
|
||||||
for (const img of [image1, image2, image3]) {
|
for (const img of [image1, image2, image3]) {
|
||||||
if (!img) continue;
|
if (!img) continue;
|
||||||
|
|
||||||
const imageValidation = await validateImage(img);
|
const imageValidation = await validateImage(img);
|
||||||
if (imageValidation.valid) {
|
if (imageValidation.valid) {
|
||||||
images.push(img);
|
customImages.push(img);
|
||||||
} else {
|
} else {
|
||||||
return rateLimit.sendResponse({ error: imageValidation.error }, imageValidation.status ?? 400);
|
return rateLimit.sendResponse({ error: imageValidation.error }, imageValidation.status ?? 400);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Check Mii portrait image as well (Switch)
|
||||||
|
if (platform === "SWITCH") {
|
||||||
|
const imageValidation = await validateImage(miiPortraitImage);
|
||||||
|
if (!imageValidation.valid) return rateLimit.sendResponse({ error: imageValidation.error }, imageValidation.status ?? 400);
|
||||||
|
}
|
||||||
|
|
||||||
const qrBytes = new Uint8Array(qrBytesRaw);
|
const qrBytes = new Uint8Array(qrBytesRaw);
|
||||||
|
|
||||||
// Convert QR code to JS
|
// Convert QR code to JS (3DS)
|
||||||
let conversion: { mii: Mii; tomodachiLifeMii: TomodachiLifeMii };
|
let conversion: { mii: Mii; tomodachiLifeMii: TomodachiLifeMii } | undefined;
|
||||||
try {
|
if (platform === "THREE_DS") {
|
||||||
conversion = convertQrCode(qrBytes);
|
try {
|
||||||
} catch (error) {
|
conversion = convertQrCode(qrBytes);
|
||||||
Sentry.captureException(error, { extra: { stage: "qr-conversion" } });
|
} catch (error) {
|
||||||
return rateLimit.sendResponse({ error: error instanceof Error ? error.message : String(error) }, 400);
|
Sentry.captureException(error, { extra: { stage: "qr-conversion" } });
|
||||||
|
return rateLimit.sendResponse({ error: error instanceof Error ? error.message : String(error) }, 400);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create Mii in database
|
// Create Mii in database
|
||||||
const miiRecord = await prisma.mii.create({
|
const miiRecord = await prisma.mii.create({
|
||||||
data: {
|
data: {
|
||||||
userId: Number(session.user.id),
|
userId: Number(session.user.id),
|
||||||
|
platform,
|
||||||
name,
|
name,
|
||||||
tags,
|
tags,
|
||||||
description,
|
description,
|
||||||
|
gender: gender ?? "MALE",
|
||||||
|
|
||||||
firstName: conversion.tomodachiLifeMii.firstName,
|
// Automatically detect certain information if on 3DS
|
||||||
lastName: conversion.tomodachiLifeMii.lastName,
|
...(platform === "THREE_DS" &&
|
||||||
gender: conversion.mii.gender == 0 ? MiiGender.MALE : MiiGender.FEMALE,
|
conversion && {
|
||||||
islandName: conversion.tomodachiLifeMii.islandName,
|
firstName: conversion.tomodachiLifeMii.firstName,
|
||||||
allowedCopying: conversion.mii.allowCopying,
|
lastName: conversion.tomodachiLifeMii.lastName,
|
||||||
|
gender: conversion.mii.gender == 0 ? MiiGender.MALE : MiiGender.FEMALE,
|
||||||
|
islandName: conversion.tomodachiLifeMii.islandName,
|
||||||
|
allowedCopying: conversion.mii.allowCopying,
|
||||||
|
}),
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
@ -125,34 +182,38 @@ export async function POST(request: NextRequest) {
|
||||||
const miiUploadsDirectory = path.join(uploadsDirectory, miiRecord.id.toString());
|
const miiUploadsDirectory = path.join(uploadsDirectory, miiRecord.id.toString());
|
||||||
await fs.mkdir(miiUploadsDirectory, { recursive: true });
|
await fs.mkdir(miiUploadsDirectory, { recursive: true });
|
||||||
|
|
||||||
// Download the image of the Mii
|
|
||||||
let studioBuffer: Buffer;
|
|
||||||
try {
|
try {
|
||||||
const studioUrl = conversion.mii.studioUrl({ width: 512 });
|
let portraitBuffer: Buffer | undefined;
|
||||||
const studioResponse = await fetch(studioUrl);
|
|
||||||
|
|
||||||
if (!studioResponse.ok) {
|
// Download the image of the Mii (3DS)
|
||||||
throw new Error(`Failed to fetch Mii image ${studioResponse.status}`);
|
if (platform === "THREE_DS") {
|
||||||
|
const studioUrl = conversion?.mii.studioUrl({ width: 512 });
|
||||||
|
const studioResponse = await fetch(studioUrl!);
|
||||||
|
|
||||||
|
if (!studioResponse.ok) {
|
||||||
|
throw new Error(`Failed to fetch Mii image ${studioResponse.status}`);
|
||||||
|
}
|
||||||
|
|
||||||
|
portraitBuffer = Buffer.from(await studioResponse.arrayBuffer());
|
||||||
|
} else if (platform === "SWITCH") {
|
||||||
|
portraitBuffer = Buffer.from(await miiPortraitImage.arrayBuffer());
|
||||||
}
|
}
|
||||||
|
|
||||||
const studioArrayBuffer = await studioResponse.arrayBuffer();
|
if (!portraitBuffer) throw Error("Mii portrait buffer not initialised");
|
||||||
studioBuffer = Buffer.from(studioArrayBuffer);
|
const webpBuffer = await sharp(portraitBuffer).webp({ quality: 85 }).toBuffer();
|
||||||
|
const fileLocation = path.join(miiUploadsDirectory, "mii.webp");
|
||||||
|
|
||||||
|
await fs.writeFile(fileLocation, webpBuffer);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
// Clean up if something went wrong
|
// Clean up if something went wrong
|
||||||
await prisma.mii.delete({ where: { id: miiRecord.id } });
|
await prisma.mii.delete({ where: { id: miiRecord.id } });
|
||||||
|
|
||||||
console.error("Failed to download Mii image:", error);
|
console.error("Failed to download/store Mii portrait:", error);
|
||||||
Sentry.captureException(error, { extra: { miiId: miiRecord.id, stage: "studio-image-download" } });
|
Sentry.captureException(error, { extra: { miiId: miiRecord.id, stage: "studio-image-download" } });
|
||||||
return rateLimit.sendResponse({ error: "Failed to download Mii image" }, 500);
|
return rateLimit.sendResponse({ error: "Failed to download/store Mii portrait" }, 500);
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
// Compress and store
|
|
||||||
const studioWebpBuffer = await sharp(studioBuffer).webp({ quality: 85 }).toBuffer();
|
|
||||||
const studioFileLocation = path.join(miiUploadsDirectory, "mii.webp");
|
|
||||||
|
|
||||||
await fs.writeFile(studioFileLocation, studioWebpBuffer);
|
|
||||||
|
|
||||||
// Generate a new QR code for aesthetic reasons
|
// Generate a new QR code for aesthetic reasons
|
||||||
const byteString = String.fromCharCode(...qrBytes);
|
const byteString = String.fromCharCode(...qrBytes);
|
||||||
const generatedCode = qrcode(0, "L");
|
const generatedCode = qrcode(0, "L");
|
||||||
|
|
@ -169,7 +230,6 @@ export async function POST(request: NextRequest) {
|
||||||
const codeFileLocation = path.join(miiUploadsDirectory, "qr-code.webp");
|
const codeFileLocation = path.join(miiUploadsDirectory, "qr-code.webp");
|
||||||
|
|
||||||
await fs.writeFile(codeFileLocation, codeWebpBuffer);
|
await fs.writeFile(codeFileLocation, codeWebpBuffer);
|
||||||
await generateMetadataImage(miiRecord, session.user.name!);
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
// Clean up if something went wrong
|
// Clean up if something went wrong
|
||||||
await prisma.mii.delete({ where: { id: miiRecord.id } });
|
await prisma.mii.delete({ where: { id: miiRecord.id } });
|
||||||
|
|
@ -182,7 +242,7 @@ export async function POST(request: NextRequest) {
|
||||||
// Compress and store user images
|
// Compress and store user images
|
||||||
try {
|
try {
|
||||||
await Promise.all(
|
await Promise.all(
|
||||||
images.map(async (image, index) => {
|
customImages.map(async (image, index) => {
|
||||||
const buffer = Buffer.from(await image.arrayBuffer());
|
const buffer = Buffer.from(await image.arrayBuffer());
|
||||||
const webpBuffer = await sharp(buffer).webp({ quality: 85 }).toBuffer();
|
const webpBuffer = await sharp(buffer).webp({ quality: 85 }).toBuffer();
|
||||||
const fileLocation = path.join(miiUploadsDirectory, `image${index}.webp`);
|
const fileLocation = path.join(miiUploadsDirectory, `image${index}.webp`);
|
||||||
|
|
@ -197,7 +257,7 @@ export async function POST(request: NextRequest) {
|
||||||
id: miiRecord.id,
|
id: miiRecord.id,
|
||||||
},
|
},
|
||||||
data: {
|
data: {
|
||||||
imageCount: images.length,
|
imageCount: customImages.length,
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
|
|
|
||||||
|
|
@ -91,6 +91,23 @@ body {
|
||||||
@apply opacity-100 scale-100;
|
@apply opacity-100 scale-100;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Fallback Tooltips */
|
||||||
|
[data-tooltip-span] {
|
||||||
|
@apply relative;
|
||||||
|
}
|
||||||
|
|
||||||
|
[data-tooltip-span] > .tooltip {
|
||||||
|
@apply absolute left-1/2 top-full mt-2 px-2 py-1 bg-orange-400 border border-orange-400 rounded-md text-sm text-white whitespace-nowrap select-none pointer-events-none shadow-md opacity-0 scale-75 transition-all duration-200 ease-out origin-top -translate-x-1/2 z-999999;
|
||||||
|
}
|
||||||
|
|
||||||
|
[data-tooltip-span] > .tooltip::before {
|
||||||
|
@apply content-[''] absolute left-1/2 -translate-x-1/2 -top-2 border-4 border-transparent border-b-orange-400;
|
||||||
|
}
|
||||||
|
|
||||||
|
[data-tooltip-span]:hover > .tooltip {
|
||||||
|
@apply opacity-100 scale-100;
|
||||||
|
}
|
||||||
|
|
||||||
/* Scrollbar */
|
/* Scrollbar */
|
||||||
/* Firefox */
|
/* Firefox */
|
||||||
* {
|
* {
|
||||||
|
|
|
||||||
|
|
@ -12,9 +12,10 @@ import LikeButton from "@/components/like-button";
|
||||||
import ImageViewer from "@/components/image-viewer";
|
import ImageViewer from "@/components/image-viewer";
|
||||||
import DeleteMiiButton from "@/components/delete-mii";
|
import DeleteMiiButton from "@/components/delete-mii";
|
||||||
import ShareMiiButton from "@/components/share-mii-button";
|
import ShareMiiButton from "@/components/share-mii-button";
|
||||||
import ScanTutorialButton from "@/components/tutorial/scan";
|
import ThreeDsScanTutorialButton from "@/components/tutorial/3ds-scan";
|
||||||
import ProfilePicture from "@/components/profile-picture";
|
import SwitchScanTutorialButton from "@/components/tutorial/switch-scan";
|
||||||
import Description from "@/components/description";
|
import Description from "@/components/description";
|
||||||
|
import { MiiPlatform } from "@prisma/client";
|
||||||
|
|
||||||
interface Props {
|
interface Props {
|
||||||
params: Promise<{ id: string }>;
|
params: Promise<{ id: string }>;
|
||||||
|
|
@ -30,6 +31,7 @@ export async function generateMetadata({ params }: Props): Promise<Metadata> {
|
||||||
include: {
|
include: {
|
||||||
user: {
|
user: {
|
||||||
select: {
|
select: {
|
||||||
|
name: true,
|
||||||
username: true,
|
username: true,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|
@ -44,28 +46,36 @@ export async function generateMetadata({ params }: Props): Promise<Metadata> {
|
||||||
|
|
||||||
const metadataImageUrl = `/mii/${mii.id}/image?type=metadata`;
|
const metadataImageUrl = `/mii/${mii.id}/image?type=metadata`;
|
||||||
|
|
||||||
const username = `@${mii.user.username}`;
|
|
||||||
|
|
||||||
return {
|
return {
|
||||||
metadataBase: new URL(process.env.NEXT_PUBLIC_BASE_URL!),
|
metadataBase: new URL(process.env.NEXT_PUBLIC_BASE_URL!),
|
||||||
title: `${mii.name} - TomodachiShare`,
|
title: `${mii.name} - TomodachiShare`,
|
||||||
description: `Check out '${mii.name}', a Tomodachi Life Mii created by ${username} on TomodachiShare. From ${mii.islandName} Island with ${mii._count.likedBy} likes.`,
|
description: `Check out '${mii.name}', a ${mii.platform === MiiPlatform.SWITCH ? "Switch Living the Dream" : "3DS"} Tomodachi Life Mii created by ${mii.user.name} on TomodachiShare with ${mii._count.likedBy} likes.`,
|
||||||
keywords: ["mii", "tomodachi life", "nintendo", "tomodachishare", "tomodachi-share", "mii creator", "mii collection", ...mii.tags],
|
keywords: ["mii", "tomodachi life", "nintendo", "tomodachishare", "tomodachi-share", "mii creator", "mii collection", ...mii.tags],
|
||||||
creator: username,
|
creator: mii.user.username,
|
||||||
openGraph: {
|
openGraph: {
|
||||||
type: "article",
|
type: "article",
|
||||||
title: `${mii.name} - TomodachiShare`,
|
title: `${mii.name} - TomodachiShare`,
|
||||||
description: `Check out '${mii.name}', a Tomodachi Life Mii created by ${username} on TomodachiShare. From ${mii.islandName} Island with ${mii._count.likedBy} likes.`,
|
description: `Check out '${mii.name}', a ${mii.platform === MiiPlatform.SWITCH ? "Switch Living the Dream" : "3DS"} Tomodachi Life Mii created by ${mii.user.name} on TomodachiShare with ${mii._count.likedBy} likes.`,
|
||||||
images: [{ url: metadataImageUrl, alt: `${mii.name}, ${mii.tags.join(", ")} ${mii.gender} Mii character` }],
|
images: [
|
||||||
|
{
|
||||||
|
url: metadataImageUrl,
|
||||||
|
alt: `${mii.name}, ${mii.tags.join(", ")} ${mii.gender} Mii character`,
|
||||||
|
},
|
||||||
|
],
|
||||||
publishedTime: mii.createdAt.toISOString(),
|
publishedTime: mii.createdAt.toISOString(),
|
||||||
authors: username,
|
authors: mii.user.username,
|
||||||
},
|
},
|
||||||
twitter: {
|
twitter: {
|
||||||
card: "summary_large_image",
|
card: "summary_large_image",
|
||||||
title: `${mii.name} - TomodachiShare`,
|
title: `${mii.name} - TomodachiShare`,
|
||||||
description: `Check out '${mii.name}', a Tomodachi Life Mii created by ${username} on TomodachiShare. From ${mii.islandName} Island with ${mii._count.likedBy} likes.`,
|
description: `Check out '${mii.name}', a ${mii.platform === MiiPlatform.SWITCH ? "Switch Living the Dream" : "3DS"} Tomodachi Life Mii created by ${mii.user.name} on TomodachiShare with ${mii._count.likedBy} likes.`,
|
||||||
images: [{ url: metadataImageUrl, alt: `${mii.name}, ${mii.tags.join(", ")} ${mii.gender} Mii character` }],
|
images: [
|
||||||
creator: username,
|
{
|
||||||
|
url: metadataImageUrl,
|
||||||
|
alt: `${mii.name}, ${mii.tags.join(", ")} ${mii.gender} Mii character`,
|
||||||
|
},
|
||||||
|
],
|
||||||
|
creator: mii.user.username!,
|
||||||
},
|
},
|
||||||
alternates: {
|
alternates: {
|
||||||
canonical: `/mii/${mii.id}`,
|
canonical: `/mii/${mii.id}`,
|
||||||
|
|
@ -116,8 +126,8 @@ export default async function MiiPage({ params }: Props) {
|
||||||
<ImageViewer
|
<ImageViewer
|
||||||
src={`/mii/${mii.id}/image?type=mii`}
|
src={`/mii/${mii.id}/image?type=mii`}
|
||||||
alt="mii headshot"
|
alt="mii headshot"
|
||||||
width={200}
|
width={250}
|
||||||
height={200}
|
height={250}
|
||||||
className="drop-shadow-lg hover:scale-105 transition-transform"
|
className="drop-shadow-lg hover:scale-105 transition-transform"
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
|
|
@ -134,25 +144,72 @@ export default async function MiiPage({ params }: Props) {
|
||||||
<hr className="w-full border-t-2 border-t-amber-400" />
|
<hr className="w-full border-t-2 border-t-amber-400" />
|
||||||
|
|
||||||
{/* Mii Info */}
|
{/* Mii Info */}
|
||||||
<ul className="text-sm w-full p-2 *:flex *:justify-between *:items-center *:my-1">
|
{mii.platform === "THREE_DS" && (
|
||||||
<li>
|
<ul className="text-sm w-full p-2 *:flex *:justify-between *:items-center *:my-1">
|
||||||
Name:{" "}
|
|
||||||
<span className="text-right font-medium">
|
|
||||||
{mii.firstName} {mii.lastName}
|
|
||||||
</span>
|
|
||||||
</li>
|
|
||||||
<li>
|
|
||||||
From: <span className="text-right font-medium">{mii.islandName} Island</span>
|
|
||||||
</li>
|
|
||||||
{mii.allowedCopying !== null && (
|
|
||||||
<li>
|
<li>
|
||||||
Allowed Copying: <input type="checkbox" checked={mii.allowedCopying} disabled className="checkbox cursor-auto!" />
|
Name:{" "}
|
||||||
|
<span className="text-right font-medium">
|
||||||
|
{mii.firstName} {mii.lastName}
|
||||||
|
</span>
|
||||||
</li>
|
</li>
|
||||||
)}
|
<li>
|
||||||
</ul>
|
From: <span className="text-right font-medium">{mii.islandName} Island</span>
|
||||||
|
</li>
|
||||||
|
<li>
|
||||||
|
Allowed Copying: <input type="checkbox" checked={mii.allowedCopying ?? false} disabled className="checkbox cursor-auto!" />
|
||||||
|
</li>
|
||||||
|
</ul>
|
||||||
|
)}
|
||||||
|
|
||||||
|
{/* Mii Platform */}
|
||||||
|
<div className={`flex items-center gap-4 text-zinc-500 text-sm font-medium mb-2 w-full ${mii.platform !== "THREE_DS" && "mt-2"}`}>
|
||||||
|
<hr className="grow border-zinc-300" />
|
||||||
|
<span>Platform</span>
|
||||||
|
<hr className="grow border-zinc-300" />
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div data-tooltip-span title={mii.platform} className="grid grid-cols-2 gap-2 mb-2">
|
||||||
|
<div
|
||||||
|
className={`tooltip mt-1! ${
|
||||||
|
mii.platform === "THREE_DS" ? "bg-sky-400! border-sky-400! before:border-b-sky-400!" : "bg-red-400! border-red-400! before:border-b-red-400!"
|
||||||
|
}`}
|
||||||
|
>
|
||||||
|
{mii.platform === "THREE_DS" ? "3DS" : "Switch"}
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div
|
||||||
|
className={`rounded-xl flex justify-center items-center size-16 text-4xl border-2 shadow-sm ${
|
||||||
|
mii.platform === "THREE_DS" ? "bg-sky-100 border-sky-400" : "bg-white border-gray-300"
|
||||||
|
}`}
|
||||||
|
>
|
||||||
|
<Icon icon="cib:nintendo-3ds" className="text-sky-500" />
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div
|
||||||
|
className={`rounded-xl flex justify-center items-center size-16 text-4xl border-2 shadow-sm ${
|
||||||
|
mii.platform === "SWITCH" ? "bg-red-100 border-red-400" : "bg-white border-gray-300"
|
||||||
|
}`}
|
||||||
|
>
|
||||||
|
<Icon icon="cib:nintendo-switch" className="text-red-400" />
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
{/* Mii Gender */}
|
{/* Mii Gender */}
|
||||||
<div className="grid grid-cols-2 gap-2">
|
<div className="flex items-center gap-4 text-zinc-500 text-sm font-medium mb-2 w-full">
|
||||||
|
<hr className="grow border-zinc-300" />
|
||||||
|
<span>Gender</span>
|
||||||
|
<hr className="grow border-zinc-300" />
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div data-tooltip-span title={mii.gender ?? "NULL"} className="grid grid-cols-2 gap-2">
|
||||||
|
<div
|
||||||
|
className={`tooltip mt-1! ${
|
||||||
|
mii.gender === "MALE" ? "bg-blue-400! border-blue-400! before:border-b-blue-400!" : "bg-pink-400! border-pink-400! before:border-b-pink-400!"
|
||||||
|
}`}
|
||||||
|
>
|
||||||
|
{mii.gender === "MALE" ? "Male" : "Female"}
|
||||||
|
</div>
|
||||||
|
|
||||||
<div
|
<div
|
||||||
className={`rounded-xl flex justify-center items-center size-16 text-5xl border-2 shadow-sm ${
|
className={`rounded-xl flex justify-center items-center size-16 text-5xl border-2 shadow-sm ${
|
||||||
mii.gender === "MALE" ? "bg-blue-100 border-blue-400" : "bg-white border-gray-300"
|
mii.gender === "MALE" ? "bg-blue-100 border-blue-400" : "bg-white border-gray-300"
|
||||||
|
|
@ -230,7 +287,7 @@ export default async function MiiPage({ params }: Props) {
|
||||||
<Icon icon="material-symbols:flag-rounded" />
|
<Icon icon="material-symbols:flag-rounded" />
|
||||||
<span>Report</span>
|
<span>Report</span>
|
||||||
</Link>
|
</Link>
|
||||||
<ScanTutorialButton />
|
{mii.platform === "THREE_DS" ? <ThreeDsScanTutorialButton /> : <SwitchScanTutorialButton />}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
||||||
|
|
@ -95,9 +95,7 @@ export default async function ExiledPage() {
|
||||||
<div key={mii.miiId} className="bg-orange-100 rounded-xl border-2 border-orange-400 flex">
|
<div key={mii.miiId} className="bg-orange-100 rounded-xl border-2 border-orange-400 flex">
|
||||||
<Image src={`/mii/${mii.miiId}/image?type=mii`} alt="mii image" width={96} height={96} />
|
<Image src={`/mii/${mii.miiId}/image?type=mii`} alt="mii image" width={96} height={96} />
|
||||||
<div className="p-4">
|
<div className="p-4">
|
||||||
<p className="text-xl font-bold line-clamp-1" title={"hello"}>
|
<p className="text-xl font-bold line-clamp-1">{mii.mii.name}</p>
|
||||||
{mii.mii.name}
|
|
||||||
</p>
|
|
||||||
<p className="text-sm">
|
<p className="text-sm">
|
||||||
<span className="font-bold">Reason:</span> {mii.reason}
|
<span className="font-bold">Reason:</span> {mii.reason}
|
||||||
</p>
|
</p>
|
||||||
|
|
|
||||||
|
|
@ -12,7 +12,7 @@ interface Props {
|
||||||
}
|
}
|
||||||
|
|
||||||
export default function Carousel({ images, className }: Props) {
|
export default function Carousel({ images, className }: Props) {
|
||||||
const [emblaRef, emblaApi] = useEmblaCarousel();
|
const [emblaRef, emblaApi] = useEmblaCarousel({ duration: 15 });
|
||||||
const [selectedIndex, setSelectedIndex] = useState(0);
|
const [selectedIndex, setSelectedIndex] = useState(0);
|
||||||
const [scrollSnaps, setScrollSnaps] = useState<number[]>([]);
|
const [scrollSnaps, setScrollSnaps] = useState<number[]>([]);
|
||||||
const [isFocused, setIsFocused] = useState(false);
|
const [isFocused, setIsFocused] = useState(false);
|
||||||
|
|
|
||||||
|
|
@ -10,7 +10,9 @@ export default function GenderSelect() {
|
||||||
const searchParams = useSearchParams();
|
const searchParams = useSearchParams();
|
||||||
const [, startTransition] = useTransition();
|
const [, startTransition] = useTransition();
|
||||||
|
|
||||||
const [selected, setSelected] = useState<MiiGender | null>((searchParams.get("gender") as MiiGender) ?? null);
|
const [selected, setSelected] = useState<MiiGender | null>(
|
||||||
|
(searchParams.get("gender") as MiiGender) ?? null
|
||||||
|
);
|
||||||
|
|
||||||
const handleClick = (gender: MiiGender) => {
|
const handleClick = (gender: MiiGender) => {
|
||||||
const filter = selected === gender ? null : gender;
|
const filter = selected === gender ? null : gender;
|
||||||
|
|
@ -31,24 +33,36 @@ export default function GenderSelect() {
|
||||||
};
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="grid grid-cols-2 gap-0.5">
|
<div className="grid grid-cols-2 gap-0.5 w-fit">
|
||||||
<button
|
<button
|
||||||
onClick={() => handleClick("MALE")}
|
onClick={() => handleClick("MALE")}
|
||||||
aria-label="Filter for Male Miis"
|
aria-label="Filter for Male Miis"
|
||||||
className={`cursor-pointer rounded-xl flex justify-center items-center size-11 text-4xl border-2 transition-all ${
|
data-tooltip-span
|
||||||
selected === "MALE" ? "bg-blue-100 border-blue-400 shadow-md" : "bg-white border-gray-300 hover:border-gray-400"
|
className={`cursor-pointer rounded-xl flex justify-center items-center size-13 text-5xl border-2 transition-all ${
|
||||||
|
selected === "MALE"
|
||||||
|
? "bg-blue-100 border-blue-400 shadow-md"
|
||||||
|
: "bg-white border-gray-300 hover:border-gray-400"
|
||||||
}`}
|
}`}
|
||||||
>
|
>
|
||||||
|
<div className="tooltip bg-blue-400! border-blue-400! before:border-b-blue-400!">
|
||||||
|
Male
|
||||||
|
</div>
|
||||||
<Icon icon="foundation:male" className="text-blue-400" />
|
<Icon icon="foundation:male" className="text-blue-400" />
|
||||||
</button>
|
</button>
|
||||||
|
|
||||||
<button
|
<button
|
||||||
onClick={() => handleClick("FEMALE")}
|
onClick={() => handleClick("FEMALE")}
|
||||||
aria-label="Filter for Female Miis"
|
aria-label="Filter for Female Miis"
|
||||||
className={`cursor-pointer rounded-xl flex justify-center items-center size-11 text-4xl border-2 transition-all ${
|
data-tooltip-span
|
||||||
selected === "FEMALE" ? "bg-pink-100 border-pink-400 shadow-md" : "bg-white border-gray-300 hover:border-gray-400"
|
className={`cursor-pointer rounded-xl flex justify-center items-center size-13 text-5xl border-2 transition-all ${
|
||||||
|
selected === "FEMALE"
|
||||||
|
? "bg-pink-100 border-pink-400 shadow-md"
|
||||||
|
: "bg-white border-gray-300 hover:border-gray-400"
|
||||||
}`}
|
}`}
|
||||||
>
|
>
|
||||||
|
<div className="tooltip bg-pink-400! border-pink-400! before:border-b-pink-400!">
|
||||||
|
Female
|
||||||
|
</div>
|
||||||
<Icon icon="foundation:female" className="text-pink-400" />
|
<Icon icon="foundation:female" className="text-pink-400" />
|
||||||
</button>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
import Link from "next/link";
|
import Link from "next/link";
|
||||||
|
|
||||||
import { Prisma } from "@prisma/client";
|
import { MiiGender, MiiPlatform, Prisma } from "@prisma/client";
|
||||||
import { Icon } from "@iconify/react";
|
import { Icon } from "@iconify/react";
|
||||||
|
|
||||||
import crypto from "crypto";
|
import crypto from "crypto";
|
||||||
|
|
@ -29,7 +29,7 @@ export default async function MiiList({ searchParams, userId, inLikesPage }: Pro
|
||||||
const parsed = searchSchema.safeParse(searchParams);
|
const parsed = searchSchema.safeParse(searchParams);
|
||||||
if (!parsed.success) return <h1>{parsed.error.issues[0].message}</h1>;
|
if (!parsed.success) return <h1>{parsed.error.issues[0].message}</h1>;
|
||||||
|
|
||||||
const { q: query, sort, tags, exclude, gender, allowCopying, page = 1, limit = 24, seed } = parsed.data;
|
const { q: query, sort, tags, exclude, platform, gender, allowCopying, page = 1, limit = 24, seed } = parsed.data;
|
||||||
|
|
||||||
// My Likes page
|
// My Likes page
|
||||||
let miiIdsLiked: number[] | undefined = undefined;
|
let miiIdsLiked: number[] | undefined = undefined;
|
||||||
|
|
@ -52,6 +52,8 @@ export default async function MiiList({ searchParams, userId, inLikesPage }: Pro
|
||||||
// Tag filtering
|
// Tag filtering
|
||||||
...(tags && tags.length > 0 && { tags: { hasEvery: tags } }),
|
...(tags && tags.length > 0 && { tags: { hasEvery: tags } }),
|
||||||
...(exclude && exclude.length > 0 && { NOT: { tags: { hasSome: exclude } } }),
|
...(exclude && exclude.length > 0 && { NOT: { tags: { hasSome: exclude } } }),
|
||||||
|
// Platform
|
||||||
|
...(platform && { platform: { equals: platform } }),
|
||||||
// Gender
|
// Gender
|
||||||
...(gender && { gender: { equals: gender } }),
|
...(gender && { gender: { equals: gender } }),
|
||||||
// Allow Copying
|
// Allow Copying
|
||||||
|
|
@ -71,6 +73,7 @@ export default async function MiiList({ searchParams, userId, inLikesPage }: Pro
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
}),
|
}),
|
||||||
|
platform: true,
|
||||||
name: true,
|
name: true,
|
||||||
imageCount: true,
|
imageCount: true,
|
||||||
tags: true,
|
tags: true,
|
||||||
|
|
@ -143,7 +146,13 @@ export default async function MiiList({ searchParams, userId, inLikesPage }: Pro
|
||||||
[totalCount, filteredCount, list] = await Promise.all([
|
[totalCount, filteredCount, list] = await Promise.all([
|
||||||
prisma.mii.count({ where: { ...where, userId } }),
|
prisma.mii.count({ where: { ...where, userId } }),
|
||||||
prisma.mii.count({ where, skip, take: limit }),
|
prisma.mii.count({ where, skip, take: limit }),
|
||||||
prisma.mii.findMany({ where, orderBy, select, skip: (page - 1) * limit, take: limit }),
|
prisma.mii.findMany({
|
||||||
|
where,
|
||||||
|
orderBy,
|
||||||
|
select,
|
||||||
|
skip: (page - 1) * limit,
|
||||||
|
take: limit,
|
||||||
|
}),
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -156,7 +165,7 @@ export default async function MiiList({ searchParams, userId, inLikesPage }: Pro
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="w-full">
|
<div className="w-full">
|
||||||
<div className="bg-amber-50 border-2 border-amber-500 rounded-2xl shadow-lg p-4 flex justify-between items-center gap-2 mb-2 max-[56rem]:flex-col">
|
<div className="bg-amber-50 border-2 border-amber-500 rounded-2xl shadow-lg p-4 flex justify-between items-center gap-2 mb-2 max-md:flex-col">
|
||||||
<div className="flex items-center gap-2">
|
<div className="flex items-center gap-2">
|
||||||
{totalCount == filteredCount ? (
|
{totalCount == filteredCount ? (
|
||||||
<>
|
<>
|
||||||
|
|
|
||||||
58
src/components/mii-list/platform-select.tsx
Normal file
|
|
@ -0,0 +1,58 @@
|
||||||
|
"use client";
|
||||||
|
|
||||||
|
import { useRouter, useSearchParams } from "next/navigation";
|
||||||
|
import { useState, useTransition } from "react";
|
||||||
|
import { Icon } from "@iconify/react";
|
||||||
|
import { MiiPlatform } from "@prisma/client";
|
||||||
|
|
||||||
|
export default function PlatformSelect() {
|
||||||
|
const router = useRouter();
|
||||||
|
const searchParams = useSearchParams();
|
||||||
|
const [, startTransition] = useTransition();
|
||||||
|
|
||||||
|
const [selected, setSelected] = useState<MiiPlatform | null>((searchParams.get("platform") as MiiPlatform) ?? null);
|
||||||
|
|
||||||
|
const handleClick = (platform: MiiPlatform) => {
|
||||||
|
const filter = selected === platform ? null : platform;
|
||||||
|
setSelected(filter);
|
||||||
|
|
||||||
|
const params = new URLSearchParams(searchParams);
|
||||||
|
if (filter) {
|
||||||
|
params.set("platform", filter);
|
||||||
|
} else {
|
||||||
|
params.delete("platform");
|
||||||
|
}
|
||||||
|
|
||||||
|
startTransition(() => {
|
||||||
|
router.push(`?${params.toString()}`);
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div className="grid grid-cols-2 gap-0.5 w-fit">
|
||||||
|
<button
|
||||||
|
onClick={() => handleClick("THREE_DS")}
|
||||||
|
aria-label="Filter for 3DS Miis"
|
||||||
|
data-tooltip-span
|
||||||
|
className={`cursor-pointer rounded-xl flex justify-center items-center size-13 text-3xl border-2 transition-all ${
|
||||||
|
selected === "THREE_DS" ? "bg-sky-100 border-sky-400 shadow-md" : "bg-white border-gray-300 hover:border-gray-400"
|
||||||
|
}`}
|
||||||
|
>
|
||||||
|
<div className="tooltip !bg-sky-400 !border-sky-400 before:!border-b-sky-400">3DS</div>
|
||||||
|
<Icon icon="cib:nintendo-3ds" className="text-sky-400" />
|
||||||
|
</button>
|
||||||
|
|
||||||
|
<button
|
||||||
|
onClick={() => handleClick("SWITCH")}
|
||||||
|
aria-label="Filter for Switch Miis"
|
||||||
|
data-tooltip-span
|
||||||
|
className={`cursor-pointer rounded-xl flex justify-center items-center size-13 text-3xl border-2 transition-all ${
|
||||||
|
selected === "SWITCH" ? "bg-red-100 border-red-400 shadow-md" : "bg-white border-gray-300 hover:border-gray-400"
|
||||||
|
}`}
|
||||||
|
>
|
||||||
|
<div className="tooltip !bg-red-400 !border-red-400 before:!border-b-red-400">Switch</div>
|
||||||
|
<Icon icon="cib:nintendo-switch" className="text-red-400" />
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
@ -7,6 +7,7 @@ import { FileWithPath } from "react-dropzone";
|
||||||
import { Icon } from "@iconify/react";
|
import { Icon } from "@iconify/react";
|
||||||
|
|
||||||
import qrcode from "qrcode-generator";
|
import qrcode from "qrcode-generator";
|
||||||
|
import { MiiGender, MiiPlatform } from "@prisma/client";
|
||||||
|
|
||||||
import { nameSchema, tagsSchema } from "@/lib/schemas";
|
import { nameSchema, tagsSchema } from "@/lib/schemas";
|
||||||
import { convertQrCode } from "@/lib/qr-codes";
|
import { convertQrCode } from "@/lib/qr-codes";
|
||||||
|
|
@ -15,9 +16,11 @@ import { TomodachiLifeMii } from "@/lib/tomodachi-life-mii";
|
||||||
|
|
||||||
import TagSelector from "../tag-selector";
|
import TagSelector from "../tag-selector";
|
||||||
import ImageList from "./image-list";
|
import ImageList from "./image-list";
|
||||||
|
import PortraitUpload from "./portrait-upload";
|
||||||
import QrUpload from "./qr-upload";
|
import QrUpload from "./qr-upload";
|
||||||
import QrScanner from "./qr-scanner";
|
import QrScanner from "./qr-scanner";
|
||||||
import SubmitTutorialButton from "../tutorial/submit";
|
import SwitchSubmitTutorialButton from "../tutorial/switch-submit";
|
||||||
|
import ThreeDsSubmitTutorialButton from "../tutorial/3ds-submit";
|
||||||
import LikeButton from "../like-button";
|
import LikeButton from "../like-button";
|
||||||
import Carousel from "../carousel";
|
import Carousel from "../carousel";
|
||||||
import SubmitButton from "../submit-button";
|
import SubmitButton from "../submit-button";
|
||||||
|
|
@ -35,16 +38,19 @@ export default function SubmitForm() {
|
||||||
);
|
);
|
||||||
|
|
||||||
const [isQrScannerOpen, setIsQrScannerOpen] = useState(false);
|
const [isQrScannerOpen, setIsQrScannerOpen] = useState(false);
|
||||||
const [studioUrl, setStudioUrl] = useState<string | undefined>();
|
const [miiPortraitUri, setMiiPortraitUri] = useState<string | undefined>();
|
||||||
const [generatedQrCodeUrl, setGeneratedQrCodeUrl] = useState<string | undefined>();
|
const [generatedQrCodeUri, setGeneratedQrCodeUri] = useState<string | undefined>();
|
||||||
|
|
||||||
const [error, setError] = useState<string | undefined>(undefined);
|
|
||||||
|
|
||||||
const [name, setName] = useState("");
|
const [name, setName] = useState("");
|
||||||
const [tags, setTags] = useState<string[]>([]);
|
const [tags, setTags] = useState<string[]>([]);
|
||||||
const [description, setDescription] = useState("");
|
const [description, setDescription] = useState("");
|
||||||
const [qrBytesRaw, setQrBytesRaw] = useState<number[]>([]);
|
const [qrBytesRaw, setQrBytesRaw] = useState<number[]>([]);
|
||||||
|
|
||||||
|
const [platform, setPlatform] = useState<MiiPlatform>("SWITCH");
|
||||||
|
const [gender, setGender] = useState<MiiGender>("MALE");
|
||||||
|
|
||||||
|
const [error, setError] = useState<string | undefined>(undefined);
|
||||||
|
|
||||||
const handleSubmit = async () => {
|
const handleSubmit = async () => {
|
||||||
// Validate before sending request
|
// Validate before sending request
|
||||||
const nameValidation = nameSchema.safeParse(name);
|
const nameValidation = nameSchema.safeParse(name);
|
||||||
|
|
@ -60,6 +66,7 @@ export default function SubmitForm() {
|
||||||
|
|
||||||
// Send request to server
|
// Send request to server
|
||||||
const formData = new FormData();
|
const formData = new FormData();
|
||||||
|
formData.append("platform", platform);
|
||||||
formData.append("name", name);
|
formData.append("name", name);
|
||||||
formData.append("tags", JSON.stringify(tags));
|
formData.append("tags", JSON.stringify(tags));
|
||||||
formData.append("description", description);
|
formData.append("description", description);
|
||||||
|
|
@ -69,6 +76,24 @@ export default function SubmitForm() {
|
||||||
formData.append(`image${index + 1}`, file);
|
formData.append(`image${index + 1}`, file);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
if (platform === "SWITCH") {
|
||||||
|
const response = await fetch(miiPortraitUri!);
|
||||||
|
|
||||||
|
if (!response.ok) {
|
||||||
|
setError("Failed to check Mii portrait. Did you upload one?");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const blob = await response.blob();
|
||||||
|
if (!blob.type.startsWith("image/")) {
|
||||||
|
setError("Invalid image file returned");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
formData.append("gender", gender);
|
||||||
|
formData.append("miiPortraitImage", blob);
|
||||||
|
}
|
||||||
|
|
||||||
const response = await fetch("/api/submit", {
|
const response = await fetch("/api/submit", {
|
||||||
method: "POST",
|
method: "POST",
|
||||||
body: formData,
|
body: formData,
|
||||||
|
|
@ -96,38 +121,39 @@ export default function SubmitForm() {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Convert QR code to JS
|
// Convert QR code to JS (3DS)
|
||||||
let conversion: { mii: Mii; tomodachiLifeMii: TomodachiLifeMii };
|
if (platform === "THREE_DS") {
|
||||||
try {
|
let conversion: { mii: Mii; tomodachiLifeMii: TomodachiLifeMii };
|
||||||
conversion = convertQrCode(qrBytes);
|
try {
|
||||||
} catch (error) {
|
conversion = convertQrCode(qrBytes);
|
||||||
setError(error instanceof Error ? error.message : String(error));
|
setMiiPortraitUri(conversion.mii.studioUrl({ width: 512 }));
|
||||||
return;
|
} catch (error) {
|
||||||
|
setError(error instanceof Error ? error.message : String(error));
|
||||||
|
return;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Generate a new QR code for aesthetic reasons
|
||||||
try {
|
try {
|
||||||
setStudioUrl(conversion.mii.studioUrl({ width: 512 }));
|
|
||||||
|
|
||||||
// Generate a new QR code for aesthetic reasons
|
|
||||||
const byteString = String.fromCharCode(...qrBytes);
|
const byteString = String.fromCharCode(...qrBytes);
|
||||||
const generatedCode = qrcode(0, "L");
|
const generatedCode = qrcode(0, "L");
|
||||||
generatedCode.addData(byteString, "Byte");
|
generatedCode.addData(byteString, "Byte");
|
||||||
generatedCode.make();
|
generatedCode.make();
|
||||||
|
|
||||||
setGeneratedQrCodeUrl(generatedCode.createDataURL());
|
setGeneratedQrCodeUri(generatedCode.createDataURL());
|
||||||
} catch {
|
} catch {
|
||||||
setError("Failed to get and/or generate Mii images");
|
setError("Failed to regenerate QR code");
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
preview();
|
preview();
|
||||||
}, [qrBytesRaw]);
|
}, [qrBytesRaw, platform]);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<form className="flex justify-center gap-4 w-full max-lg:flex-col max-lg:items-center">
|
<form className="flex justify-center gap-4 w-full max-lg:flex-col max-lg:items-center">
|
||||||
<div className="flex justify-center">
|
<div className="flex justify-center">
|
||||||
<div className="w-75 h-min flex flex-col bg-zinc-50 rounded-3xl border-2 border-zinc-300 shadow-lg p-3">
|
<div className="w-75 h-min flex flex-col bg-zinc-50 rounded-3xl border-2 border-zinc-300 shadow-lg p-3">
|
||||||
<Carousel images={[studioUrl ?? "/loading.svg", generatedQrCodeUrl ?? "/loading.svg", ...files.map((file) => URL.createObjectURL(file))]} />
|
<Carousel images={[miiPortraitUri ?? "/loading.svg", generatedQrCodeUri ?? "/loading.svg", ...files.map((file) => URL.createObjectURL(file))]} />
|
||||||
|
|
||||||
<div className="p-4 flex flex-col gap-1 h-full">
|
<div className="p-4 flex flex-col gap-1 h-full">
|
||||||
<h1 className="font-bold text-2xl line-clamp-1" title={name}>
|
<h1 className="font-bold text-2xl line-clamp-1" title={name}>
|
||||||
|
|
@ -162,6 +188,47 @@ export default function SubmitForm() {
|
||||||
<hr className="grow border-zinc-300" />
|
<hr className="grow border-zinc-300" />
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
{/* Platform select */}
|
||||||
|
<div className="w-full grid grid-cols-3 items-center">
|
||||||
|
<label htmlFor="name" className="font-semibold">
|
||||||
|
Platform
|
||||||
|
</label>
|
||||||
|
<div className="relative col-span-2 grid grid-cols-2 bg-orange-300 border-2 border-orange-400 rounded-4xl shadow-md inset-shadow-sm/10">
|
||||||
|
{/* Animated indicator */}
|
||||||
|
{/* TODO: maybe change width as part of animation? */}
|
||||||
|
<div
|
||||||
|
className={`absolute inset-0 w-1/2 bg-orange-200 rounded-4xl transition-transform duration-300 ${
|
||||||
|
platform === "SWITCH" ? "translate-x-0" : "translate-x-full"
|
||||||
|
}`}
|
||||||
|
></div>
|
||||||
|
|
||||||
|
{/* Switch button */}
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
onClick={() => setPlatform("SWITCH")}
|
||||||
|
className={`p-2 text-slate-800/35 cursor-pointer flex justify-center items-center gap-2 z-10 transition-colors ${
|
||||||
|
platform === "SWITCH" && "text-slate-800!"
|
||||||
|
}`}
|
||||||
|
>
|
||||||
|
<Icon icon="cib:nintendo-switch" className="text-2xl" />
|
||||||
|
Switch
|
||||||
|
</button>
|
||||||
|
|
||||||
|
{/* 3DS button */}
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
onClick={() => setPlatform("THREE_DS")}
|
||||||
|
className={`p-2 text-slate-800/35 cursor-pointer flex justify-center items-center gap-2 z-10 transition-colors ${
|
||||||
|
platform === "THREE_DS" && "text-slate-800!"
|
||||||
|
}`}
|
||||||
|
>
|
||||||
|
<Icon icon="cib:nintendo-3ds" className="text-2xl" />
|
||||||
|
3DS
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{/* Name */}
|
||||||
<div className="w-full grid grid-cols-3 items-center">
|
<div className="w-full grid grid-cols-3 items-center">
|
||||||
<label htmlFor="name" className="font-semibold">
|
<label htmlFor="name" className="font-semibold">
|
||||||
Name
|
Name
|
||||||
|
|
@ -185,11 +252,13 @@ export default function SubmitForm() {
|
||||||
<TagSelector tags={tags} setTags={setTags} showTagLimit />
|
<TagSelector tags={tags} setTags={setTags} showTagLimit />
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
{/* Description */}
|
||||||
<div className="w-full grid grid-cols-3 items-start">
|
<div className="w-full grid grid-cols-3 items-start">
|
||||||
<label htmlFor="reason-note" className="font-semibold py-2">
|
<label htmlFor="description" className="font-semibold py-2">
|
||||||
Description
|
Description
|
||||||
</label>
|
</label>
|
||||||
<textarea
|
<textarea
|
||||||
|
name="description"
|
||||||
rows={5}
|
rows={5}
|
||||||
maxLength={256}
|
maxLength={256}
|
||||||
placeholder="(optional) Type a description..."
|
placeholder="(optional) Type a description..."
|
||||||
|
|
@ -199,7 +268,54 @@ export default function SubmitForm() {
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
{/* Separator */}
|
{/* Gender (switch only) */}
|
||||||
|
{platform === "SWITCH" && (
|
||||||
|
<div className="w-full grid grid-cols-3 items-start">
|
||||||
|
<label htmlFor="gender" className="font-semibold py-2">
|
||||||
|
Gender
|
||||||
|
</label>
|
||||||
|
<div className="col-span-2 flex gap-1">
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
onClick={() => setGender("MALE")}
|
||||||
|
aria-label="Filter for Male Miis"
|
||||||
|
className={`cursor-pointer rounded-xl flex justify-center items-center size-11 text-4xl border-2 transition-all ${
|
||||||
|
gender === "MALE" ? "bg-blue-100 border-blue-400 shadow-md" : "bg-white border-gray-300 hover:border-gray-400"
|
||||||
|
}`}
|
||||||
|
>
|
||||||
|
<Icon icon="foundation:male" className="text-blue-400" />
|
||||||
|
</button>
|
||||||
|
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
onClick={() => setGender("FEMALE")}
|
||||||
|
aria-label="Filter for Female Miis"
|
||||||
|
className={`cursor-pointer rounded-xl flex justify-center items-center size-11 text-4xl border-2 transition-all ${
|
||||||
|
gender === "FEMALE" ? "bg-pink-100 border-pink-400 shadow-md" : "bg-white border-gray-300 hover:border-gray-400"
|
||||||
|
}`}
|
||||||
|
>
|
||||||
|
<Icon icon="foundation:female" className="text-pink-400" />
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
|
||||||
|
{platform === "SWITCH" && (
|
||||||
|
<>
|
||||||
|
{/* Separator */}
|
||||||
|
<div className="flex items-center gap-4 text-zinc-500 text-sm font-medium mt-8 mb-2">
|
||||||
|
<hr className="grow border-zinc-300" />
|
||||||
|
<span>Mii Portrait</span>
|
||||||
|
<hr className="grow border-zinc-300" />
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div className="flex flex-col items-center gap-2">
|
||||||
|
<PortraitUpload setImage={setMiiPortraitUri} />
|
||||||
|
</div>
|
||||||
|
</>
|
||||||
|
)}
|
||||||
|
|
||||||
|
{/* QR code selector */}
|
||||||
<div className="flex items-center gap-4 text-zinc-500 text-sm font-medium mt-8 mb-2">
|
<div className="flex items-center gap-4 text-zinc-500 text-sm font-medium mt-8 mb-2">
|
||||||
<hr className="grow border-zinc-300" />
|
<hr className="grow border-zinc-300" />
|
||||||
<span>QR Code</span>
|
<span>QR Code</span>
|
||||||
|
|
@ -216,12 +332,18 @@ export default function SubmitForm() {
|
||||||
</button>
|
</button>
|
||||||
|
|
||||||
<QrScanner isOpen={isQrScannerOpen} setIsOpen={setIsQrScannerOpen} setQrBytesRaw={setQrBytesRaw} />
|
<QrScanner isOpen={isQrScannerOpen} setIsOpen={setIsQrScannerOpen} setQrBytesRaw={setQrBytesRaw} />
|
||||||
<SubmitTutorialButton />
|
{platform === "THREE_DS" ? (
|
||||||
|
<>
|
||||||
|
<ThreeDsSubmitTutorialButton />
|
||||||
|
|
||||||
<span className="text-xs text-zinc-400">For emulators, aes_keys.txt is required.</span>
|
<span className="text-xs text-zinc-400">For emulators, aes_keys.txt is required.</span>
|
||||||
|
</>
|
||||||
|
) : (
|
||||||
|
<SwitchSubmitTutorialButton />
|
||||||
|
)}
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
{/* Separator */}
|
{/* Custom images selector */}
|
||||||
<div className="flex items-center gap-4 text-zinc-500 text-sm font-medium mt-6 mb-2">
|
<div className="flex items-center gap-4 text-zinc-500 text-sm font-medium mt-6 mb-2">
|
||||||
<hr className="grow border-zinc-300" />
|
<hr className="grow border-zinc-300" />
|
||||||
<span>Custom images</span>
|
<span>Custom images</span>
|
||||||
|
|
|
||||||
45
src/components/submit-form/portrait-upload.tsx
Normal file
|
|
@ -0,0 +1,45 @@
|
||||||
|
"use client";
|
||||||
|
|
||||||
|
import { useCallback, useState } from "react";
|
||||||
|
import { FileWithPath } from "react-dropzone";
|
||||||
|
import Dropzone from "../dropzone";
|
||||||
|
|
||||||
|
interface Props {
|
||||||
|
setImage: React.Dispatch<React.SetStateAction<string | undefined>>;
|
||||||
|
}
|
||||||
|
|
||||||
|
export default function PortraitUpload({ setImage }: Props) {
|
||||||
|
const [hasImage, setHasImage] = useState(false);
|
||||||
|
|
||||||
|
const handleDrop = useCallback(
|
||||||
|
(acceptedFiles: FileWithPath[]) => {
|
||||||
|
const file = acceptedFiles[0];
|
||||||
|
// Convert to Data URI
|
||||||
|
const reader = new FileReader();
|
||||||
|
reader.onload = async (event) => {
|
||||||
|
setImage(event.target!.result as string);
|
||||||
|
setHasImage(true);
|
||||||
|
};
|
||||||
|
reader.readAsDataURL(file);
|
||||||
|
},
|
||||||
|
[setImage]
|
||||||
|
);
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div className="max-w-md w-full">
|
||||||
|
<Dropzone onDrop={handleDrop} options={{ maxFiles: 1 }}>
|
||||||
|
<p className="text-center text-sm">
|
||||||
|
{!hasImage ? (
|
||||||
|
<>
|
||||||
|
Drag and drop your Mii's portrait here
|
||||||
|
<br />
|
||||||
|
or click to open
|
||||||
|
</>
|
||||||
|
) : (
|
||||||
|
"Uploaded!"
|
||||||
|
)}
|
||||||
|
</p>
|
||||||
|
</Dropzone>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
"use client";
|
"use client";
|
||||||
|
|
||||||
import { useCallback, useRef } from "react";
|
import { useCallback, useRef, useState } from "react";
|
||||||
import { FileWithPath } from "react-dropzone";
|
import { FileWithPath } from "react-dropzone";
|
||||||
import jsQR from "jsqr";
|
import jsQR from "jsqr";
|
||||||
import Dropzone from "../dropzone";
|
import Dropzone from "../dropzone";
|
||||||
|
|
@ -10,36 +10,38 @@ interface Props {
|
||||||
}
|
}
|
||||||
|
|
||||||
export default function QrUpload({ setQrBytesRaw }: Props) {
|
export default function QrUpload({ setQrBytesRaw }: Props) {
|
||||||
|
const [hasImage, setHasImage] = useState(false);
|
||||||
const canvasRef = useRef<HTMLCanvasElement>(null);
|
const canvasRef = useRef<HTMLCanvasElement>(null);
|
||||||
|
|
||||||
const handleDrop = useCallback(
|
const handleDrop = useCallback(
|
||||||
(acceptedFiles: FileWithPath[]) => {
|
(acceptedFiles: FileWithPath[]) => {
|
||||||
acceptedFiles.forEach((file) => {
|
const file = acceptedFiles[0];
|
||||||
// Scan QR code
|
|
||||||
const reader = new FileReader();
|
|
||||||
reader.onload = async (event) => {
|
|
||||||
const image = new Image();
|
|
||||||
image.onload = () => {
|
|
||||||
const canvas = canvasRef.current;
|
|
||||||
if (!canvas) return;
|
|
||||||
|
|
||||||
const ctx = canvas.getContext("2d");
|
// Scan QR code
|
||||||
if (!ctx) return;
|
const reader = new FileReader();
|
||||||
|
reader.onload = async (event) => {
|
||||||
|
const image = new Image();
|
||||||
|
image.onload = () => {
|
||||||
|
const canvas = canvasRef.current;
|
||||||
|
if (!canvas) return;
|
||||||
|
|
||||||
canvas.width = image.width;
|
const ctx = canvas.getContext("2d");
|
||||||
canvas.height = image.height;
|
if (!ctx) return;
|
||||||
ctx.drawImage(image, 0, 0, image.width, image.height);
|
|
||||||
|
|
||||||
const imageData = ctx.getImageData(0, 0, image.width, image.height);
|
canvas.width = image.width;
|
||||||
const code = jsQR(imageData.data, image.width, image.height);
|
canvas.height = image.height;
|
||||||
if (!code) return;
|
ctx.drawImage(image, 0, 0, image.width, image.height);
|
||||||
|
|
||||||
setQrBytesRaw(code.binaryData!);
|
const imageData = ctx.getImageData(0, 0, image.width, image.height);
|
||||||
};
|
const code = jsQR(imageData.data, image.width, image.height);
|
||||||
image.src = event.target!.result as string;
|
if (!code) return;
|
||||||
|
|
||||||
|
setQrBytesRaw(code.binaryData!);
|
||||||
|
setHasImage(true);
|
||||||
};
|
};
|
||||||
reader.readAsDataURL(file);
|
image.src = event.target!.result as string;
|
||||||
});
|
};
|
||||||
|
reader.readAsDataURL(file);
|
||||||
},
|
},
|
||||||
[setQrBytesRaw],
|
[setQrBytesRaw],
|
||||||
);
|
);
|
||||||
|
|
@ -48,9 +50,15 @@ export default function QrUpload({ setQrBytesRaw }: Props) {
|
||||||
<div className="max-w-md w-full">
|
<div className="max-w-md w-full">
|
||||||
<Dropzone onDrop={handleDrop} options={{ maxFiles: 1 }}>
|
<Dropzone onDrop={handleDrop} options={{ maxFiles: 1 }}>
|
||||||
<p className="text-center text-sm">
|
<p className="text-center text-sm">
|
||||||
Drag and drop your QR code image here
|
{!hasImage ? (
|
||||||
<br />
|
<>
|
||||||
or click to open
|
Drag and drop your QR code image here
|
||||||
|
<br />
|
||||||
|
or click to open
|
||||||
|
</>
|
||||||
|
) : (
|
||||||
|
"Uploaded!"
|
||||||
|
)}
|
||||||
</p>
|
</p>
|
||||||
</Dropzone>
|
</Dropzone>
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -97,7 +97,7 @@ export default function TagSelector({ tags, setTags, showTagLimit, isExclude }:
|
||||||
<button
|
<button
|
||||||
type="button"
|
type="button"
|
||||||
aria-label="Delete Tag"
|
aria-label="Delete Tag"
|
||||||
className="text-black cursor-pointer"
|
className="text-slate-800 cursor-pointer"
|
||||||
onClick={(e) => {
|
onClick={(e) => {
|
||||||
e.stopPropagation();
|
e.stopPropagation();
|
||||||
removeTag(tag);
|
removeTag(tag);
|
||||||
|
|
|
||||||
61
src/components/tutorial/3ds-scan.tsx
Normal file
|
|
@ -0,0 +1,61 @@
|
||||||
|
"use client";
|
||||||
|
|
||||||
|
import { useState } from "react";
|
||||||
|
import { createPortal } from "react-dom";
|
||||||
|
import { Icon } from "@iconify/react";
|
||||||
|
import Tutorial from ".";
|
||||||
|
|
||||||
|
export default function ThreeDsScanTutorialButton() {
|
||||||
|
const [isOpen, setIsOpen] = useState(false);
|
||||||
|
|
||||||
|
return (
|
||||||
|
<>
|
||||||
|
<button
|
||||||
|
aria-label="Tutorial"
|
||||||
|
type="button"
|
||||||
|
onClick={() => setIsOpen(true)}
|
||||||
|
className="text-3xl cursor-pointer"
|
||||||
|
>
|
||||||
|
<Icon icon="fa:question-circle" />
|
||||||
|
<span>Tutorial</span>
|
||||||
|
</button>
|
||||||
|
|
||||||
|
{isOpen &&
|
||||||
|
createPortal(
|
||||||
|
<Tutorial
|
||||||
|
tutorials={[
|
||||||
|
{
|
||||||
|
title: "Adding Mii",
|
||||||
|
steps: [
|
||||||
|
{
|
||||||
|
text: "1. Enter the town hall",
|
||||||
|
imageSrc: "/tutorial/3ds/step1.png",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
text: "2. Go into 'QR Code'",
|
||||||
|
imageSrc: "/tutorial/3ds/adding-mii/step2.png",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
text: "3. Press 'Scan QR Code'",
|
||||||
|
imageSrc: "/tutorial/3ds/adding-mii/step3.png",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
text: "4. Click on the QR code below the Mii's image",
|
||||||
|
imageSrc: "/tutorial/3ds/adding-mii/step4.png",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
text: "5. Scan with your 3DS",
|
||||||
|
imageSrc: "/tutorial/3ds/adding-mii/step5.png",
|
||||||
|
},
|
||||||
|
{ type: "finish" },
|
||||||
|
],
|
||||||
|
},
|
||||||
|
]}
|
||||||
|
isOpen={isOpen}
|
||||||
|
setIsOpen={setIsOpen}
|
||||||
|
/>,
|
||||||
|
document.body
|
||||||
|
)}
|
||||||
|
</>
|
||||||
|
);
|
||||||
|
}
|
||||||
101
src/components/tutorial/3ds-submit.tsx
Normal file
|
|
@ -0,0 +1,101 @@
|
||||||
|
"use client";
|
||||||
|
|
||||||
|
import { useState } from "react";
|
||||||
|
import { createPortal } from "react-dom";
|
||||||
|
import Tutorial from ".";
|
||||||
|
|
||||||
|
export default function SubmitTutorialButton() {
|
||||||
|
const [isOpen, setIsOpen] = useState(false);
|
||||||
|
|
||||||
|
return (
|
||||||
|
<>
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
onClick={() => setIsOpen(true)}
|
||||||
|
className="text-sm text-orange-400 cursor-pointer underline-offset-2 hover:underline"
|
||||||
|
>
|
||||||
|
How to?
|
||||||
|
</button>
|
||||||
|
|
||||||
|
{isOpen &&
|
||||||
|
createPortal(
|
||||||
|
<Tutorial
|
||||||
|
tutorials={[
|
||||||
|
{
|
||||||
|
title: "Allow Copying",
|
||||||
|
thumbnail: "/tutorial/3ds/allow-copying/thumbnail.png",
|
||||||
|
hint: "Suggested!",
|
||||||
|
steps: [
|
||||||
|
{ type: "start" },
|
||||||
|
{
|
||||||
|
text: "1. Enter the town hall",
|
||||||
|
imageSrc: "/tutorial/3ds/step1.png",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
text: "2. Go into 'Mii List'",
|
||||||
|
imageSrc: "/tutorial/3ds/allow-copying/step2.png",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
text: "3. Select and edit the Mii you wish to submit",
|
||||||
|
imageSrc: "/tutorial/3ds/allow-copying/step3.png",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
text: "4. Click 'Other Settings' in the information screen",
|
||||||
|
imageSrc: "/tutorial/3ds/allow-copying/step4.png",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
text: "5. Click on 'Don't Allow' under the 'Copying' text",
|
||||||
|
imageSrc: "/tutorial/3ds/allow-copying/step5.png",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
text: "6. Press 'Allow'",
|
||||||
|
imageSrc: "/tutorial/3ds/allow-copying/step6.png",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
text: "7. Confirm the edits to the Mii",
|
||||||
|
imageSrc: "/tutorial/3ds/allow-copying/step7.png",
|
||||||
|
},
|
||||||
|
{ type: "finish" },
|
||||||
|
],
|
||||||
|
},
|
||||||
|
{
|
||||||
|
title: "Create QR Code",
|
||||||
|
thumbnail: "/tutorial/3ds/create-qr-code/thumbnail.png",
|
||||||
|
steps: [
|
||||||
|
{ type: "start" },
|
||||||
|
{
|
||||||
|
text: "1. Enter the town hall",
|
||||||
|
imageSrc: "/tutorial/3ds/step1.png",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
text: "2. Go into 'QR Code'",
|
||||||
|
imageSrc: "/tutorial/3ds/create-qr-code/step2.png",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
text: "3. Press 'Create QR Code'",
|
||||||
|
imageSrc: "/tutorial/3ds/create-qr-code/step3.png",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
text: "4. Select and press 'OK' on the Mii you wish to submit",
|
||||||
|
imageSrc: "/tutorial/3ds/create-qr-code/step4.png",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
text: "5. Pick any option; it doesn't matter since the QR code regenerates upon submission.",
|
||||||
|
imageSrc: "/tutorial/3ds/create-qr-code/step5.png",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
text: "6. Exit the tutorial; Upload the QR code (scan with camera or upload file through SD card).",
|
||||||
|
imageSrc: "/tutorial/3ds/create-qr-code/step6.png",
|
||||||
|
},
|
||||||
|
{ type: "finish" },
|
||||||
|
],
|
||||||
|
},
|
||||||
|
]}
|
||||||
|
isOpen={isOpen}
|
||||||
|
setIsOpen={setIsOpen}
|
||||||
|
/>,
|
||||||
|
document.body
|
||||||
|
)}
|
||||||
|
</>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
@ -5,7 +5,6 @@ import { useEffect, useState } from "react";
|
||||||
import useEmblaCarousel from "embla-carousel-react";
|
import useEmblaCarousel from "embla-carousel-react";
|
||||||
import { Icon } from "@iconify/react";
|
import { Icon } from "@iconify/react";
|
||||||
import confetti from "canvas-confetti";
|
import confetti from "canvas-confetti";
|
||||||
import ReturnToIsland from "../admin/return-to-island";
|
|
||||||
|
|
||||||
interface Slide {
|
interface Slide {
|
||||||
// step is never used, undefined is assumed as a step
|
// step is never used, undefined is assumed as a step
|
||||||
|
|
@ -30,7 +29,7 @@ interface Props {
|
||||||
export default function Tutorial({ tutorials, isOpen, setIsOpen }: Props) {
|
export default function Tutorial({ tutorials, isOpen, setIsOpen }: Props) {
|
||||||
const [isVisible, setIsVisible] = useState(false);
|
const [isVisible, setIsVisible] = useState(false);
|
||||||
|
|
||||||
const [emblaRef, emblaApi] = useEmblaCarousel({ loop: true });
|
const [emblaRef, emblaApi] = useEmblaCarousel({ loop: true, duration: 15 });
|
||||||
const [selectedIndex, setSelectedIndex] = useState(0);
|
const [selectedIndex, setSelectedIndex] = useState(0);
|
||||||
|
|
||||||
// Build index map
|
// Build index map
|
||||||
|
|
|
||||||
61
src/components/tutorial/switch-scan.tsx
Normal file
|
|
@ -0,0 +1,61 @@
|
||||||
|
"use client";
|
||||||
|
|
||||||
|
import { useState } from "react";
|
||||||
|
import { createPortal } from "react-dom";
|
||||||
|
import { Icon } from "@iconify/react";
|
||||||
|
import Tutorial from ".";
|
||||||
|
|
||||||
|
export default function ThreeDsScanTutorialButton() {
|
||||||
|
const [isOpen, setIsOpen] = useState(false);
|
||||||
|
|
||||||
|
return (
|
||||||
|
<>
|
||||||
|
<button
|
||||||
|
aria-label="Tutorial"
|
||||||
|
type="button"
|
||||||
|
onClick={() => setIsOpen(true)}
|
||||||
|
className="text-3xl cursor-pointer"
|
||||||
|
>
|
||||||
|
<Icon icon="fa:question-circle" />
|
||||||
|
<span>Tutorial</span>
|
||||||
|
</button>
|
||||||
|
|
||||||
|
{isOpen &&
|
||||||
|
createPortal(
|
||||||
|
<Tutorial
|
||||||
|
tutorials={[
|
||||||
|
{
|
||||||
|
title: "Adding Mii",
|
||||||
|
steps: [
|
||||||
|
{
|
||||||
|
text: "1. Enter the town hall",
|
||||||
|
imageSrc: "/tutorial/switch/step1.png",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
text: "2. Go into 'QR Code'",
|
||||||
|
imageSrc: "/tutorial/switch/adding-mii/step2.png",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
text: "3. Press 'Scan QR Code'",
|
||||||
|
imageSrc: "/tutorial/switch/adding-mii/step3.png",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
text: "4. Click on the QR code below the Mii's image",
|
||||||
|
imageSrc: "/tutorial/switch/adding-mii/step4.png",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
text: "5. Scan with your 3DS",
|
||||||
|
imageSrc: "/tutorial/switch/adding-mii/step5.png",
|
||||||
|
},
|
||||||
|
{ type: "finish" },
|
||||||
|
],
|
||||||
|
},
|
||||||
|
]}
|
||||||
|
isOpen={isOpen}
|
||||||
|
setIsOpen={setIsOpen}
|
||||||
|
/>,
|
||||||
|
document.body
|
||||||
|
)}
|
||||||
|
</>
|
||||||
|
);
|
||||||
|
}
|
||||||
101
src/components/tutorial/switch-submit.tsx
Normal file
|
|
@ -0,0 +1,101 @@
|
||||||
|
"use client";
|
||||||
|
|
||||||
|
import { useState } from "react";
|
||||||
|
import { createPortal } from "react-dom";
|
||||||
|
import Tutorial from ".";
|
||||||
|
|
||||||
|
export default function SubmitTutorialButton() {
|
||||||
|
const [isOpen, setIsOpen] = useState(false);
|
||||||
|
|
||||||
|
return (
|
||||||
|
<>
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
onClick={() => setIsOpen(true)}
|
||||||
|
className="text-sm text-orange-400 cursor-pointer underline-offset-2 hover:underline"
|
||||||
|
>
|
||||||
|
How to?
|
||||||
|
</button>
|
||||||
|
|
||||||
|
{isOpen &&
|
||||||
|
createPortal(
|
||||||
|
<Tutorial
|
||||||
|
tutorials={[
|
||||||
|
{
|
||||||
|
title: "Allow Copying",
|
||||||
|
thumbnail: "/tutorial/switch/allow-copying/thumbnail.png",
|
||||||
|
hint: "Suggested!",
|
||||||
|
steps: [
|
||||||
|
{ type: "start" },
|
||||||
|
{
|
||||||
|
text: "1. Enter the town hall",
|
||||||
|
imageSrc: "/tutorial/switch/step1.png",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
text: "2. Go into 'Mii List'",
|
||||||
|
imageSrc: "/tutorial/switch/allow-copying/step2.png",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
text: "3. Select and edit the Mii you wish to submit",
|
||||||
|
imageSrc: "/tutorial/switch/allow-copying/step3.png",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
text: "4. Click 'Other Settings' in the information screen",
|
||||||
|
imageSrc: "/tutorial/switch/allow-copying/step4.png",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
text: "5. Click on 'Don't Allow' under the 'Copying' text",
|
||||||
|
imageSrc: "/tutorial/switch/allow-copying/step5.png",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
text: "6. Press 'Allow'",
|
||||||
|
imageSrc: "/tutorial/switch/allow-copying/step6.png",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
text: "7. Confirm the edits to the Mii",
|
||||||
|
imageSrc: "/tutorial/switch/allow-copying/step7.png",
|
||||||
|
},
|
||||||
|
{ type: "finish" },
|
||||||
|
],
|
||||||
|
},
|
||||||
|
{
|
||||||
|
title: "Create QR Code",
|
||||||
|
thumbnail: "/tutorial/switch/create-qr-code/thumbnail.png",
|
||||||
|
steps: [
|
||||||
|
{ type: "start" },
|
||||||
|
{
|
||||||
|
text: "1. Enter the town hall",
|
||||||
|
imageSrc: "/tutorial/switch/step1.png",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
text: "2. Go into 'QR Code'",
|
||||||
|
imageSrc: "/tutorial/switch/create-qr-code/step2.png",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
text: "3. Press 'Create QR Code'",
|
||||||
|
imageSrc: "/tutorial/switch/create-qr-code/step3.png",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
text: "4. Select and press 'OK' on the Mii you wish to submit",
|
||||||
|
imageSrc: "/tutorial/switch/create-qr-code/step4.png",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
text: "5. Pick any option; it doesn't matter since the QR code regenerates upon submission.",
|
||||||
|
imageSrc: "/tutorial/switch/create-qr-code/step5.png",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
text: "6. Exit the tutorial; Upload the QR code (scan with camera or upload file through SD card).",
|
||||||
|
imageSrc: "/tutorial/switch/create-qr-code/step6.png",
|
||||||
|
},
|
||||||
|
{ type: "finish" },
|
||||||
|
],
|
||||||
|
},
|
||||||
|
]}
|
||||||
|
isOpen={isOpen}
|
||||||
|
setIsOpen={setIsOpen}
|
||||||
|
/>,
|
||||||
|
document.body
|
||||||
|
)}
|
||||||
|
</>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
@ -150,8 +150,22 @@ export async function generateMetadataImage(mii: Mii, author: string): Promise<{
|
||||||
<div tw="w-full h-full bg-amber-50 border-2 border-amber-500 rounded-2xl p-4 flex flex-col">
|
<div tw="w-full h-full bg-amber-50 border-2 border-amber-500 rounded-2xl p-4 flex flex-col">
|
||||||
<div tw="flex w-full">
|
<div tw="flex w-full">
|
||||||
{/* Mii image */}
|
{/* Mii image */}
|
||||||
<div tw="w-80 rounded-xl flex justify-center mr-2" style={{ backgroundImage: "linear-gradient(to bottom, #fef3c7, #fde68a);" }}>
|
<div
|
||||||
<img src={miiImage} width={248} height={248} style={{ filter: "drop-shadow(0 10px 8px #00000024) drop-shadow(0 4px 3px #00000024)" }} />
|
tw="w-80 h-62 rounded-xl flex justify-center mr-2 px-2"
|
||||||
|
style={{
|
||||||
|
backgroundImage: "linear-gradient(to bottom, #fef3c7, #fde68a);",
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<img
|
||||||
|
src={miiImage}
|
||||||
|
width={248}
|
||||||
|
height={248}
|
||||||
|
tw="w-full h-full"
|
||||||
|
style={{
|
||||||
|
objectFit: "contain",
|
||||||
|
filter: "drop-shadow(0 10px 8px #00000024) drop-shadow(0 4px 3px #00000024)",
|
||||||
|
}}
|
||||||
|
/>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
{/* QR code */}
|
{/* QR code */}
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
import { MiiGender } from "@prisma/client";
|
import { MiiGender, MiiPlatform } from "@prisma/client";
|
||||||
import { z } from "zod";
|
import { z } from "zod";
|
||||||
|
|
||||||
// profanity censoring bypasses the regex in some of these but I think it's funny
|
// profanity censoring bypasses the regex in some of these but I think it's funny
|
||||||
|
|
@ -58,6 +58,7 @@ export const searchSchema = z.object({
|
||||||
.map((tag) => tag.trim())
|
.map((tag) => tag.trim())
|
||||||
.filter((tag) => tag.length > 0),
|
.filter((tag) => tag.length > 0),
|
||||||
),
|
),
|
||||||
|
platform: z.enum(MiiPlatform, { error: "Platform must be either 'THREE_DS', or 'SWITCH'" }).optional(),
|
||||||
gender: z.enum(MiiGender, { error: "Gender must be either 'MALE', or 'FEMALE'" }).optional(),
|
gender: z.enum(MiiGender, { error: "Gender must be either 'MALE', or 'FEMALE'" }).optional(),
|
||||||
allowCopying: z.coerce.boolean({ error: "Allow Copying must be either true or false" }).optional(),
|
allowCopying: z.coerce.boolean({ error: "Allow Copying must be either true or false" }).optional(),
|
||||||
// todo: incorporate tagsSchema
|
// todo: incorporate tagsSchema
|
||||||
|
|
|
||||||