-
Notifications
You must be signed in to change notification settings - Fork 4
feat: display multi organization in event detail #304
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,155 @@ | ||||||||||||||||||||||||||||
| import NextImage from "@/components/image"; | ||||||||||||||||||||||||||||
| import { | ||||||||||||||||||||||||||||
| BiliButton, | ||||||||||||||||||||||||||||
| EmailButton, | ||||||||||||||||||||||||||||
| FacebookButton, | ||||||||||||||||||||||||||||
| PlurkButton, | ||||||||||||||||||||||||||||
| QQGroupButton, | ||||||||||||||||||||||||||||
| RednoteButton, | ||||||||||||||||||||||||||||
| TwitterButton, | ||||||||||||||||||||||||||||
| WebsiteButton, | ||||||||||||||||||||||||||||
| WeiboButton, | ||||||||||||||||||||||||||||
| } from "@/components/OrganizationLinkButton"; | ||||||||||||||||||||||||||||
| import OrganizationStatus from "@/components/organizationStatus"; | ||||||||||||||||||||||||||||
| import type { EventItem } from "@/types/event"; | ||||||||||||||||||||||||||||
| import { sendTrack } from "@/utils/track"; | ||||||||||||||||||||||||||||
| import clsx from "clsx"; | ||||||||||||||||||||||||||||
| import { useTranslation } from "next-i18next/pages"; | ||||||||||||||||||||||||||||
| import Link from "next/link"; | ||||||||||||||||||||||||||||
| import { useState } from "react"; | ||||||||||||||||||||||||||||
| import { IoChevronBack, IoChevronForward } from "react-icons/io5"; | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| type EventOrganizationCardProps = { | ||||||||||||||||||||||||||||
| event: EventItem; | ||||||||||||||||||||||||||||
| showDescriptionContainer: boolean; | ||||||||||||||||||||||||||||
| }; | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| export default function EventOrganizationCard(props: EventOrganizationCardProps) { | ||||||||||||||||||||||||||||
| const { t } = useTranslation(); | ||||||||||||||||||||||||||||
| const orgList = [props.event.organization, ...props.event.organizations]; | ||||||||||||||||||||||||||||
| const [activeIndex, setActiveIndex] = useState(0); | ||||||||||||||||||||||||||||
| const showOrgSwitcher = orgList.length > 1; | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| const organization = orgList[activeIndex] ?? orgList[0]!; | ||||||||||||||||||||||||||||
|
Comment on lines
+29
to
+33
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
建议按 ♻️ 建议修改- const orgList = [props.event.organization, ...props.event.organizations];
+ const orgList = [props.event.organization, ...(props.event.organizations ?? [])]
+ .filter((o): o is NonNullable<typeof o> => !!o)
+ .filter((o, i, arr) => arr.findIndex((x) => x.slug === o.slug) === i);
+ if (orgList.length === 0) return null;📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||||||||||||||||
| const organizationProfileHref = `/${organization.slug}`; | ||||||||||||||||||||||||||||
| const trackOrganizationProfileClick = () => { | ||||||||||||||||||||||||||||
| sendTrack({ | ||||||||||||||||||||||||||||
| eventName: "click-event-portal", | ||||||||||||||||||||||||||||
| eventValue: { | ||||||||||||||||||||||||||||
| link: organizationProfileHref, | ||||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||||
| }); | ||||||||||||||||||||||||||||
| }; | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| const goToPrev = () => { | ||||||||||||||||||||||||||||
| setActiveIndex((i) => (i - 1 + orgList.length) % orgList.length); | ||||||||||||||||||||||||||||
| }; | ||||||||||||||||||||||||||||
| const goToNext = () => { | ||||||||||||||||||||||||||||
| setActiveIndex((i) => (i + 1) % orgList.length); | ||||||||||||||||||||||||||||
| }; | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| return ( | ||||||||||||||||||||||||||||
| <div | ||||||||||||||||||||||||||||
| id="event-detail__right" | ||||||||||||||||||||||||||||
| className={clsx( | ||||||||||||||||||||||||||||
| "bg-white rounded-xl mb-4 lg:mb-0", | ||||||||||||||||||||||||||||
| !props.showDescriptionContainer && "w-full", | ||||||||||||||||||||||||||||
| props.showDescriptionContainer && "md:w-4/12", | ||||||||||||||||||||||||||||
| )} | ||||||||||||||||||||||||||||
| > | ||||||||||||||||||||||||||||
| <div className="p-4"> | ||||||||||||||||||||||||||||
| {showOrgSwitcher && ( | ||||||||||||||||||||||||||||
| <div className="flex justify-between items-center mb-1"> | ||||||||||||||||||||||||||||
| <span className="text-lg font-bold text-gray-600"> | ||||||||||||||||||||||||||||
| {t("event.hostOrganizationCounter", { index: activeIndex + 1, total: orgList.length })} | ||||||||||||||||||||||||||||
| </span> | ||||||||||||||||||||||||||||
| <div | ||||||||||||||||||||||||||||
| className="inline-flex p-1.5 gap-1 items-stretch rounded-xl bg-slate-100/95" | ||||||||||||||||||||||||||||
| role="group" | ||||||||||||||||||||||||||||
| aria-label={t("event.hostSwitchGroupAria")} | ||||||||||||||||||||||||||||
| > | ||||||||||||||||||||||||||||
| <button | ||||||||||||||||||||||||||||
| type="button" | ||||||||||||||||||||||||||||
| onClick={goToPrev} | ||||||||||||||||||||||||||||
| className="rounded-lg px-2.5 py-1.5 text-slate-600 bg-white hover:shadow-sm transition-[color,box-shadow] duration-150 focus:outline-none focus-visible:ring-2 focus-visible:ring-slate-300/80 focus-visible:ring-offset-1" | ||||||||||||||||||||||||||||
| aria-label={t("event.prevHostOrganization")} | ||||||||||||||||||||||||||||
| > | ||||||||||||||||||||||||||||
| <IoChevronBack className="text-lg" aria-hidden /> | ||||||||||||||||||||||||||||
| </button> | ||||||||||||||||||||||||||||
| <button | ||||||||||||||||||||||||||||
| type="button" | ||||||||||||||||||||||||||||
| onClick={goToNext} | ||||||||||||||||||||||||||||
| className="rounded-lg px-2.5 py-1.5 text-slate-600 bg-white hover:shadow-sm transition-[color,box-shadow] duration-150 focus:outline-none focus-visible:ring-2 focus-visible:ring-slate-300/80 focus-visible:ring-offset-1" | ||||||||||||||||||||||||||||
| aria-label={t("event.nextHostOrganization")} | ||||||||||||||||||||||||||||
| > | ||||||||||||||||||||||||||||
| <IoChevronForward className="text-lg" aria-hidden /> | ||||||||||||||||||||||||||||
| </button> | ||||||||||||||||||||||||||||
| </div> | ||||||||||||||||||||||||||||
| </div> | ||||||||||||||||||||||||||||
| )} | ||||||||||||||||||||||||||||
| <div className="flex"> | ||||||||||||||||||||||||||||
| {organization.logoUrl && ( | ||||||||||||||||||||||||||||
| <div className="border rounded flex justify-center items-center p-2 w-[100px] h-[100px]"> | ||||||||||||||||||||||||||||
| <NextImage | ||||||||||||||||||||||||||||
| className="object-contain" | ||||||||||||||||||||||||||||
| alt={t("organization.logoAlt", { name: organization.name })} | ||||||||||||||||||||||||||||
| width={200} | ||||||||||||||||||||||||||||
| height={200} | ||||||||||||||||||||||||||||
| src={organization.logoUrl} | ||||||||||||||||||||||||||||
| autoFormat | ||||||||||||||||||||||||||||
| /> | ||||||||||||||||||||||||||||
| </div> | ||||||||||||||||||||||||||||
| )} | ||||||||||||||||||||||||||||
| <div className="ml-4 flex flex-col justify-between"> | ||||||||||||||||||||||||||||
| <div> | ||||||||||||||||||||||||||||
| <Link | ||||||||||||||||||||||||||||
| className="text-2xl font-bold text-gray-600" | ||||||||||||||||||||||||||||
| href={organizationProfileHref} | ||||||||||||||||||||||||||||
| onClick={trackOrganizationProfileClick} | ||||||||||||||||||||||||||||
| > | ||||||||||||||||||||||||||||
| {organization.name} | ||||||||||||||||||||||||||||
| </Link> | ||||||||||||||||||||||||||||
| <div className="flex items-center text-gray-500 mb-4"> | ||||||||||||||||||||||||||||
| <span className="text-sm"> | ||||||||||||||||||||||||||||
| <OrganizationStatus status={organization.status || ""} /> | ||||||||||||||||||||||||||||
| </span> | ||||||||||||||||||||||||||||
| </div> | ||||||||||||||||||||||||||||
| </div> | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| <Link href={organizationProfileHref} onClick={trackOrganizationProfileClick}> | ||||||||||||||||||||||||||||
| <button | ||||||||||||||||||||||||||||
| type="button" | ||||||||||||||||||||||||||||
| className="border rounded px-2 py-1 text-sm text-gray-500 hover:border-slate-400 hover:drop-shadow transition duration-200" | ||||||||||||||||||||||||||||
| > | ||||||||||||||||||||||||||||
| {t("event.gotoOrganization")} | ||||||||||||||||||||||||||||
| </button> | ||||||||||||||||||||||||||||
| </Link> | ||||||||||||||||||||||||||||
| </div> | ||||||||||||||||||||||||||||
| </div> | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| <div | ||||||||||||||||||||||||||||
| className={clsx( | ||||||||||||||||||||||||||||
| "items-center text-gray-500 grid gap-4 mt-4", | ||||||||||||||||||||||||||||
| !props.showDescriptionContainer && "lg:grid-cols-2", | ||||||||||||||||||||||||||||
| )} | ||||||||||||||||||||||||||||
| > | ||||||||||||||||||||||||||||
| {organization.website && <WebsiteButton t={t} href={organization.website} />} | ||||||||||||||||||||||||||||
| {organization.qqGroup && <QQGroupButton t={t} text={organization.qqGroup} />} | ||||||||||||||||||||||||||||
| {organization.bilibili && <BiliButton t={t} href={organization.bilibili} />} | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| {organization.weibo && <WeiboButton t={t} href={organization.weibo} />} | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| {organization.twitter && <TwitterButton t={t} href={organization.twitter} />} | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| {organization.contactMail && <EmailButton t={t} mail={organization.contactMail} />} | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| {organization.plurk && <PlurkButton t={t} href={organization.plurk} />} | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| {organization.facebook && <FacebookButton t={t} href={organization.facebook} />} | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| {organization.rednote && <RednoteButton t={t} href={organization.rednote} />} | ||||||||||||||||||||||||||||
| </div> | ||||||||||||||||||||||||||||
| </div> | ||||||||||||||||||||||||||||
| </div> | ||||||||||||||||||||||||||||
| ); | ||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||
Uh oh!
There was an error while loading. Please reload this page.