added linting

added linting
This commit is contained in:
2024-05-16 16:59:25 +07:00
parent d125687536
commit 5c4abf24bb
15 changed files with 1759 additions and 71 deletions

8
.eslintrc.json Normal file
View File

@@ -0,0 +1,8 @@
{
"extends": [
"next/core-web-vitals",
"next",
"prettier",
"plugin:prettier/recommended"
]
}

View File

@@ -1,9 +1,8 @@
"use client"; "use client";
import { LocationContext } from "@/components/locationContenxt"; import { LocationContext } from "@/components/locationContext";
import { useContext, useEffect, useState } from "react"; import { useContext, useState } from "react";
import Grouping from "./Grouping"; import Grouping from "./Grouping";
import { unique } from "drizzle-orm/mysql-core";
type Props = { type Props = {
allJobs: JobCategory[]; allJobs: JobCategory[];
@@ -22,7 +21,7 @@ export default function GroupCreator({ allJobs }: Props) {
let locationContext = useContext(LocationContext); let locationContext = useContext(LocationContext);
let [usedJobs, setUsedJobs] = useState<number[]>([]); let [usedJobs, setUsedJobs] = useState<number[]>([]);
let [groups, setGroup] = useState<Group[]>( let [groups, setGroup] = useState<Group[]>(
[...Array(4).keys()].map((i) => ({ id: i + 1, jobs: [] })) [...Array(4).keys()].map((i) => ({ id: i + 1, jobs: [] })),
); );
function useJob(id: number) { function useJob(id: number) {
setUsedJobs((u) => [...u, id]); setUsedJobs((u) => [...u, id]);
@@ -37,13 +36,11 @@ export default function GroupCreator({ allJobs }: Props) {
groups.map((g) => { groups.map((g) => {
if (g.id != id) return g; if (g.id != id) return g;
else return { id, jobs }; else return { id, jobs };
}) }),
); );
} }
useEffect(() => { function submit() {} //TODO! submit group
console.log(groups);
}, [groups]);
if ( if (
locationContext?.zone[0] == undefined || locationContext?.zone[0] == undefined ||
@@ -66,7 +63,9 @@ export default function GroupCreator({ allJobs }: Props) {
))} ))}
<div className="flex justify-center"> <div className="flex justify-center">
<button className="bg-green-300 rounded-md p-2"></button> <button className="rounded-md bg-green-300 p-2" onClick={submit}>
</button>
</div> </div>
</div> </div>
); );

View File

@@ -28,9 +28,9 @@ export default function Grouping({
} }
useEffect(() => { useEffect(() => {
updateGroup(selectedJob.map((j) => j.id)); updateGroup(selectedJob.map((j) => j.id));
}, [selectedJob]); }, [selectedJob, updateGroup]);
return ( return (
<div className="flex flex-col gap-2 m-2 p-2 border-black rounded-md shadow-md border w-full"> <div className="m-2 flex w-full flex-col gap-2 rounded-md border border-black p-2 shadow-md">
{selectedJob.map((j) => ( {selectedJob.map((j) => (
<div className="flex justify-between gap-2 p-2" key={j.id}> <div className="flex justify-between gap-2 p-2" key={j.id}>
<p>{j.name}</p> <p>{j.name}</p>

View File

@@ -1,6 +1,6 @@
import { db } from "@/src/db"; import { db } from "@/src/db";
import LocationSelector from "../../components/LocationSelector"; import LocationSelector from "../../components/LocationSelector";
import LocationContextProvider from "@/components/locationContenxt"; import LocationContextProvider from "@/components/locationContext";
import GroupCreator from "./GroupCreator"; import GroupCreator from "./GroupCreator";
export default async function Page() { export default async function Page() {

View File

@@ -14,7 +14,7 @@ export default function IdComponent({ updateIdList }: Props) {
}; };
useEffect(() => { useEffect(() => {
updateIdList([...idSet]); updateIdList([...idSet]);
}, [idSet]); }, [idSet, updateIdList]);
return ( return (
<div className="flex justify-center"> <div className="flex justify-center">
<div className="flex flex-col gap-2"> <div className="flex flex-col gap-2">
@@ -37,7 +37,7 @@ function FixedId({ cid, removeCid }: FixedIdProps) {
<div className="flex gap-2"> <div className="flex gap-2">
<input type="text" className="border-2" disabled value={cid} /> <input type="text" className="border-2" disabled value={cid} />
<button <button
className="bg-red-300 p-2 rounded-md" className="rounded-md bg-red-300 p-2"
onClick={() => removeCid(cid)} onClick={() => removeCid(cid)}
> >
@@ -61,7 +61,7 @@ function SingleIdComponent({ onValidId }: SingleIdProps) {
setCid(""); setCid("");
} }
}, [cid]); }, [cid, onValidId]);
return ( return (
<div className="flex gap-2"> <div className="flex gap-2">
<input <input

View File

@@ -4,15 +4,13 @@ import IdComponent from "./IdComponent";
export default function Page() { export default function Page() {
let [idList, setIdList] = useState<string[]>([]); let [idList, setIdList] = useState<string[]>([]);
function submit() { function submit() {} //TODO! submit inside user
console.log(idList);
}
return ( return (
<div> <div>
<IdComponent updateIdList={(cids) => setIdList(cids)} /> <IdComponent updateIdList={(cids) => setIdList(cids)} />
<p className="flex justify-center gap-4 mt-2 items-center"> <p className="mt-2 flex items-center justify-center gap-4">
Total: {idList.length}{" "} Total: {idList.length}{" "}
<button className="bg-green-200 p-2 rounded-md" onClick={submit}> <button className="rounded-md bg-green-200 p-2" onClick={submit}>
Submit Submit
</button> </button>
</p> </p>

View File

@@ -1,7 +1,7 @@
"use client"; "use client";
import { useContext, useEffect, useState } from "react"; import { useContext, useEffect, useState } from "react";
import { LocationContext } from "../locationContenxt"; import { LocationContext } from "../locationContext";
type Props = { type Props = {
provinces: Province[]; provinces: Province[];
@@ -43,7 +43,7 @@ export default function LocationSelector({ provinces }: Props) {
locationContext.zone[1](amphurId); locationContext.zone[1](amphurId);
locationContext.province[1](provinceId); locationContext.province[1](provinceId);
}, [amphurId]); }, [amphurId, locationContext, provinceId]);
return ( return (
<div className="flex flex-col gap-2"> <div className="flex flex-col gap-2">
<div className="flex gap-2"> <div className="flex gap-2">

View File

@@ -13,7 +13,7 @@ type LocationContextType = {
}; };
export const LocationContext = createContext<LocationContextType | undefined>( export const LocationContext = createContext<LocationContextType | undefined>(
undefined undefined,
); );
export default function LocationContextProvider({ export default function LocationContextProvider({

View File

@@ -9,6 +9,7 @@
"next-dev": "next dev", "next-dev": "next dev",
"start": "node dist/src/app.js", "start": "node dist/src/app.js",
"build": "swc src -d dist", "build": "swc src -d dist",
"lint": "next lint",
"initialize_data": "node -r @swc-node/register addMetadata.ts" "initialize_data": "node -r @swc-node/register addMetadata.ts"
}, },
"keywords": [], "keywords": [],
@@ -41,8 +42,14 @@
"@types/jsonwebtoken": "^9.0.6", "@types/jsonwebtoken": "^9.0.6",
"autoprefixer": "^10.4.19", "autoprefixer": "^10.4.19",
"drizzle-kit": "^0.20.14", "drizzle-kit": "^0.20.14",
"eslint": "^8",
"eslint-config-next": "14.2.3",
"eslint-config-prettier": "^9.1.0",
"eslint-plugin-prettier": "^5.1.3",
"nodemon": "^3.1.0", "nodemon": "^3.1.0",
"postcss": "^8.4.38", "postcss": "^8.4.38",
"prettier": "^3.2.5",
"prettier-plugin-tailwindcss": "^0.5.14",
"tailwindcss": "^3.4.3", "tailwindcss": "^3.4.3",
"ts-node": "^10.9.2", "ts-node": "^10.9.2",
"typescript": "^5.4.5" "typescript": "^5.4.5"

1720
pnpm-lock.yaml generated

File diff suppressed because it is too large Load Diff

6
prettier.config.mjs Normal file
View File

@@ -0,0 +1,6 @@
/** @type {import("prettier").Config} */
const config = {
plugins: ["prettier-plugin-tailwindcss"],
};
export default config;

View File

@@ -16,7 +16,7 @@ export function createClient() {
export async function createUploadImageUrl( export async function createUploadImageUrl(
mc: minio.Client, mc: minio.Client,
objectName: string, objectName: string,
contentType: string contentType: string,
) { ) {
let policy = mc.newPostPolicy(); let policy = mc.newPostPolicy();
policy.setKey(objectName); policy.setKey(objectName);

View File

@@ -15,7 +15,7 @@ export const runPlayground = async (appRouter: AppRouter) => {
trpcApiEndpoint, trpcApiEndpoint,
playgroundEndpoint, playgroundEndpoint,
router: appRouter, router: appRouter,
}) }),
); );
app.listen(3001, () => { app.listen(3001, () => {

View File

@@ -41,7 +41,7 @@ export const user = sqliteTable(
(t) => ({ (t) => ({
phone_idx: index("phone_idx").on(t.phone), phone_idx: index("phone_idx").on(t.phone),
image_idx: index("image_idx").on(t.image), image_idx: index("image_idx").on(t.image),
}) }),
); );
export const userRelation = relations(user, ({ many, one }) => ({ export const userRelation = relations(user, ({ many, one }) => ({
@@ -98,7 +98,7 @@ export const userOpinion = sqliteTable(
}, },
(t) => ({ (t) => ({
pk: primaryKey({ columns: [t.userId, t.opinionId] }), pk: primaryKey({ columns: [t.userId, t.opinionId] }),
}) }),
); );
export const userOpinionRelation = relations(userOpinion, ({ one }) => ({ export const userOpinionRelation = relations(userOpinion, ({ one }) => ({
@@ -118,7 +118,7 @@ export const zone = sqliteTable(
.notNull() .notNull()
.references(() => province.id), .references(() => province.id),
}, },
(t) => ({ unique_name_province: unique().on(t.name, t.province) }) (t) => ({ unique_name_province: unique().on(t.name, t.province) }),
); );
export const zoneRelation = relations(zone, ({ one }) => ({ export const zoneRelation = relations(zone, ({ one }) => ({
province: one(province, { province: one(province, {
@@ -144,6 +144,6 @@ export const imageToUser = sqliteTable("image_to_user", {
.references(() => user.id), .references(() => user.id),
imageName: text("image_name").notNull(), imageName: text("image_name").notNull(),
createdOn: integer("created_on", { mode: "timestamp" }).default( createdOn: integer("created_on", { mode: "timestamp" }).default(
sql`CURRENT_TIMESTAMP` sql`CURRENT_TIMESTAMP`,
), ),
}); });

View File

@@ -47,10 +47,10 @@ export const userRoute = router({
.input( .input(
userInsertSchema.omit({ id: true }).extend({ userInsertSchema.omit({ id: true }).extend({
opinions: opinionInsertSchema, opinions: opinionInsertSchema,
}) }),
) )
.mutation( .mutation(
async ({ input }) => await createUser({ ...input }, input.opinions) async ({ input }) => await createUser({ ...input }, input.opinions),
), ),
// changeImage: protectedProcedure // changeImage: protectedProcedure
updateUser: protectedProcedure updateUser: protectedProcedure
@@ -60,7 +60,7 @@ export const userRoute = router({
.input(z.object({ userId: z.number() })) .input(z.object({ userId: z.number() }))
.mutation(async ({ input }) => await getUser(input.userId, false)), .mutation(async ({ input }) => await getUser(input.userId, false)),
getSelf: protectedProcedure.mutation( getSelf: protectedProcedure.mutation(
async ({ ctx }) => await getUser(ctx.user.id, true) async ({ ctx }) => await getUser(ctx.user.id, true),
), ),
login: publicProcedure login: publicProcedure
.input(z.object({ cid: z.string(), phone: z.string() })) .input(z.object({ cid: z.string(), phone: z.string() }))
@@ -69,7 +69,7 @@ export const userRoute = router({
.input(opinionUpdateSchema) .input(opinionUpdateSchema)
.mutation( .mutation(
async ({ input, ctx }) => async ({ input, ctx }) =>
await changeOpinion(input.opinionId, ctx.user.id, input.choice) await changeOpinion(input.opinionId, ctx.user.id, input.choice),
), ),
requestChangeImage: protectedProcedure requestChangeImage: protectedProcedure
.input(z.object({ imageName: z.string(), contentType: z.string() })) .input(z.object({ imageName: z.string(), contentType: z.string() }))
@@ -78,11 +78,11 @@ export const userRoute = router({
await requestChangeImage( await requestChangeImage(
ctx.user.id, ctx.user.id,
input.imageName, input.imageName,
input.contentType input.contentType,
) ),
), ),
confirmChangeImage: protectedProcedure.mutation( confirmChangeImage: protectedProcedure.mutation(
async ({ ctx }) => await confirmChangeImage(ctx.user.id, ctx.user.image) async ({ ctx }) => await confirmChangeImage(ctx.user.id, ctx.user.image),
), ),
getAllUser: protectedProcedure getAllUser: protectedProcedure
.input( .input(
@@ -93,7 +93,7 @@ export const userRoute = router({
zone: z.number().optional(), zone: z.number().optional(),
opinionCount: z.number().default(3), opinionCount: z.number().default(3),
province: z.number().optional(), province: z.number().optional(),
}) }),
) )
.query( .query(
async ({ input }) => async ({ input }) =>
@@ -103,8 +103,8 @@ export const userRoute = router({
input.opinionCount, input.opinionCount,
input.group, input.group,
input.zone, input.zone,
input.province input.province,
) ),
), ),
getAllUserCount: protectedProcedure getAllUserCount: protectedProcedure
.input( .input(
@@ -112,18 +112,18 @@ export const userRoute = router({
group: z.number().optional(), group: z.number().optional(),
zone: z.number().optional(), zone: z.number().optional(),
province: z.number().optional(), province: z.number().optional(),
}) }),
) )
.query( .query(
async ({ input }) => async ({ input }) =>
await getAllUserCount(input.group, input.zone, input.province) await getAllUserCount(input.group, input.zone, input.province),
), ),
}); });
async function getAllUserCount( async function getAllUserCount(
group?: number, group?: number,
zoneId?: number, zoneId?: number,
provinceId?: number provinceId?: number,
) { ) {
let zoneIds: number[] = await getZone(provinceId); let zoneIds: number[] = await getZone(provinceId);
if (provinceId && zoneIds.length === 0) { if (provinceId && zoneIds.length === 0) {
@@ -152,7 +152,7 @@ async function getAllUser(
opinionLimit: number, opinionLimit: number,
group?: number, group?: number,
zoneId?: number, zoneId?: number,
provinceId?: number provinceId?: number,
) { ) {
let zoneIds: number[] = await getZone(provinceId); let zoneIds: number[] = await getZone(provinceId);
if (provinceId && zoneIds.length === 0) { if (provinceId && zoneIds.length === 0) {
@@ -221,7 +221,7 @@ async function getUser(userId: number, showPhone: boolean) {
async function createUser( async function createUser(
newUser: UserInsertSchema, newUser: UserInsertSchema,
opinions: OpinionInsertSchema opinions: OpinionInsertSchema,
) { ) {
try { try {
let result = ( let result = (
@@ -264,7 +264,7 @@ async function login(cid: string, phone: string) {
async function changeOpinion( async function changeOpinion(
opinionId: number, opinionId: number,
userId: number, userId: number,
opinionChoice: OpinionInsertSchema[0]["choice"] opinionChoice: OpinionInsertSchema[0]["choice"],
) { ) {
try { try {
let thisOpinion = await db let thisOpinion = await db
@@ -308,7 +308,7 @@ async function changeOpinion(
async function requestChangeImage( async function requestChangeImage(
userId: number, userId: number,
imageName: string, imageName: string,
contentType: string contentType: string,
) { ) {
const mc = createClient(); const mc = createClient();
// Check if the image is valid // Check if the image is valid