From bf87bc2321c4e48bbc102e0066cb02dbccd9ac74 Mon Sep 17 00:00:00 2001 From: yutakobaayshidev <91340399+yutakobayashidev@users.noreply.github.com> Date: Thu, 20 Jul 2023 18:19:16 +0900 Subject: [PATCH] =?UTF-8?q?=E2=99=BB=EF=B8=8F=20refactor?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- frontend/prisma/seed.ts | 73 +++--- frontend/src/app/_components/BottomMenu.tsx | 217 +++++++---------- frontend/src/app/_components/Header.tsx | 14 +- frontend/src/app/_components/Meeting.tsx | 123 ---------- frontend/src/app/_components/Meetings.tsx | 135 +++++++++-- frontend/src/app/about/page.tsx | 2 +- .../src/app/dashboard/settings/Settings.tsx | 10 +- frontend/src/app/face/PersonModal.tsx | 4 +- frontend/src/app/meetings/[id]/Comment.tsx | 2 +- frontend/src/app/meetings/[id]/Comments.tsx | 11 +- frontend/src/app/meetings/[id]/Summarize.tsx | 70 +++--- frontend/src/app/meetings/[id]/Transcript.tsx | 118 +++++----- frontend/src/app/meetings/[id]/Video.tsx | 123 +++++----- frontend/src/app/meetings/[id]/actions.ts | 2 +- frontend/src/app/members/[id]/Chat.tsx | 6 +- frontend/src/app/members/[id]/page.tsx | 218 +++++++++--------- frontend/src/app/page.tsx | 28 +-- frontend/src/app/search/Search.tsx | 68 ++++++ frontend/src/app/search/page.tsx | 98 ++++++++ frontend/src/helper/utils.ts | 16 ++ 20 files changed, 728 insertions(+), 610 deletions(-) delete mode 100644 frontend/src/app/_components/Meeting.tsx create mode 100644 frontend/src/app/search/Search.tsx create mode 100644 frontend/src/app/search/page.tsx diff --git a/frontend/prisma/seed.ts b/frontend/prisma/seed.ts index 9305764..04a1c7f 100644 --- a/frontend/prisma/seed.ts +++ b/frontend/prisma/seed.ts @@ -1,4 +1,5 @@ import { PrismaClient } from "@prisma/client"; + const prisma = new PrismaClient(); async function main() { @@ -58,113 +59,113 @@ async function main() { name: "自由民主党", description: "自由民主党(じゆうみんしゅとう、英: Liberal Democratic Party、英文略称: LDP[ / Lib Dems)は、日本の政党。自由主義を掲げ、つねに改革を進める保守政党を標榜している。", + facebook: "jimin.official", image: "https://pbs.twimg.com/profile_images/1532645750521606145/CQPpEZtc_400x400.jpg", - facebook: "jimin.official", twitter: "jimin_koho", + website: "https://www.jimin.jp/", wikipedia: "https://ja.wikipedia.org/wiki/%E8%87%AA%E7%94%B1%E6%B0%91%E4%B8%BB%E5%85%9A_(%E6%97%A5%E6%9C%AC)", - website: "https://www.jimin.jp/", }, { id: "RIKKEN", name: "立憲民主党", - website: "https://cdp-japan.jp/", - image: - "https://pbs.twimg.com/profile_images/1311187310852022272/8TOEuyf-_400x400.jpg", description: "立憲民主党(りっけんみんしゅとう、英: The Constitutional Democratic Party of Japan、略称: CDP)は、日本の政党。立憲主義に基づく民主政治を綱領に掲げる、リベラル政党である。", facebook: "rikkenminshu", + image: + "https://pbs.twimg.com/profile_images/1311187310852022272/8TOEuyf-_400x400.jpg", twitter: "CDP2017", + website: "https://cdp-japan.jp/", wikipedia: "https://ja.wikipedia.org/wiki/%E7%AB%8B%E6%86%B2%E6%B0%91%E4%B8%BB%E5%85%9A_(%E6%97%A5%E6%9C%AC_2020)", }, { id: "KOMEI", name: "公明党", - website: "https://www.komei.or.jp/", - twitter: "komei_koho", + description: + "公明党は、日本の政党。宗教団体の創価学会を支持母体として中道政治の実現を目指して結成された。 略称は公明。1字表記の際は公。現在の党キャッチコピーは、「小さな声を、聴く力。」。 1999年10月5日から2009年9月16日まで、および2012年12月26日から現在まで自由民主党と自公連立政権を構成している。", facebook: "komeito", - wikipedia: - "https://ja.wikipedia.org/wiki/%E5%85%AC%E6%98%8E%E5%85%9A#:~:text=%E5%85%AC%E6%98%8E%E5%85%9A%E3%81%AF%E3%80%81%E8%B1%8A%E3%81%8B%E3%81%AA%E3%82%8B%E4%BA%BA%E9%96%93,%E3%81%AE%E5%A4%A7%E8%A1%86%E6%94%BF%E5%85%9A%E3%81%A7%E3%81%82%E3%82%8B%E3%80%82", image: "https://pbs.twimg.com/profile_images/1371640641873084417/vQuhD0GE_400x400.jpg", - description: - "公明党は、日本の政党。宗教団体の創価学会を支持母体として中道政治の実現を目指して結成された。 略称は公明。1字表記の際は公。現在の党キャッチコピーは、「小さな声を、聴く力。」。 1999年10月5日から2009年9月16日まで、および2012年12月26日から現在まで自由民主党と自公連立政権を構成している。", + twitter: "komei_koho", + website: "https://www.komei.or.jp/", + wikipedia: + "https://ja.wikipedia.org/wiki/%E5%85%AC%E6%98%8E%E5%85%9A#:~:text=%E5%85%AC%E6%98%8E%E5%85%9A%E3%81%AF%E3%80%81%E8%B1%8A%E3%81%8B%E3%81%AA%E3%82%8B%E4%BA%BA%E9%96%93,%E3%81%AE%E5%A4%A7%E8%A1%86%E6%94%BF%E5%85%9A%E3%81%A7%E3%81%82%E3%82%8B%E3%80%82", }, { id: "KYOSAN", name: "日本共産党", - website: "https://www.jcp.or.jp", - twitter: "jcp_cc", + description: + "日本共産党は、日本の政党。科学的社会主義を理論的基礎とする社会主義・共産主義政党である。 略称は「JCP」。日本国内では単に「共産党」、「共産」と呼ばれる。「日共」とも。1字表記の際は、「共」と表記される。", facebook: "kyosanto", - wikipedia: - "https://ja.wikipedia.org/wiki/%E6%97%A5%E6%9C%AC%E5%85%B1%E7%94%A3%E5%85%9A", image: "https://pbs.twimg.com/profile_images/920124778182144000/2NzWLV_Q_400x400.jpg", - description: - "日本共産党は、日本の政党。科学的社会主義を理論的基礎とする社会主義・共産主義政党である。 略称は「JCP」。日本国内では単に「共産党」、「共産」と呼ばれる。「日共」とも。1字表記の際は、「共」と表記される。", + twitter: "jcp_cc", + website: "https://www.jcp.or.jp", + wikipedia: + "https://ja.wikipedia.org/wiki/%E6%97%A5%E6%9C%AC%E5%85%B1%E7%94%A3%E5%85%9A", }, { id: "ISHIN", name: "日本維新の会", - website: "https://o-ishin.jp", - twitter: "osaka_ishin", + description: + "日本維新の会は、日本の政党。行政改革や憲法改正、規制改革、機会平等、地方分権などを政策に掲げる保守政党である 。 略称は「維新」、1字表記は「維」。 自公連立政権に対しては、是々非々の立場を取っている。そのため、立憲民主党をはじめとするいわゆる野党共闘とは距離を置いており、これらの野党を批判することも多い。", facebook: "nipponishinnokai", - wikipedia: - "https://ja.wikipedia.org/wiki/%E6%97%A5%E6%9C%AC%E7%B6%AD%E6%96%B0%E3%81%AE%E4%BC%9A_(2016-)", image: "https://pbs.twimg.com/profile_images/919020416076677120/yaugkUxG_400x400.jpg", - description: - "日本維新の会は、日本の政党。行政改革や憲法改正、規制改革、機会平等、地方分権などを政策に掲げる保守政党である 。 略称は「維新」、1字表記は「維」。 自公連立政権に対しては、是々非々の立場を取っている。そのため、立憲民主党をはじめとするいわゆる野党共闘とは距離を置いており、これらの野党を批判することも多い。", + twitter: "osaka_ishin", + website: "https://o-ishin.jp", + wikipedia: + "https://ja.wikipedia.org/wiki/%E6%97%A5%E6%9C%AC%E7%B6%AD%E6%96%B0%E3%81%AE%E4%BC%9A_(2016-)", }, { id: "KOKUMIN", name: "国民民主党", - twitter: "DPFPnews", - website: "https://new-kokumin.jp", + description: + "国民民主党は、日本の政党。穏健保守からリベラルまでを包摂する中道政党である。 公職選挙法における略称は「民主党」。マスメディアでは、「国民民主」、「国民」。 旧・立憲民主党と旧・国民民主党の合流の際に、玉木雄一郎らを中心とする合流に参加しない国民民主党の一部の議員により2020年に結党された。", facebook: "democratic.party.for.the.people", image: "https://pbs.twimg.com/profile_images/1060713235500814337/hNsdccnL_400x400.jpg", - description: - "国民民主党は、日本の政党。穏健保守からリベラルまでを包摂する中道政党である。 公職選挙法における略称は「民主党」。マスメディアでは、「国民民主」、「国民」。 旧・立憲民主党と旧・国民民主党の合流の際に、玉木雄一郎らを中心とする合流に参加しない国民民主党の一部の議員により2020年に結党された。", + twitter: "DPFPnews", + website: "https://new-kokumin.jp", }, { id: "REIWA", name: "れいわ新選組", - twitter: "reiwashinsen", - website: "https://reiwa-shinsengumi.com", + description: + "れいわ新選組は、日本の政党。略称はれいわ。 2019年4月1日に元俳優で当時参議院議員であった山本太郎が設立した政党である。 同年7月の第25回参議院議員選挙比例区で得票率2%を上回り、設立から約3か月半で公職選挙法が規定する政党要件を満たした。", facebook: "reiwa.shinsengumi", image: "https://pbs.twimg.com/profile_images/1326482970765484032/YHpERFmF_400x400.jpg", - description: - "れいわ新選組は、日本の政党。略称はれいわ。 2019年4月1日に元俳優で当時参議院議員であった山本太郎が設立した政党である。 同年7月の第25回参議院議員選挙比例区で得票率2%を上回り、設立から約3か月半で公職選挙法が規定する政党要件を満たした。", + twitter: "reiwashinsen", + website: "https://reiwa-shinsengumi.com", }, ]; for (const group of groups) { await prisma.group.upsert({ - where: { id: group.id as any }, create: { id: group.id as any, name: group.name, - website: group.website, description: group.description, - image: group.image, facebook: group.facebook, + image: group.image, twitter: group.twitter, + website: group.website, wikipedia: group.wikipedia, }, update: { id: group.id as any, name: group.name, - website: group.website, description: group.description, - image: group.image, facebook: group.facebook, + image: group.image, twitter: group.twitter, + website: group.website, wikipedia: group.wikipedia, }, + where: { id: group.id as any }, }); } diff --git a/frontend/src/app/_components/BottomMenu.tsx b/frontend/src/app/_components/BottomMenu.tsx index 065bbc0..0c28563 100644 --- a/frontend/src/app/_components/BottomMenu.tsx +++ b/frontend/src/app/_components/BottomMenu.tsx @@ -12,145 +12,98 @@ import { SearchIcon, } from "@xpadev-net/designsystem-icons"; import cn from "classnames"; +import type { Route } from "next"; import Link from "next/link"; import { usePathname } from "next/navigation"; +import { FC } from "react"; -export default function MobileFooter() { +interface LinkIconItemProps { + Icon: FC<{ className: string; fill: string; height: string; width: string }>; + label: string; + OutlinedIcon: FC<{ + className: string; + fill: string; + height: string; + width: string; + }>; + path: Route | URL; +} + +const LinkIconItem: FC = ({ + Icon, + label, + OutlinedIcon, + path, +}) => { let pathname = usePathname() || "/"; + return ( +
  • + + {pathname === path ? ( + + ) : ( + + )} + {label} + +
  • + ); +}; + +export default function MobileFooter() { return (
    -
      -
    • - - {pathname === "/" ? ( - - ) : ( - - )} - ホーム - -
    • -
    • - - {pathname === "/face" ? ( - - ) : ( - - )} - 顔認識 - -
    • -
    • - - {pathname === "/chat" ? ( - - ) : ( - - )} - チャット - -
    • -
    • - - {pathname === "/topics" ? ( - - ) : ( - - )} - トピック - -
    • -
    • - -
    • +
        + + + + +
    ); diff --git a/frontend/src/app/_components/Header.tsx b/frontend/src/app/_components/Header.tsx index a109a92..9ca33ea 100644 --- a/frontend/src/app/_components/Header.tsx +++ b/frontend/src/app/_components/Header.tsx @@ -2,6 +2,7 @@ import { auth } from "@auth"; import { config } from "@site.config"; import { Login } from "@src/app/_components/Login"; import UserMenu from "@src/app/_components/UserMenu"; +import { SearchIcon } from "@xpadev-net/designsystem-icons"; import Link from "next/link"; export default async function Header() { @@ -10,13 +11,18 @@ export default async function Header() { return (
    - + {config.siteMeta.title}
    + + + {session?.user ? : }
    diff --git a/frontend/src/app/_components/Meeting.tsx b/frontend/src/app/_components/Meeting.tsx deleted file mode 100644 index 3c2d83a..0000000 --- a/frontend/src/app/_components/Meeting.tsx +++ /dev/null @@ -1,123 +0,0 @@ -"use client"; - -import { formatDate , isKanji,kanaToHira } from "@src/helper/utils"; -import { useKuromoji } from "@src/hooks/useKuromoji"; -import Link from "next/link"; -import { type Session } from "next-auth"; -import { useEffect,useState } from "react"; -import { FaClock } from "react-icons/fa"; - -export default function Meeting({ - meetings, - user, -}: { - meetings: { - id: string; - date: string; - house: string | null; - kids: string | null; - meeting_name: string; - summary: string | null; - }[]; - user: Session["user"]; -}) { - const [isChecked, setIsChecked] = useState(false); - const { isTokenizerReady, tokenizer } = useKuromoji(); - const [rubyKids, setRubyKids] = useState<{ [id: string]: string }>({}); - - useEffect(() => { - if (user && tokenizer) { - setIsChecked(user.kids); - } - }, [user, tokenizer]); - - useEffect(() => { - const generateRubyForAllMeetings = async () => { - if (isChecked && tokenizer && meetings) { - const newRubyKids: { [id: string]: string } = {}; - for (const meeting of meetings) { - const text = meeting.kids || ""; - const tokens = tokenizer.tokenize(text); - const rubyText = tokens - .map((token) => { - const surface = token.surface_form; - const reading = token.reading; - if (!reading) { - return surface; - } - const hiraReading = kanaToHira(reading); - if (surface.split("").some(isKanji)) { - return `${surface}${hiraReading}`; - } else { - return surface; - } - }) - .join(""); - newRubyKids[meeting.id] = rubyText; - } - setRubyKids(newRubyKids); - } - }; - generateRubyForAllMeetings(); - }, [isChecked, tokenizer, meetings]); - - return ( -
    - -
    - {meetings.map((meeting) => ( - -

    - {meeting.house && ( - - {meeting.house === "COUNCILLORS" ? "参議院" : "衆議院"} - - )} - {meeting.meeting_name} -

    - - {meeting.summary && ( -
    - {isChecked && meeting.kids ? ( - - ) : ( - meeting.summary - )} -
    - )} - - ))} -
    -
    - ); -} diff --git a/frontend/src/app/_components/Meetings.tsx b/frontend/src/app/_components/Meetings.tsx index 3cb4f34..3c2d83a 100644 --- a/frontend/src/app/_components/Meetings.tsx +++ b/frontend/src/app/_components/Meetings.tsx @@ -1,22 +1,123 @@ -import Meeting from "@src/app/_components/Meeting"; -import prisma from "@src/lib/prisma"; +"use client"; -import { auth } from "@/auth"; +import { formatDate , isKanji,kanaToHira } from "@src/helper/utils"; +import { useKuromoji } from "@src/hooks/useKuromoji"; +import Link from "next/link"; +import { type Session } from "next-auth"; +import { useEffect,useState } from "react"; +import { FaClock } from "react-icons/fa"; -export default async function Meetings() { - const meetingsPromise = prisma.video.findMany({ - orderBy: [ - { - date: "desc", - }, - ], - }); - const sessionPromise = auth(); +export default function Meeting({ + meetings, + user, +}: { + meetings: { + id: string; + date: string; + house: string | null; + kids: string | null; + meeting_name: string; + summary: string | null; + }[]; + user: Session["user"]; +}) { + const [isChecked, setIsChecked] = useState(false); + const { isTokenizerReady, tokenizer } = useKuromoji(); + const [rubyKids, setRubyKids] = useState<{ [id: string]: string }>({}); - const [session, meetings] = await Promise.all([ - sessionPromise, - meetingsPromise, - ]); + useEffect(() => { + if (user && tokenizer) { + setIsChecked(user.kids); + } + }, [user, tokenizer]); - return ; + useEffect(() => { + const generateRubyForAllMeetings = async () => { + if (isChecked && tokenizer && meetings) { + const newRubyKids: { [id: string]: string } = {}; + for (const meeting of meetings) { + const text = meeting.kids || ""; + const tokens = tokenizer.tokenize(text); + const rubyText = tokens + .map((token) => { + const surface = token.surface_form; + const reading = token.reading; + if (!reading) { + return surface; + } + const hiraReading = kanaToHira(reading); + if (surface.split("").some(isKanji)) { + return `${surface}${hiraReading}`; + } else { + return surface; + } + }) + .join(""); + newRubyKids[meeting.id] = rubyText; + } + setRubyKids(newRubyKids); + } + }; + generateRubyForAllMeetings(); + }, [isChecked, tokenizer, meetings]); + + return ( +
    + +
    + {meetings.map((meeting) => ( + +

    + {meeting.house && ( + + {meeting.house === "COUNCILLORS" ? "参議院" : "衆議院"} + + )} + {meeting.meeting_name} +

    + + {meeting.summary && ( +
    + {isChecked && meeting.kids ? ( + + ) : ( + meeting.summary + )} +
    + )} + + ))} +
    +
    + ); } diff --git a/frontend/src/app/about/page.tsx b/frontend/src/app/about/page.tsx index d3ebb29..f603c7d 100644 --- a/frontend/src/app/about/page.tsx +++ b/frontend/src/app/about/page.tsx @@ -1,6 +1,6 @@ import { config } from "@site.config"; import type { Metadata } from "next"; -import { FaDiscord,FaGithub } from "react-icons/fa"; +import { FaDiscord, FaGithub } from "react-icons/fa"; export const metadata: Metadata = { title: "このサイトについて", diff --git a/frontend/src/app/dashboard/settings/Settings.tsx b/frontend/src/app/dashboard/settings/Settings.tsx index d3c372a..3a522ab 100644 --- a/frontend/src/app/dashboard/settings/Settings.tsx +++ b/frontend/src/app/dashboard/settings/Settings.tsx @@ -1,15 +1,15 @@ "use client"; -import { Dialog,Switch } from "@headlessui/react"; +import { Dialog, Switch } from "@headlessui/react"; import GLogo from "@public/g-logo.svg"; import Modal from "@src/app/_components/Modal"; import { ArrowDownIcon } from "@xpadev-net/designsystem-icons"; import cn from "classnames"; import { useRouter } from "next/navigation"; import { type Session } from "next-auth"; -import { useEffect , useState , useTransition } from "react"; +import { useEffect, useState, useTransition } from "react"; -import { DeleteAccount,updatePrefecture, updateUser } from "./actions"; +import { DeleteAccount, updatePrefecture, updateUser } from "./actions"; export default function Settings({ prefectures, @@ -78,7 +78,7 @@ export default function Settings({ setPrefecture(Number(event.target.value)); }} - className="border-normal-400 hover:border-normal-500 hover:bg-normal-50 block w-full appearance-none rounded-lg border-2 bg-white py-2 pl-3 pr-8 leading-tight transition-colors focus:border-primary focus:outline-none" + className="border-normal-400 hover:border-normal-500 hover:bg-normal-50 focus:border-primary block w-full appearance-none rounded-lg border-2 bg-white py-2 pl-3 pr-8 leading-tight transition-colors focus:outline-none" > {prefectures.map((prefecture) => (