From a0b900559c3509a6eb77bb9c757b42bc70ebe244 Mon Sep 17 00:00:00 2001 From: croumegous Date: Sat, 31 Dec 2022 12:59:35 +0100 Subject: [PATCH 1/8] chore: eslint plugins to sort import and remove unused import automatically --- website/.eslintrc.json | 17 +++++- website/package-lock.json | 61 +++++++++++++++++++ website/package.json | 7 ++- website/src/components/Container.cy.tsx | 1 + website/src/components/Faq.tsx | 2 - website/src/components/Footer.tsx | 1 + website/src/components/Header/Header.tsx | 9 ++- website/src/components/Header/NavLinks.tsx | 4 +- website/src/components/Header/UserMenu.tsx | 6 +- website/src/components/Header/index.ts | 2 +- website/src/components/Hero.tsx | 2 +- website/src/components/Layout.tsx | 2 +- website/src/components/Sortable/Sortable.tsx | 9 +-- .../src/components/Sortable/SortableItem.tsx | 2 +- .../TaskSelection/TaskSelection.tsx | 5 +- website/src/components/TaskSelection/index.ts | 4 +- website/src/pages/404.tsx | 4 -- website/src/pages/_app.tsx | 15 +++-- website/src/pages/account/edit.tsx | 6 +- website/src/pages/account/index.tsx | 4 +- website/src/pages/api/auth/[...nextauth].ts | 12 ++-- website/src/pages/api/new_task/[task_type].ts | 2 - website/src/pages/api/update_task.ts | 2 - website/src/pages/api/username.tsx | 2 - website/src/pages/auth/signin.tsx | 5 +- website/src/pages/auth/verify.tsx | 4 +- website/src/pages/create/assistant_reply.tsx | 18 +++--- website/src/pages/create/summarize_story.tsx | 16 +++-- website/src/pages/create/user_reply.tsx | 14 ++--- .../pages/evaluate/rank_assistant_replies.tsx | 16 +++-- .../pages/evaluate/rank_initial_prompts.tsx | 14 ++--- .../src/pages/evaluate/rank_user_replies.tsx | 16 +++-- website/src/pages/evaluate/rate_summary.tsx | 18 +++--- website/src/pages/index.tsx | 5 +- .../pages/leaderboard/score-leaderboard.tsx | 2 +- 35 files changed, 179 insertions(+), 130 deletions(-) diff --git a/website/.eslintrc.json b/website/.eslintrc.json index 95127c06..b2253ce8 100644 --- a/website/.eslintrc.json +++ b/website/.eslintrc.json @@ -6,6 +6,19 @@ "next/core-web-vitals" ], "rules": { - "sort-imports": "warn" - } + "simple-import-sort/imports": "error", + "simple-import-sort/exports": "error", + "@typescript-eslint/no-unused-vars": "off", + "unused-imports/no-unused-imports": "error", + "unused-imports/no-unused-vars": [ + "warn", + { + "vars": "all", + "varsIgnorePattern": "^_", + "args": "after-used", + "argsIgnorePattern": "^_" + } + ] + }, + "plugins": ["simple-import-sort", "unused-imports"] } diff --git a/website/package-lock.json b/website/package-lock.json index c67880f1..1896ff26 100644 --- a/website/package-lock.json +++ b/website/package-lock.json @@ -24,6 +24,7 @@ "clsx": "^1.2.1", "eslint": "8.29.0", "eslint-config-next": "13.0.6", + "eslint-plugin-simple-import-sort": "^8.0.0", "focus-visible": "^5.2.0", "framer-motion": "^6.5.1", "next": "13.0.6", @@ -57,6 +58,7 @@ "cypress": "^12.2.0", "cypress-image-diff-js": "^1.23.0", "eslint-plugin-storybook": "^0.6.8", + "eslint-plugin-unused-imports": "^2.0.0", "prettier": "2.8.1", "prisma": "^4.7.1", "typescript": "4.9.4" @@ -16344,6 +16346,14 @@ "url": "https://github.com/sponsors/ljharb" } }, + "node_modules/eslint-plugin-simple-import-sort": { + "version": "8.0.0", + "resolved": "https://registry.npmjs.org/eslint-plugin-simple-import-sort/-/eslint-plugin-simple-import-sort-8.0.0.tgz", + "integrity": "sha512-bXgJQ+lqhtQBCuWY/FUWdB27j4+lqcvXv5rUARkzbeWLwea+S5eBZEQrhnO+WgX3ZoJHVj0cn943iyXwByHHQw==", + "peerDependencies": { + "eslint": ">=5.0.0" + } + }, "node_modules/eslint-plugin-storybook": { "version": "0.6.8", "resolved": "https://registry.npmjs.org/eslint-plugin-storybook/-/eslint-plugin-storybook-0.6.8.tgz", @@ -16371,6 +16381,36 @@ "lodash": "^4.17.15" } }, + "node_modules/eslint-plugin-unused-imports": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/eslint-plugin-unused-imports/-/eslint-plugin-unused-imports-2.0.0.tgz", + "integrity": "sha512-3APeS/tQlTrFa167ThtP0Zm0vctjr4M44HMpeg1P4bK6wItarumq0Ma82xorMKdFsWpphQBlRPzw/pxiVELX1A==", + "dev": true, + "dependencies": { + "eslint-rule-composer": "^0.3.0" + }, + "engines": { + "node": "^12.22.0 || ^14.17.0 || >=16.0.0" + }, + "peerDependencies": { + "@typescript-eslint/eslint-plugin": "^5.0.0", + "eslint": "^8.0.0" + }, + "peerDependenciesMeta": { + "@typescript-eslint/eslint-plugin": { + "optional": true + } + } + }, + "node_modules/eslint-rule-composer": { + "version": "0.3.0", + "resolved": "https://registry.npmjs.org/eslint-rule-composer/-/eslint-rule-composer-0.3.0.tgz", + "integrity": "sha512-bt+Sh8CtDmn2OajxvNO+BX7Wn4CIWMpTRm3MaiKPCQcnnlm0CS2mhui6QaoeQugs+3Kj2ESKEEGJUdVafwhiCg==", + "dev": true, + "engines": { + "node": ">=4.0.0" + } + }, "node_modules/eslint-scope": { "version": "5.1.1", "resolved": "https://registry.npmjs.org/eslint-scope/-/eslint-scope-5.1.1.tgz", @@ -40976,6 +41016,12 @@ "integrity": "sha512-oFc7Itz9Qxh2x4gNHStv3BqJq54ExXmfC+a1NjAta66IAN87Wu0R/QArgIS9qKzX3dXKPI9H5crl9QchNMY9+g==", "requires": {} }, + "eslint-plugin-simple-import-sort": { + "version": "8.0.0", + "resolved": "https://registry.npmjs.org/eslint-plugin-simple-import-sort/-/eslint-plugin-simple-import-sort-8.0.0.tgz", + "integrity": "sha512-bXgJQ+lqhtQBCuWY/FUWdB27j4+lqcvXv5rUARkzbeWLwea+S5eBZEQrhnO+WgX3ZoJHVj0cn943iyXwByHHQw==", + "requires": {} + }, "eslint-plugin-storybook": { "version": "0.6.8", "resolved": "https://registry.npmjs.org/eslint-plugin-storybook/-/eslint-plugin-storybook-0.6.8.tgz", @@ -40999,6 +41045,21 @@ } } }, + "eslint-plugin-unused-imports": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/eslint-plugin-unused-imports/-/eslint-plugin-unused-imports-2.0.0.tgz", + "integrity": "sha512-3APeS/tQlTrFa167ThtP0Zm0vctjr4M44HMpeg1P4bK6wItarumq0Ma82xorMKdFsWpphQBlRPzw/pxiVELX1A==", + "dev": true, + "requires": { + "eslint-rule-composer": "^0.3.0" + } + }, + "eslint-rule-composer": { + "version": "0.3.0", + "resolved": "https://registry.npmjs.org/eslint-rule-composer/-/eslint-rule-composer-0.3.0.tgz", + "integrity": "sha512-bt+Sh8CtDmn2OajxvNO+BX7Wn4CIWMpTRm3MaiKPCQcnnlm0CS2mhui6QaoeQugs+3Kj2ESKEEGJUdVafwhiCg==", + "dev": true + }, "eslint-scope": { "version": "5.1.1", "resolved": "https://registry.npmjs.org/eslint-scope/-/eslint-scope-5.1.1.tgz", diff --git a/website/package.json b/website/package.json index 87e4ebeb..98f18965 100644 --- a/website/package.json +++ b/website/package.json @@ -12,7 +12,10 @@ "build-storybook": "build-storybook", "cypress": "cypress open", "cypress:run": "cypress run", - "cypress:image-baseline": "cypress-image-diff -u" + "cypress:image-baseline": "cypress-image-diff -u", + "fix:lint": "eslint --fix src/", + "fix:format": "prettier --write ./src", + "fix": "npm run fix:lint && npm run fix:format" }, "dependencies": { "@chakra-ui/react": "^2.4.4", @@ -31,6 +34,7 @@ "clsx": "^1.2.1", "eslint": "8.29.0", "eslint-config-next": "13.0.6", + "eslint-plugin-simple-import-sort": "^8.0.0", "focus-visible": "^5.2.0", "framer-motion": "^6.5.1", "next": "13.0.6", @@ -64,6 +68,7 @@ "cypress": "^12.2.0", "cypress-image-diff-js": "^1.23.0", "eslint-plugin-storybook": "^0.6.8", + "eslint-plugin-unused-imports": "^2.0.0", "prettier": "2.8.1", "prisma": "^4.7.1", "typescript": "4.9.4" diff --git a/website/src/components/Container.cy.tsx b/website/src/components/Container.cy.tsx index 5ffa204f..3e458307 100644 --- a/website/src/components/Container.cy.tsx +++ b/website/src/components/Container.cy.tsx @@ -1,4 +1,5 @@ import React from "react"; + import { Container } from "./Container"; describe("", () => { diff --git a/website/src/components/Faq.tsx b/website/src/components/Faq.tsx index d7c2eae9..8f42b920 100644 --- a/website/src/components/Faq.tsx +++ b/website/src/components/Faq.tsx @@ -1,5 +1,3 @@ -import Link from "next/link"; - import { Container } from "./Container"; const faqs = [ diff --git a/website/src/components/Footer.tsx b/website/src/components/Footer.tsx index 28765664..a07ba24a 100644 --- a/website/src/components/Footer.tsx +++ b/website/src/components/Footer.tsx @@ -1,5 +1,6 @@ import Image from "next/image"; import Link from "next/link"; + import { Container } from "./Container"; export function Footer() { diff --git a/website/src/components/Header/Header.tsx b/website/src/components/Header/Header.tsx index 7bf3b062..b1cbb94d 100644 --- a/website/src/components/Header/Header.tsx +++ b/website/src/components/Header/Header.tsx @@ -1,14 +1,13 @@ import { Button } from "@chakra-ui/react"; import { Popover } from "@headlessui/react"; +import clsx from "clsx"; import { AnimatePresence, motion } from "framer-motion"; import Image from "next/image"; import Link from "next/link"; - -import { signOut, useSession } from "next-auth/react"; -import { FaUser, FaSignOutAlt } from "react-icons/fa"; -import clsx from "clsx"; - +import { useSession } from "next-auth/react"; +import { FaUser } from "react-icons/fa"; import { Container } from "src/components/Container"; + import { NavLinks } from "./NavLinks"; import { UserMenu } from "./UserMenu"; diff --git a/website/src/components/Header/NavLinks.tsx b/website/src/components/Header/NavLinks.tsx index 955d92f8..3903c8b6 100644 --- a/website/src/components/Header/NavLinks.tsx +++ b/website/src/components/Header/NavLinks.tsx @@ -1,6 +1,6 @@ -import { useState } from "react"; -import Link from "next/link"; import { AnimatePresence, motion } from "framer-motion"; +import Link from "next/link"; +import { useState } from "react"; export function NavLinks(): JSX.Element { const [hoveredIndex, setHoveredIndex] = useState(null); diff --git a/website/src/components/Header/UserMenu.tsx b/website/src/components/Header/UserMenu.tsx index 3fe4d2da..8de54f3d 100644 --- a/website/src/components/Header/UserMenu.tsx +++ b/website/src/components/Header/UserMenu.tsx @@ -1,8 +1,8 @@ -import React from "react"; -import { signOut, useSession } from "next-auth/react"; -import Image from "next/image"; import { Popover } from "@headlessui/react"; import { AnimatePresence, motion } from "framer-motion"; +import Image from "next/image"; +import { signOut, useSession } from "next-auth/react"; +import React from "react"; import { FaCog, FaSignOutAlt } from "react-icons/fa"; export function UserMenu() { diff --git a/website/src/components/Header/index.ts b/website/src/components/Header/index.ts index 005784d9..3d5a7125 100644 --- a/website/src/components/Header/index.ts +++ b/website/src/components/Header/index.ts @@ -1,3 +1,3 @@ export { Header } from "./Header"; -export { UserMenu } from "./UserMenu"; export { NavLinks } from "./NavLinks"; +export { UserMenu } from "./UserMenu"; diff --git a/website/src/components/Hero.tsx b/website/src/components/Hero.tsx index 4f6bf4cb..3ddbc194 100644 --- a/website/src/components/Hero.tsx +++ b/website/src/components/Hero.tsx @@ -1,5 +1,5 @@ -import { useId } from "react"; import Image from "next/image"; +import { useId } from "react"; import { Container } from "./Container"; diff --git a/website/src/components/Layout.tsx b/website/src/components/Layout.tsx index 6cd08771..5f6f66b4 100644 --- a/website/src/components/Layout.tsx +++ b/website/src/components/Layout.tsx @@ -1,9 +1,9 @@ // https://nextjs.org/docs/basic-features/layouts import type { NextPage } from "next"; +import { Header } from "src/components/Header"; import { Footer } from "./Footer"; -import { Header } from "src/components/Header"; export type NextPageWithLayout

= NextPage & { getLayout?: (page: React.ReactElement) => React.ReactNode; diff --git a/website/src/components/Sortable/Sortable.tsx b/website/src/components/Sortable/Sortable.tsx index a86b957a..74ff1bb2 100644 --- a/website/src/components/Sortable/Sortable.tsx +++ b/website/src/components/Sortable/Sortable.tsx @@ -1,8 +1,9 @@ -import { DndContext, PointerSensor, TouchSensor, closestCenter, useSensor, useSensors } from "@dnd-kit/core"; -import { ReactNode, useEffect, useState } from "react"; -import { SortableContext, arrayMove, verticalListSortingStrategy } from "@dnd-kit/sortable"; -import type { DragEndEvent } from "@dnd-kit/core/dist/types/events"; import { Flex } from "@chakra-ui/react"; +import { closestCenter, DndContext, PointerSensor, TouchSensor, useSensor, useSensors } from "@dnd-kit/core"; +import type { DragEndEvent } from "@dnd-kit/core/dist/types/events"; +import { arrayMove, SortableContext, verticalListSortingStrategy } from "@dnd-kit/sortable"; +import { ReactNode, useEffect, useState } from "react"; + import { SortableItem } from "./SortableItem"; export interface SortableProps { diff --git a/website/src/components/Sortable/SortableItem.tsx b/website/src/components/Sortable/SortableItem.tsx index e6b1707f..244fc313 100644 --- a/website/src/components/Sortable/SortableItem.tsx +++ b/website/src/components/Sortable/SortableItem.tsx @@ -1,6 +1,6 @@ +import { useSortable } from "@dnd-kit/sortable"; import { CSS } from "@dnd-kit/utilities"; import { PropsWithChildren } from "react"; -import { useSortable } from "@dnd-kit/sortable"; export const SortableItem = ({ children, id }: PropsWithChildren<{ id: number }>) => { const { attributes, listeners, setNodeRef, transform, transition } = useSortable({ id }); diff --git a/website/src/components/TaskSelection/TaskSelection.tsx b/website/src/components/TaskSelection/TaskSelection.tsx index c4f14cde..7cb216c1 100644 --- a/website/src/components/TaskSelection/TaskSelection.tsx +++ b/website/src/components/TaskSelection/TaskSelection.tsx @@ -1,7 +1,8 @@ -import React from "react"; -import { TaskOptions } from "./TaskOptions"; import { Flex } from "@chakra-ui/react"; +import React from "react"; + import { TaskOption } from "./TaskOption"; +import { TaskOptions } from "./TaskOptions"; export const TaskSelection = () => { return ( diff --git a/website/src/components/TaskSelection/index.ts b/website/src/components/TaskSelection/index.ts index 4da7ea7f..d6d93973 100644 --- a/website/src/components/TaskSelection/index.ts +++ b/website/src/components/TaskSelection/index.ts @@ -1,3 +1,3 @@ -export { TaskSelection } from "./TaskSelection"; -export { TaskOptions } from "./TaskOptions"; export { TaskOption } from "./TaskOption"; +export { TaskOptions } from "./TaskOptions"; +export { TaskSelection } from "./TaskSelection"; diff --git a/website/src/pages/404.tsx b/website/src/pages/404.tsx index 2f464fa2..1eb600d7 100644 --- a/website/src/pages/404.tsx +++ b/website/src/pages/404.tsx @@ -1,8 +1,4 @@ -import { useSession } from "next-auth/react"; -import { Footer } from "../components/Footer"; -import { Header } from "src/components/Header"; import Head from "next/head"; -import Link from "next/link"; export default function Error() { return ( diff --git a/website/src/pages/_app.tsx b/website/src/pages/_app.tsx index 119f337b..b36e3392 100644 --- a/website/src/pages/_app.tsx +++ b/website/src/pages/_app.tsx @@ -1,14 +1,13 @@ -import { ChakraProvider } from "@chakra-ui/react"; -import { SessionProvider } from "next-auth/react"; -import { Inter } from "@next/font/google"; -import { extendTheme } from "@chakra-ui/react"; -import type { AppProps } from "next/app"; - -import { NextPageWithLayout, getDefaultLayout } from "src/components/Layout"; - import "../styles/globals.css"; import "focus-visible"; +import { ChakraProvider } from "@chakra-ui/react"; +import { extendTheme } from "@chakra-ui/react"; +import { Inter } from "@next/font/google"; +import type { AppProps } from "next/app"; +import { SessionProvider } from "next-auth/react"; +import { getDefaultLayout, NextPageWithLayout } from "src/components/Layout"; + const inter = Inter({ subsets: ["latin"], variable: "--font-inter", diff --git a/website/src/pages/account/edit.tsx b/website/src/pages/account/edit.tsx index d652ef8a..a14c27f8 100644 --- a/website/src/pages/account/edit.tsx +++ b/website/src/pages/account/edit.tsx @@ -1,8 +1,8 @@ -import React, { useState } from "react"; -import { useSession } from "next-auth/react"; -import { Button, Input, InputGroup, Stack } from "@chakra-ui/react"; +import { Button, Input, InputGroup } from "@chakra-ui/react"; import Head from "next/head"; import Router from "next/router"; +import { useSession } from "next-auth/react"; +import React, { useState } from "react"; export default function Account() { const { data: session } = useSession(); diff --git a/website/src/pages/account/index.tsx b/website/src/pages/account/index.tsx index 98bdc301..b5c9d906 100644 --- a/website/src/pages/account/index.tsx +++ b/website/src/pages/account/index.tsx @@ -1,8 +1,8 @@ +import { Button } from "@chakra-ui/react"; import Head from "next/head"; import Link from "next/link"; -import React, { useState } from "react"; import { useSession } from "next-auth/react"; -import { Button } from "@chakra-ui/react"; +import React, { useState } from "react"; export default function Account() { const { data: session } = useSession(); diff --git a/website/src/pages/api/auth/[...nextauth].ts b/website/src/pages/api/auth/[...nextauth].ts index e0d818c5..9bb993e5 100644 --- a/website/src/pages/api/auth/[...nextauth].ts +++ b/website/src/pages/api/auth/[...nextauth].ts @@ -1,12 +1,10 @@ -import type { AuthOptions } from "next-auth"; -import NextAuth from "next-auth"; -import { NextApiHandler } from "next"; -import DiscordProvider from "next-auth/providers/discord"; -import EmailProvider from "next-auth/providers/email"; -import CredentialsProvider from "next-auth/providers/credentials"; import { PrismaAdapter } from "@next-auth/prisma-adapter"; import { boolean } from "boolean"; - +import type { AuthOptions } from "next-auth"; +import NextAuth from "next-auth"; +import CredentialsProvider from "next-auth/providers/credentials"; +import DiscordProvider from "next-auth/providers/discord"; +import EmailProvider from "next-auth/providers/email"; import prisma from "src/lib/prismadb"; const providers = []; diff --git a/website/src/pages/api/new_task/[task_type].ts b/website/src/pages/api/new_task/[task_type].ts index 6c3eb01b..b07215cd 100644 --- a/website/src/pages/api/new_task/[task_type].ts +++ b/website/src/pages/api/new_task/[task_type].ts @@ -1,7 +1,5 @@ import { getToken } from "next-auth/jwt"; - import prisma from "src/lib/prismadb"; -import { authOptions } from "src/pages/api/auth/[...nextauth]"; /** * Returns a new task created from the Task Backend. We do a few things here: diff --git a/website/src/pages/api/update_task.ts b/website/src/pages/api/update_task.ts index 35de6542..ef0147df 100644 --- a/website/src/pages/api/update_task.ts +++ b/website/src/pages/api/update_task.ts @@ -1,7 +1,5 @@ import { getToken } from "next-auth/jwt"; - import prisma from "src/lib/prismadb"; -import { authOptions } from "src/pages/api/auth/[...nextauth]"; /** * Stores the task interaction with the Task Backend and then returns the next task generated. diff --git a/website/src/pages/api/username.tsx b/website/src/pages/api/username.tsx index a8aab7aa..36c8360e 100644 --- a/website/src/pages/api/username.tsx +++ b/website/src/pages/api/username.tsx @@ -1,6 +1,4 @@ import { getSession } from "next-auth/react"; -import { Prisma } from "@prisma/client"; -import Email from "next-auth/providers/email"; // POST /api/post // Required fields in body: title diff --git a/website/src/pages/auth/signin.tsx b/website/src/pages/auth/signin.tsx index 1f1b0323..bcb51835 100644 --- a/website/src/pages/auth/signin.tsx +++ b/website/src/pages/auth/signin.tsx @@ -1,10 +1,9 @@ import { Button, Input, Stack } from "@chakra-ui/react"; import Head from "next/head"; -import { FaDiscord, FaEnvelope, FaGithub, FaBug } from "react-icons/fa"; +import Link from "next/link"; import { getCsrfToken, getProviders, signIn } from "next-auth/react"; import React, { useRef } from "react"; -import Link from "next/link"; - +import { FaBug, FaDiscord, FaEnvelope, FaGithub } from "react-icons/fa"; import { AuthLayout } from "src/components/AuthLayout"; export default function Signin({ csrfToken, providers }) { diff --git a/website/src/pages/auth/verify.tsx b/website/src/pages/auth/verify.tsx index f22bea2d..cbf40241 100644 --- a/website/src/pages/auth/verify.tsx +++ b/website/src/pages/auth/verify.tsx @@ -1,7 +1,5 @@ import Head from "next/head"; -import { getCsrfToken, getProviders, signIn } from "next-auth/react"; -import Link from "next/link"; - +import { getCsrfToken, getProviders } from "next-auth/react"; import { AuthLayout } from "src/components/AuthLayout"; export default function Verify() { diff --git a/website/src/pages/create/assistant_reply.tsx b/website/src/pages/create/assistant_reply.tsx index ef4175db..d28a0ad0 100644 --- a/website/src/pages/create/assistant_reply.tsx +++ b/website/src/pages/create/assistant_reply.tsx @@ -1,17 +1,15 @@ import { Flex, Textarea } from "@chakra-ui/react"; import { useRef, useState } from "react"; -import useSWRMutation from "swr/mutation"; -import useSWRImmutable from "swr/immutable"; - -import fetcher from "src/lib/fetcher"; -import poster from "src/lib/poster"; - -import { Messages } from "src/components/Messages"; -import { TwoColumns } from "src/components/TwoColumns"; -import { LoadingScreen } from "src/components/Loading/LoadingScreen"; -import { TaskInfo } from "src/components/TaskInfo/TaskInfo"; import { SkipButton } from "src/components/Buttons/Skip"; import { SubmitButton } from "src/components/Buttons/Submit"; +import { LoadingScreen } from "src/components/Loading/LoadingScreen"; +import { Messages } from "src/components/Messages"; +import { TaskInfo } from "src/components/TaskInfo/TaskInfo"; +import { TwoColumns } from "src/components/TwoColumns"; +import fetcher from "src/lib/fetcher"; +import poster from "src/lib/poster"; +import useSWRImmutable from "swr/immutable"; +import useSWRMutation from "swr/mutation"; const AssistantReply = () => { const [tasks, setTasks] = useState([]); diff --git a/website/src/pages/create/summarize_story.tsx b/website/src/pages/create/summarize_story.tsx index 77b03d1d..8746b03e 100644 --- a/website/src/pages/create/summarize_story.tsx +++ b/website/src/pages/create/summarize_story.tsx @@ -1,17 +1,15 @@ import { Flex, Textarea } from "@chakra-ui/react"; import Head from "next/head"; import { useRef, useState } from "react"; -import useSWRImmutable from "swr/immutable"; -import useSWRMutation from "swr/mutation"; - -import fetcher from "src/lib/fetcher"; -import poster from "src/lib/poster"; - -import { LoadingScreen } from "src/components/Loading/LoadingScreen"; -import { TwoColumns } from "src/components/TwoColumns"; -import { TaskInfo } from "src/components/TaskInfo/TaskInfo"; import { SkipButton } from "src/components/Buttons/Skip"; import { SubmitButton } from "src/components/Buttons/Submit"; +import { LoadingScreen } from "src/components/Loading/LoadingScreen"; +import { TaskInfo } from "src/components/TaskInfo/TaskInfo"; +import { TwoColumns } from "src/components/TwoColumns"; +import fetcher from "src/lib/fetcher"; +import poster from "src/lib/poster"; +import useSWRImmutable from "swr/immutable"; +import useSWRMutation from "swr/mutation"; const SummarizeStory = () => { // Use an array of tasks that record the sequence of steps until a task is diff --git a/website/src/pages/create/user_reply.tsx b/website/src/pages/create/user_reply.tsx index 89d17e4f..36c912d5 100644 --- a/website/src/pages/create/user_reply.tsx +++ b/website/src/pages/create/user_reply.tsx @@ -1,17 +1,15 @@ import { Flex, Textarea } from "@chakra-ui/react"; import { useRef, useState } from "react"; -import useSWRMutation from "swr/mutation"; -import useSWRImmutable from "swr/immutable"; - -import fetcher from "src/lib/fetcher"; -import poster from "src/lib/poster"; - +import { SkipButton } from "src/components/Buttons/Skip"; +import { SubmitButton } from "src/components/Buttons/Submit"; import { LoadingScreen } from "src/components/Loading/LoadingScreen"; import { Messages } from "src/components/Messages"; import { TaskInfo } from "src/components/TaskInfo/TaskInfo"; import { TwoColumns } from "src/components/TwoColumns"; -import { SkipButton } from "src/components/Buttons/Skip"; -import { SubmitButton } from "src/components/Buttons/Submit"; +import fetcher from "src/lib/fetcher"; +import poster from "src/lib/poster"; +import useSWRImmutable from "swr/immutable"; +import useSWRMutation from "swr/mutation"; const UserReply = () => { const [tasks, setTasks] = useState([]); diff --git a/website/src/pages/evaluate/rank_assistant_replies.tsx b/website/src/pages/evaluate/rank_assistant_replies.tsx index e2b89d90..cd6d7811 100644 --- a/website/src/pages/evaluate/rank_assistant_replies.tsx +++ b/website/src/pages/evaluate/rank_assistant_replies.tsx @@ -1,17 +1,15 @@ -import { Button, Flex } from "@chakra-ui/react"; +import { Flex } from "@chakra-ui/react"; import Head from "next/head"; import { useState } from "react"; -import useSWRImmutable from "swr/immutable"; -import useSWRMutation from "swr/mutation"; - -import fetcher from "src/lib/fetcher"; -import poster from "src/lib/poster"; - +import { SkipButton } from "src/components/Buttons/Skip"; +import { SubmitButton } from "src/components/Buttons/Submit"; import { LoadingScreen } from "src/components/Loading/LoadingScreen"; import { Sortable } from "src/components/Sortable/Sortable"; import { TaskInfo } from "src/components/TaskInfo/TaskInfo"; -import { SubmitButton } from "src/components/Buttons/Submit"; -import { SkipButton } from "src/components/Buttons/Skip"; +import fetcher from "src/lib/fetcher"; +import poster from "src/lib/poster"; +import useSWRImmutable from "swr/immutable"; +import useSWRMutation from "swr/mutation"; const RankAssistantReplies = () => { const [tasks, setTasks] = useState([]); diff --git a/website/src/pages/evaluate/rank_initial_prompts.tsx b/website/src/pages/evaluate/rank_initial_prompts.tsx index a71b223e..4f236b50 100644 --- a/website/src/pages/evaluate/rank_initial_prompts.tsx +++ b/website/src/pages/evaluate/rank_initial_prompts.tsx @@ -1,17 +1,15 @@ import { Flex } from "@chakra-ui/react"; import Head from "next/head"; import { useState } from "react"; -import useSWRImmutable from "swr/immutable"; -import useSWRMutation from "swr/mutation"; - -import fetcher from "src/lib/fetcher"; -import poster from "src/lib/poster"; - +import { SkipButton } from "src/components/Buttons/Skip"; +import { SubmitButton } from "src/components/Buttons/Submit"; import { LoadingScreen } from "src/components/Loading/LoadingScreen"; import { Sortable } from "src/components/Sortable/Sortable"; import { TaskInfo } from "src/components/TaskInfo/TaskInfo"; -import { SkipButton } from "src/components/Buttons/Skip"; -import { SubmitButton } from "src/components/Buttons/Submit"; +import fetcher from "src/lib/fetcher"; +import poster from "src/lib/poster"; +import useSWRImmutable from "swr/immutable"; +import useSWRMutation from "swr/mutation"; const RankInitialPrompts = () => { const [tasks, setTasks] = useState([]); diff --git a/website/src/pages/evaluate/rank_user_replies.tsx b/website/src/pages/evaluate/rank_user_replies.tsx index 1d16b55f..b67fda10 100644 --- a/website/src/pages/evaluate/rank_user_replies.tsx +++ b/website/src/pages/evaluate/rank_user_replies.tsx @@ -1,17 +1,15 @@ +import { Flex } from "@chakra-ui/react"; import Head from "next/head"; import { useState } from "react"; -import useSWRImmutable from "swr/immutable"; -import useSWRMutation from "swr/mutation"; - -import fetcher from "src/lib/fetcher"; -import poster from "src/lib/poster"; - +import { SkipButton } from "src/components/Buttons/Skip"; +import { SubmitButton } from "src/components/Buttons/Submit"; import { LoadingScreen } from "src/components/Loading/LoadingScreen"; import { Sortable } from "src/components/Sortable/Sortable"; import { TaskInfo } from "src/components/TaskInfo/TaskInfo"; -import { Flex } from "@chakra-ui/react"; -import { SkipButton } from "src/components/Buttons/Skip"; -import { SubmitButton } from "src/components/Buttons/Submit"; +import fetcher from "src/lib/fetcher"; +import poster from "src/lib/poster"; +import useSWRImmutable from "swr/immutable"; +import useSWRMutation from "swr/mutation"; const RankUserReplies = () => { const [tasks, setTasks] = useState([]); diff --git a/website/src/pages/evaluate/rate_summary.tsx b/website/src/pages/evaluate/rate_summary.tsx index c3d7509d..f11e19f6 100644 --- a/website/src/pages/evaluate/rate_summary.tsx +++ b/website/src/pages/evaluate/rate_summary.tsx @@ -2,18 +2,16 @@ import { Flex, Textarea } from "@chakra-ui/react"; import { QuestionMarkCircleIcon } from "@heroicons/react/20/solid"; import Head from "next/head"; import { useState } from "react"; -import useSWRImmutable from "swr/immutable"; -import useSWRMutation from "swr/mutation"; - -import RatingRadioGroup from "src/components/RatingRadioGroup"; -import fetcher from "src/lib/fetcher"; -import poster from "src/lib/poster"; - -import { LoadingScreen } from "src/components/Loading/LoadingScreen"; -import { TwoColumns } from "src/components/TwoColumns"; -import { TaskInfo } from "src/components/TaskInfo/TaskInfo"; import { SkipButton } from "src/components/Buttons/Skip"; import { SubmitButton } from "src/components/Buttons/Submit"; +import { LoadingScreen } from "src/components/Loading/LoadingScreen"; +import RatingRadioGroup from "src/components/RatingRadioGroup"; +import { TaskInfo } from "src/components/TaskInfo/TaskInfo"; +import { TwoColumns } from "src/components/TwoColumns"; +import fetcher from "src/lib/fetcher"; +import poster from "src/lib/poster"; +import useSWRImmutable from "swr/immutable"; +import useSWRMutation from "swr/mutation"; const RateSummary = () => { // Use an array of tasks that record the sequence of steps until a task is diff --git a/website/src/pages/index.tsx b/website/src/pages/index.tsx index 61dea8e9..722abd35 100644 --- a/website/src/pages/index.tsx +++ b/website/src/pages/index.tsx @@ -1,12 +1,11 @@ import Head from "next/head"; import { useSession } from "next-auth/react"; - import { CallToAction } from "src/components/CallToAction"; import { Faq } from "src/components/Faq"; +import { Footer } from "src/components/Footer"; +import { Header } from "src/components/Header"; import { Hero } from "src/components/Hero"; import { TaskSelection } from "src/components/TaskSelection"; -import { Header } from "src/components/Header"; -import { Footer } from "src/components/Footer"; const Home = () => { const { data: session } = useSession(); diff --git a/website/src/pages/leaderboard/score-leaderboard.tsx b/website/src/pages/leaderboard/score-leaderboard.tsx index 495c1c35..231c9e71 100644 --- a/website/src/pages/leaderboard/score-leaderboard.tsx +++ b/website/src/pages/leaderboard/score-leaderboard.tsx @@ -1,5 +1,5 @@ -import RankItem from "src/components/RankItem"; import { HiBarsArrowDown } from "react-icons/hi2"; +import RankItem from "src/components/RankItem"; const LeaderBoard = () => { const PlaceHolderProps = { username: "test_user", score: 10 }; From 8c79cadbb1117e1946e224d83139824e7e6725ad Mon Sep 17 00:00:00 2001 From: croumegous Date: Sat, 31 Dec 2022 13:32:22 +0100 Subject: [PATCH 2/8] chore: manually fix linter warning --- website/.eslintrc.json | 16 +++------------- website/package.json | 4 ++-- website/src/components/Header/Header.stories.jsx | 1 + .../src/components/Header/NavLinks.stories.jsx | 1 + .../src/components/Header/UserMenu.stories.jsx | 1 + website/src/components/Header/UserMenu.tsx | 1 - .../src/components/Loading/Loading.stories.jsx | 1 + website/src/components/RankItem.tsx | 4 ++-- website/src/components/RatingRadioGroup.tsx | 2 +- website/src/components/TaskInfo/TaskInfo.tsx | 2 +- website/src/pages/_app.tsx | 1 + website/src/pages/account/index.tsx | 1 + website/src/pages/api/new_task/[task_type].ts | 2 +- website/src/pages/api/username.tsx | 1 - website/src/pages/auth/signin.tsx | 2 ++ website/src/pages/auth/verify.tsx | 1 + website/src/pages/create/assistant_reply.tsx | 2 +- website/src/pages/create/summarize_story.tsx | 2 +- website/src/pages/create/user_reply.tsx | 2 +- .../pages/evaluate/rank_assistant_replies.tsx | 2 +- .../src/pages/evaluate/rank_initial_prompts.tsx | 2 +- website/src/pages/evaluate/rank_user_replies.tsx | 2 +- website/src/pages/evaluate/rate_summary.tsx | 2 +- 23 files changed, 26 insertions(+), 29 deletions(-) diff --git a/website/.eslintrc.json b/website/.eslintrc.json index b2253ce8..04b5d542 100644 --- a/website/.eslintrc.json +++ b/website/.eslintrc.json @@ -6,19 +6,9 @@ "next/core-web-vitals" ], "rules": { - "simple-import-sort/imports": "error", - "simple-import-sort/exports": "error", - "@typescript-eslint/no-unused-vars": "off", - "unused-imports/no-unused-imports": "error", - "unused-imports/no-unused-vars": [ - "warn", - { - "vars": "all", - "varsIgnorePattern": "^_", - "args": "after-used", - "argsIgnorePattern": "^_" - } - ] + "unused-imports/no-unused-imports": "warn", + "simple-import-sort/imports": "warn", + "simple-import-sort/exports": "warn" }, "plugins": ["simple-import-sort", "unused-imports"] } diff --git a/website/package.json b/website/package.json index 98f18965..80bc8bb4 100644 --- a/website/package.json +++ b/website/package.json @@ -13,9 +13,9 @@ "cypress": "cypress open", "cypress:run": "cypress run", "cypress:image-baseline": "cypress-image-diff -u", - "fix:lint": "eslint --fix src/", + "fix:lint": "eslint --fix src/ --ext .js,.jsx,.ts,.tsx", "fix:format": "prettier --write ./src", - "fix": "npm run fix:lint && npm run fix:format" + "fix": "npm run fix:format && npm run fix:lint" }, "dependencies": { "@chakra-ui/react": "^2.4.4", diff --git a/website/src/components/Header/Header.stories.jsx b/website/src/components/Header/Header.stories.jsx index 793d4921..6a8a3866 100644 --- a/website/src/components/Header/Header.stories.jsx +++ b/website/src/components/Header/Header.stories.jsx @@ -3,6 +3,7 @@ import React from "react"; import { Header } from "./Header"; +// eslint-disable-next-line import/no-anonymous-default-export export default { title: "Header/Header", component: Header, diff --git a/website/src/components/Header/NavLinks.stories.jsx b/website/src/components/Header/NavLinks.stories.jsx index f7fafae2..9f21e151 100644 --- a/website/src/components/Header/NavLinks.stories.jsx +++ b/website/src/components/Header/NavLinks.stories.jsx @@ -1,5 +1,6 @@ import { NavLinks } from "./NavLinks"; +// eslint-disable-next-line import/no-anonymous-default-export export default { title: "Header/NavLinks", component: NavLinks, diff --git a/website/src/components/Header/UserMenu.stories.jsx b/website/src/components/Header/UserMenu.stories.jsx index 3c489617..aeb7e1c6 100644 --- a/website/src/components/Header/UserMenu.stories.jsx +++ b/website/src/components/Header/UserMenu.stories.jsx @@ -3,6 +3,7 @@ import React from "react"; import UserMenu from "./UserMenu"; +// eslint-disable-next-line import/no-anonymous-default-export export default { title: "Header/UserMenu", component: UserMenu, diff --git a/website/src/components/Header/UserMenu.tsx b/website/src/components/Header/UserMenu.tsx index 8de54f3d..c42d8895 100644 --- a/website/src/components/Header/UserMenu.tsx +++ b/website/src/components/Header/UserMenu.tsx @@ -12,7 +12,6 @@ export function UserMenu() { return <>; } if (session && session.user) { - const email = session.user.email; const accountOptions = [ { name: "Account Settings", diff --git a/website/src/components/Loading/Loading.stories.jsx b/website/src/components/Loading/Loading.stories.jsx index 0f068009..02579819 100644 --- a/website/src/components/Loading/Loading.stories.jsx +++ b/website/src/components/Loading/Loading.stories.jsx @@ -1,5 +1,6 @@ import { LoadingScreen } from "./LoadingScreen"; +// eslint-disable-next-line import/no-anonymous-default-export export default { title: "Example/LoadingScreen", component: LoadingScreen, diff --git a/website/src/components/RankItem.tsx b/website/src/components/RankItem.tsx index 3ba9da70..f424fa26 100644 --- a/website/src/components/RankItem.tsx +++ b/website/src/components/RankItem.tsx @@ -2,8 +2,8 @@ const RankItem = ({ username, score }) => { return (

1
-
@username
-
20.5
+
{username}
+
{score}
gold
); diff --git a/website/src/components/RatingRadioGroup.tsx b/website/src/components/RatingRadioGroup.tsx index 7fbcc3ac..6a63d1ec 100644 --- a/website/src/components/RatingRadioGroup.tsx +++ b/website/src/components/RatingRadioGroup.tsx @@ -1,7 +1,7 @@ import { Box, HStack, useRadio, useRadioGroup } from "@chakra-ui/react"; const RatingRadioButton = (props) => { - const { state, getInputProps, getCheckboxProps } = useRadio(props); + const { getInputProps, getCheckboxProps } = useRadio(props); const input = getInputProps(); const checkbox = getCheckboxProps(); diff --git a/website/src/components/TaskInfo/TaskInfo.tsx b/website/src/components/TaskInfo/TaskInfo.tsx index 629d5c1a..fa16615e 100644 --- a/website/src/components/TaskInfo/TaskInfo.tsx +++ b/website/src/components/TaskInfo/TaskInfo.tsx @@ -1,4 +1,4 @@ -export const TaskInfo = ({ id, output }: { id: string; output: any }) => { +export const TaskInfo = ({ id, output }: { id: string; output: string }) => { return (
Prompt diff --git a/website/src/pages/_app.tsx b/website/src/pages/_app.tsx index b36e3392..b9cffba1 100644 --- a/website/src/pages/_app.tsx +++ b/website/src/pages/_app.tsx @@ -8,6 +8,7 @@ import type { AppProps } from "next/app"; import { SessionProvider } from "next-auth/react"; import { getDefaultLayout, NextPageWithLayout } from "src/components/Layout"; +// eslint-disable-next-line @typescript-eslint/no-unused-vars const inter = Inter({ subsets: ["latin"], variable: "--font-inter", diff --git a/website/src/pages/account/index.tsx b/website/src/pages/account/index.tsx index b5c9d906..51f7ed38 100644 --- a/website/src/pages/account/index.tsx +++ b/website/src/pages/account/index.tsx @@ -8,6 +8,7 @@ export default function Account() { const { data: session } = useSession(); const [username, setUsername] = useState("null"); + // eslint-disable-next-line @typescript-eslint/no-unused-vars const handleUpdate = async () => { const response = await fetch("../api/update", { method: "POST", diff --git a/website/src/pages/api/new_task/[task_type].ts b/website/src/pages/api/new_task/[task_type].ts index b07215cd..69548b5f 100644 --- a/website/src/pages/api/new_task/[task_type].ts +++ b/website/src/pages/api/new_task/[task_type].ts @@ -63,7 +63,7 @@ const handler = async (req, res) => { message_id: registeredTask.id, }), }); - const ack = await ackRes.json(); + await ackRes.json(); // Send the results to the client. res.status(200).json(registeredTask); diff --git a/website/src/pages/api/username.tsx b/website/src/pages/api/username.tsx index 36c8360e..0a88ad20 100644 --- a/website/src/pages/api/username.tsx +++ b/website/src/pages/api/username.tsx @@ -5,7 +5,6 @@ import { getSession } from "next-auth/react"; // Optional fields in body: content export default async function handle(req, res) { const { username } = req.body; - const { email } = req.body; const session = await getSession({ req }); const result = await prisma.user.update({ diff --git a/website/src/pages/auth/signin.tsx b/website/src/pages/auth/signin.tsx index bcb51835..2ead2414 100644 --- a/website/src/pages/auth/signin.tsx +++ b/website/src/pages/auth/signin.tsx @@ -6,6 +6,7 @@ import React, { useRef } from "react"; import { FaBug, FaDiscord, FaEnvelope, FaGithub } from "react-icons/fa"; import { AuthLayout } from "src/components/AuthLayout"; +// eslint-disable-next-line @typescript-eslint/no-unused-vars export default function Signin({ csrfToken, providers }) { const { discord, email, github, credentials } = providers; const emailEl = useRef(null); @@ -104,6 +105,7 @@ export default function Signin({ csrfToken, providers }) { ); } +// eslint-disable-next-line @typescript-eslint/no-unused-vars export async function getServerSideProps(context) { const csrfToken = await getCsrfToken(); const providers = await getProviders(); diff --git a/website/src/pages/auth/verify.tsx b/website/src/pages/auth/verify.tsx index cbf40241..e004f504 100644 --- a/website/src/pages/auth/verify.tsx +++ b/website/src/pages/auth/verify.tsx @@ -16,6 +16,7 @@ export default function Verify() { ); } +// eslint-disable-next-line @typescript-eslint/no-unused-vars export async function getServerSideProps(context) { const csrfToken = await getCsrfToken(); const providers = await getProviders(); diff --git a/website/src/pages/create/assistant_reply.tsx b/website/src/pages/create/assistant_reply.tsx index d28a0ad0..54badd71 100644 --- a/website/src/pages/create/assistant_reply.tsx +++ b/website/src/pages/create/assistant_reply.tsx @@ -22,7 +22,7 @@ const AssistantReply = () => { }, }); - const { trigger, isMutating } = useSWRMutation("/api/update_task", poster, { + const { trigger } = useSWRMutation("/api/update_task", poster, { onSuccess: async (data) => { const newTask = await data.json(); setTasks((oldTasks) => [...oldTasks, newTask]); diff --git a/website/src/pages/create/summarize_story.tsx b/website/src/pages/create/summarize_story.tsx index 8746b03e..e136035a 100644 --- a/website/src/pages/create/summarize_story.tsx +++ b/website/src/pages/create/summarize_story.tsx @@ -29,7 +29,7 @@ const SummarizeStory = () => { // Every time we submit an answer to the latest task, let the backend handle // all the interactions then add the resulting task to the queue. This ends // when we hit the done task. - const { trigger, isMutating } = useSWRMutation("/api/update_task", poster, { + const { trigger } = useSWRMutation("/api/update_task", poster, { onSuccess: async (data) => { const newTask = await data.json(); // This is the more efficient way to update a react state array. diff --git a/website/src/pages/create/user_reply.tsx b/website/src/pages/create/user_reply.tsx index 36c912d5..1b221571 100644 --- a/website/src/pages/create/user_reply.tsx +++ b/website/src/pages/create/user_reply.tsx @@ -22,7 +22,7 @@ const UserReply = () => { }, }); - const { trigger, isMutating } = useSWRMutation("/api/update_task", poster, { + const { trigger } = useSWRMutation("/api/update_task", poster, { onSuccess: async (data) => { const newTask = await data.json(); setTasks((oldTasks) => [...oldTasks, newTask]); diff --git a/website/src/pages/evaluate/rank_assistant_replies.tsx b/website/src/pages/evaluate/rank_assistant_replies.tsx index cd6d7811..da3b8d4e 100644 --- a/website/src/pages/evaluate/rank_assistant_replies.tsx +++ b/website/src/pages/evaluate/rank_assistant_replies.tsx @@ -25,7 +25,7 @@ const RankAssistantReplies = () => { }, }); - const { trigger, isMutating } = useSWRMutation("/api/update_task", poster, { + const { trigger } = useSWRMutation("/api/update_task", poster, { onSuccess: async (data) => { const newTask = await data.json(); setTasks((oldTasks) => [...oldTasks, newTask]); diff --git a/website/src/pages/evaluate/rank_initial_prompts.tsx b/website/src/pages/evaluate/rank_initial_prompts.tsx index 4f236b50..4bfc5163 100644 --- a/website/src/pages/evaluate/rank_initial_prompts.tsx +++ b/website/src/pages/evaluate/rank_initial_prompts.tsx @@ -25,7 +25,7 @@ const RankInitialPrompts = () => { }, }); - const { trigger, isMutating } = useSWRMutation("/api/update_task", poster, { + const { trigger } = useSWRMutation("/api/update_task", poster, { onSuccess: async (data) => { const newTask = await data.json(); setTasks((oldTasks) => [...oldTasks, newTask]); diff --git a/website/src/pages/evaluate/rank_user_replies.tsx b/website/src/pages/evaluate/rank_user_replies.tsx index b67fda10..0a1c6d16 100644 --- a/website/src/pages/evaluate/rank_user_replies.tsx +++ b/website/src/pages/evaluate/rank_user_replies.tsx @@ -25,7 +25,7 @@ const RankUserReplies = () => { }, }); - const { trigger, isMutating } = useSWRMutation("/api/update_task", poster, { + const { trigger } = useSWRMutation("/api/update_task", poster, { onSuccess: async (data) => { const newTask = await data.json(); setTasks((oldTasks) => [...oldTasks, newTask]); diff --git a/website/src/pages/evaluate/rate_summary.tsx b/website/src/pages/evaluate/rate_summary.tsx index f11e19f6..f64b0f1a 100644 --- a/website/src/pages/evaluate/rate_summary.tsx +++ b/website/src/pages/evaluate/rate_summary.tsx @@ -30,7 +30,7 @@ const RateSummary = () => { // Every time we submit an answer to the latest task, let the backend handle // all the interactions then add the resulting task to the queue. This ends // when we hit the done task. - const { trigger, isMutating } = useSWRMutation("/api/update_task", poster, { + const { trigger } = useSWRMutation("/api/update_task", poster, { onSuccess: async (data) => { const newTask = await data.json(); // This is the more efficient way to update a react state array. From 6319f1ad17688d64b7696362cc1b9a56af828407 Mon Sep 17 00:00:00 2001 From: Adrian Cowan Date: Sun, 1 Jan 2023 15:18:59 +1100 Subject: [PATCH 3/8] website: Add drag handles to rank-able (drag-able) items to make it clear they can be dragged. The formatting changes to the SortableItem also had the side-effect of removing the dot points. --- website/src/components/Sortable/SortableItem.tsx | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/website/src/components/Sortable/SortableItem.tsx b/website/src/components/Sortable/SortableItem.tsx index 244fc313..c8a93075 100644 --- a/website/src/components/Sortable/SortableItem.tsx +++ b/website/src/components/Sortable/SortableItem.tsx @@ -1,6 +1,8 @@ import { useSortable } from "@dnd-kit/sortable"; import { CSS } from "@dnd-kit/utilities"; +import { RxDragHandleDots2 } from "react-icons/rx"; import { PropsWithChildren } from "react"; +import { Button } from "@chakra-ui/react"; export const SortableItem = ({ children, id }: PropsWithChildren<{ id: number }>) => { const { attributes, listeners, setNodeRef, transform, transition } = useSortable({ id }); @@ -13,12 +15,13 @@ export const SortableItem = ({ children, id }: PropsWithChildren<{ id: number }> return (
  • + {children}
  • ); From 64a7b9848a9ba1f9046906aa644f05fa4369f366 Mon Sep 17 00:00:00 2001 From: Adrian Cowan Date: Sun, 1 Jan 2023 15:56:20 +1100 Subject: [PATCH 4/8] website: Restrict ranking items to vertical motion to avoid breaking the webpage layout. When the items are drag-able outside the page boundary the viewport leaves the page boundary. This looks particularly unprofessionally on mobile. There is also another option to restrict to the page boundaries (restrictToWindowEdges) which might be better but it doesn't appear to work on mobile (firefox); the issue is that the items get stuck slightly off to the left edge of the viewport and can't be moved horizontally at all (even without restrictToVerticalAxis). --- website/package-lock.json | 23 ++++++++++++++++++++ website/package.json | 1 + website/src/components/Sortable/Sortable.tsx | 8 ++++++- 3 files changed, 31 insertions(+), 1 deletion(-) diff --git a/website/package-lock.json b/website/package-lock.json index 9bc7cde1..1587c01e 100644 --- a/website/package-lock.json +++ b/website/package-lock.json @@ -10,6 +10,7 @@ "dependencies": { "@chakra-ui/react": "^2.4.4", "@dnd-kit/core": "^6.0.6", + "@dnd-kit/modifiers": "^6.0.1", "@dnd-kit/sortable": "^7.0.1", "@emotion/react": "^11.10.5", "@emotion/styled": "^11.10.5", @@ -3356,6 +3357,19 @@ "react-dom": ">=16.8.0" } }, + "node_modules/@dnd-kit/modifiers": { + "version": "6.0.1", + "resolved": "https://registry.npmjs.org/@dnd-kit/modifiers/-/modifiers-6.0.1.tgz", + "integrity": "sha512-rbxcsg3HhzlcMHVHWDuh9LCjpOVAgqbV78wLGI8tziXY3+qcMQ61qVXIvNKQFuhj75dSfD+o+PYZQ/NUk2A23A==", + "dependencies": { + "@dnd-kit/utilities": "^3.2.1", + "tslib": "^2.0.0" + }, + "peerDependencies": { + "@dnd-kit/core": "^6.0.6", + "react": ">=16.8.0" + } + }, "node_modules/@dnd-kit/sortable": { "version": "7.0.1", "resolved": "https://registry.npmjs.org/@dnd-kit/sortable/-/sortable-7.0.1.tgz", @@ -30905,6 +30919,15 @@ "tslib": "^2.0.0" } }, + "@dnd-kit/modifiers": { + "version": "6.0.1", + "resolved": "https://registry.npmjs.org/@dnd-kit/modifiers/-/modifiers-6.0.1.tgz", + "integrity": "sha512-rbxcsg3HhzlcMHVHWDuh9LCjpOVAgqbV78wLGI8tziXY3+qcMQ61qVXIvNKQFuhj75dSfD+o+PYZQ/NUk2A23A==", + "requires": { + "@dnd-kit/utilities": "^3.2.1", + "tslib": "^2.0.0" + } + }, "@dnd-kit/sortable": { "version": "7.0.1", "resolved": "https://registry.npmjs.org/@dnd-kit/sortable/-/sortable-7.0.1.tgz", diff --git a/website/package.json b/website/package.json index c7532955..bc1f3b69 100644 --- a/website/package.json +++ b/website/package.json @@ -20,6 +20,7 @@ "dependencies": { "@chakra-ui/react": "^2.4.4", "@dnd-kit/core": "^6.0.6", + "@dnd-kit/modifiers": "^6.0.1", "@dnd-kit/sortable": "^7.0.1", "@emotion/react": "^11.10.5", "@emotion/styled": "^11.10.5", diff --git a/website/src/components/Sortable/Sortable.tsx b/website/src/components/Sortable/Sortable.tsx index 74ff1bb2..7ca761df 100644 --- a/website/src/components/Sortable/Sortable.tsx +++ b/website/src/components/Sortable/Sortable.tsx @@ -2,6 +2,7 @@ import { Flex } from "@chakra-ui/react"; import { closestCenter, DndContext, PointerSensor, TouchSensor, useSensor, useSensors } from "@dnd-kit/core"; import type { DragEndEvent } from "@dnd-kit/core/dist/types/events"; import { arrayMove, SortableContext, verticalListSortingStrategy } from "@dnd-kit/sortable"; +import { restrictToVerticalAxis } from "@dnd-kit/modifiers"; import { ReactNode, useEffect, useState } from "react"; import { SortableItem } from "./SortableItem"; @@ -33,7 +34,12 @@ export const Sortable = ({ items, onChange }: SortableProps) => { const sensors = useSensors(useSensor(PointerSensor), useSensor(TouchSensor)); return ( - + {itemsWithIds.map(({ id, item }) => ( From ab8fbbecca941c5609cbbe1f07b068d1996a7bae Mon Sep 17 00:00:00 2001 From: Adrian Cowan Date: Sun, 1 Jan 2023 16:39:15 +1100 Subject: [PATCH 5/8] website: Add basic keyboard support for ranking items to improve accessibility --- website/src/components/Sortable/Sortable.tsx | 23 +++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) diff --git a/website/src/components/Sortable/Sortable.tsx b/website/src/components/Sortable/Sortable.tsx index 7ca761df..1ac95bf7 100644 --- a/website/src/components/Sortable/Sortable.tsx +++ b/website/src/components/Sortable/Sortable.tsx @@ -1,7 +1,20 @@ import { Flex } from "@chakra-ui/react"; -import { closestCenter, DndContext, PointerSensor, TouchSensor, useSensor, useSensors } from "@dnd-kit/core"; +import { + closestCenter, + DndContext, + PointerSensor, + TouchSensor, + KeyboardSensor, + useSensor, + useSensors, +} from "@dnd-kit/core"; import type { DragEndEvent } from "@dnd-kit/core/dist/types/events"; -import { arrayMove, SortableContext, verticalListSortingStrategy } from "@dnd-kit/sortable"; +import { + arrayMove, + SortableContext, + sortableKeyboardCoordinates, + verticalListSortingStrategy, +} from "@dnd-kit/sortable"; import { restrictToVerticalAxis } from "@dnd-kit/modifiers"; import { ReactNode, useEffect, useState } from "react"; @@ -31,7 +44,11 @@ export const Sortable = ({ items, onChange }: SortableProps) => { ); }, [items]); - const sensors = useSensors(useSensor(PointerSensor), useSensor(TouchSensor)); + const sensors = useSensors( + useSensor(PointerSensor), + useSensor(TouchSensor), + useSensor(KeyboardSensor, { coordinateGetter: sortableKeyboardCoordinates }) + ); return ( Date: Sun, 1 Jan 2023 17:16:05 +1100 Subject: [PATCH 6/8] website: Fix order of imports in Sortable/SortableItem --- website/src/components/Sortable/Sortable.tsx | 2 +- website/src/components/Sortable/SortableItem.tsx | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/website/src/components/Sortable/Sortable.tsx b/website/src/components/Sortable/Sortable.tsx index 1ac95bf7..615b0853 100644 --- a/website/src/components/Sortable/Sortable.tsx +++ b/website/src/components/Sortable/Sortable.tsx @@ -9,13 +9,13 @@ import { useSensors, } from "@dnd-kit/core"; import type { DragEndEvent } from "@dnd-kit/core/dist/types/events"; +import { restrictToVerticalAxis } from "@dnd-kit/modifiers"; import { arrayMove, SortableContext, sortableKeyboardCoordinates, verticalListSortingStrategy, } from "@dnd-kit/sortable"; -import { restrictToVerticalAxis } from "@dnd-kit/modifiers"; import { ReactNode, useEffect, useState } from "react"; import { SortableItem } from "./SortableItem"; diff --git a/website/src/components/Sortable/SortableItem.tsx b/website/src/components/Sortable/SortableItem.tsx index c8a93075..834a854f 100644 --- a/website/src/components/Sortable/SortableItem.tsx +++ b/website/src/components/Sortable/SortableItem.tsx @@ -1,8 +1,8 @@ +import { Button } from "@chakra-ui/react"; import { useSortable } from "@dnd-kit/sortable"; import { CSS } from "@dnd-kit/utilities"; import { RxDragHandleDots2 } from "react-icons/rx"; import { PropsWithChildren } from "react"; -import { Button } from "@chakra-ui/react"; export const SortableItem = ({ children, id }: PropsWithChildren<{ id: number }>) => { const { attributes, listeners, setNodeRef, transform, transition } = useSortable({ id }); From 550d695a58780cf4921af30237c738a96d07cb2b Mon Sep 17 00:00:00 2001 From: Alex Ott <66271487+AlexanderHOtt@users.noreply.github.com> Date: Sat, 31 Dec 2022 14:36:06 -0800 Subject: [PATCH 7/8] merge upstream/main --- discord-bot/bot/extensions/guild_settings.py | 1 + 1 file changed, 1 insertion(+) diff --git a/discord-bot/bot/extensions/guild_settings.py b/discord-bot/bot/extensions/guild_settings.py index 1aba9f47..cb419874 100644 --- a/discord-bot/bot/extensions/guild_settings.py +++ b/discord-bot/bot/extensions/guild_settings.py @@ -64,6 +64,7 @@ async def log_channel(ctx: lightbulb.SlashContext) -> None: conn: Connection = ctx.bot.d.db assert ctx.guild_id is not None # `guild_only` check assert isinstance(channel, hikari.PermissibleGuildChannel) + type(channel).mro() # Check if the bot can send messages in that channel assert (me := ctx.bot.get_me()) is not None # non-None after `StartedEvent` From 4d76355dc899f0cf1e4ff087788d07ec096192fe Mon Sep 17 00:00:00 2001 From: Alex Ott <66271487+AlexanderHOtt@users.noreply.github.com> Date: Sat, 31 Dec 2022 16:31:04 -0800 Subject: [PATCH 8/8] update permissions check for guild settings --- discord-bot/bot/extensions/guild_settings.py | 31 +++++++++++++------- 1 file changed, 20 insertions(+), 11 deletions(-) diff --git a/discord-bot/bot/extensions/guild_settings.py b/discord-bot/bot/extensions/guild_settings.py index cb419874..d09407da 100644 --- a/discord-bot/bot/extensions/guild_settings.py +++ b/discord-bot/bot/extensions/guild_settings.py @@ -5,7 +5,7 @@ import lightbulb from aiosqlite import Connection from bot.db.schemas import GuildSettings from bot.utils import mention -from lightbulb.utils.permissions import permissions_in +from lightbulb.utils import permissions_in from loguru import logger plugin = lightbulb.Plugin("GuildSettings") @@ -56,33 +56,42 @@ if guild_settings.log_channel_id else 'not set'} @settings.child @lightbulb.option("channel", "The channel to use.", hikari.TextableGuildChannel) -@lightbulb.command("log_channel", "Set the channel that the bot logs task and label completions in.") +@lightbulb.command("log_channel", "Set the channel that the bot logs task and label completions in.", ephemeral=True) @lightbulb.implements(lightbulb.SlashSubCommand) async def log_channel(ctx: lightbulb.SlashContext) -> None: """Set the channel that the bot logs task and label completions in.""" channel: hikari.TextableGuildChannel = ctx.options.channel conn: Connection = ctx.bot.d.db assert ctx.guild_id is not None # `guild_only` check - assert isinstance(channel, hikari.PermissibleGuildChannel) - type(channel).mro() # Check if the bot can send messages in that channel - assert (me := ctx.bot.get_me()) is not None # non-None after `StartedEvent` - if (own_member := ctx.bot.cache.get_member(ctx.guild_id, me.id)) is None: - own_member = await ctx.bot.rest.fetch_member(ctx.guild_id, me.id) - perms = permissions_in(channel, own_member) - if perms & ~hikari.Permissions.SEND_MESSAGES: - await ctx.respond("I don't have permission to send messages in that channel.") + assert isinstance(channel, hikari.InteractionChannel) # Slash commands are interactions + me = ctx.bot.cache.get_me() or await ctx.bot.rest.fetch_my_user() + own_member = ctx.bot.cache.get_member(ctx.guild_id, me.id) or await ctx.bot.rest.fetch_member(ctx.guild_id, me.id) + + # Get the channel from the cache if it is there, otherwise fetch it + if (ch := ctx.bot.cache.get_guild_channel(channel.id)) is None: + ch = {ch.id: ch for ch in await ctx.bot.rest.fetch_guild_channels(channel.id)}[channel.id] + + if not isinstance(ch, hikari.GuildTextChannel): + await ctx.respond(f"{ch.mention} is not a text channel.") + return + + # if the bot's permissions for this channel don't contain SEND_MESSAGE + # This will also filter out categories and voice channels + print(permissions_in(ch, own_member) & hikari.Permissions.SEND_MESSAGES) + if not permissions_in(ch, own_member) & hikari.Permissions.SEND_MESSAGES: + await ctx.respond(f"I don't have permission to send messages in {ch.mention}.") return await ctx.respond(f"Setting `log_channel` to {channel.mention}.") + # update the database async with conn.cursor() as cursor: await cursor.execute( "INSERT OR REPLACE INTO guild_settings (guild_id, log_channel_id) VALUES (?, ?)", (ctx.guild_id, channel.id), ) - await conn.commit() logger.info(f"Updated `log_channel` for {ctx.guild_id} to {channel.id}.")