Skip to content

Commit

Permalink
feat: use new API replace Xata (#202)
Browse files Browse the repository at this point in the history
* feat: use new API replace Xata

* fix: fix zod schema

* chore: kick out xata and superjson

* chore: use new type

* chore: update CI env
  • Loading branch information
PaiJi authored Sep 6, 2024
1 parent 49a6e0e commit 1d0fc46
Show file tree
Hide file tree
Showing 27 changed files with 1,384 additions and 1,174 deletions.
13 changes: 4 additions & 9 deletions .env.example
Original file line number Diff line number Diff line change
@@ -1,14 +1,9 @@
# API key used by the CLI and the SDK
# Make sure your framework/tooling loads this file on startup to have it available for the SDK
XATA_API_KEY=
# Xata branch that will be used if there's not a xata branch with the same name as your git branch
XATA_BRANCH=main
XATA_FALLBACK_BRANCH=main

NEXT_PUBLIC_ENABLE_TRACK=false
SENTRY_AUTH_TOKEN=
NEXT_PUBLIC_SENTRY_DSN=

FEC_API_TOKEN=

NEXT_PUBLIC_ENABLE_TRACK=false
NEXT_PUBLIC_REGION=GLOBAL
NEXT_PUBLIC_WEBSITE_URL=www.furryeventchina.com
NEXT_PUBLIC_STATIC_CDN_URL=https://static.furrycons.cn
NEXT_PUBLIC_SENTRY_DSN=
4 changes: 4 additions & 0 deletions .github/workflows/deploy-self-host.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ jobs:
NEXT_PUBLIC_REGION: ${{ vars.NEXT_PUBLIC_REGION }}
NEXT_PUBLIC_STATIC_CDN_URL: ${{vars.NEXT_PUBLIC_STATIC_CDN_URL}}
NEXT_PUBLIC_WEBSITE_URL: ${{vars.NEXT_PUBLIC_WEBSITE_URL}}
FEC_API_TOKEN: ${{vars.FEC_API_TOKEN}}
steps:
- name: Checkout repository
uses: actions/checkout@v4
Expand All @@ -34,6 +35,7 @@ jobs:
echo NEXT_PUBLIC_ENABLE_TRACK="$ENABLE_TRACK" >> .env
echo NEXT_PUBLIC_STATIC_CDN_URL="$NEXT_PUBLIC_STATIC_CDN_URL" >>.env
echo NEXT_PUBLIC_WEBSITE_URL="$NEXT_PUBLIC_WEBSITE_URL" >>.env
echo FEC_API_TOKEN="$FEC_API_TOKEN" >>.env
- name: Login to ACR
uses: aliyun/acr-login@v1
Expand Down Expand Up @@ -62,6 +64,7 @@ jobs:
NEXT_PUBLIC_REGION: ${{ vars.NEXT_PUBLIC_REGION }}
NEXT_PUBLIC_SENTRY_DSN: ${{vars.NEXT_PUBLIC_SENTRY_DSN}}
NEXT_PUBLIC_WEBSITE_URL: ${{vars.NEXT_PUBLIC_WEBSITE_URL}}
FEC_API_TOKEN: ${{vars.FEC_API_TOKEN}}
steps:
- name: Checkout repository
uses: actions/checkout@v4
Expand All @@ -76,6 +79,7 @@ jobs:
echo NEXT_PUBLIC_REGION="$NEXT_PUBLIC_REGION" >>.env
echo NEXT_PUBLIC_SENTRY_DSN="$NEXT_PUBLIC_SENTRY_DSN" >>.env
echo NEXT_PUBLIC_WEBSITE_URL="$NEXT_PUBLIC_WEBSITE_URL" >>.env
echo FEC_API_TOKEN="$FEC_API_TOKEN" >>.env
- name: Login to ACR
uses: aliyun/acr-login@v1
Expand Down
5 changes: 3 additions & 2 deletions .github/workflows/nextjs_bundle_analysis.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Copyright (c) HashiCorp, Inc.
# SPDX-License-Identifier: MPL-2.0

name: 'Next.js Bundle Analysis'
name: "Next.js Bundle Analysis"

on:
pull_request:
Expand Down Expand Up @@ -29,6 +29,7 @@ jobs:
XATA_FALLBACK_BRANCH: ${{ vars.XATA_FALLBACK_BRANCH }}
SENTRY_AUTH_TOKEN: ${{ secrets.SENTRY_AUTH_TOKEN }}
NEXT_PUBLIC_ENABLE_TRACK: ${{ vars.ENABLE_TRACK }}
FEC_API_TOKEN: ${{vars.FEC_API_TOKEN}}
steps:
- uses: actions/checkout@v3

Expand Down Expand Up @@ -117,7 +118,7 @@ jobs:
id: fc
with:
issue-number: ${{ github.event.number }}
body-includes: '<!-- __NEXTJS_BUNDLE -->'
body-includes: "<!-- __NEXTJS_BUNDLE -->"

- name: Create Comment
uses: peter-evans/create-or-update-comment@v2
Expand Down
2 changes: 1 addition & 1 deletion .nvmrc
Original file line number Diff line number Diff line change
@@ -1 +1 @@
lts/hydrogen
lts/iron
10 changes: 9 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
![](https://img.shields.io/badge/Sentry-purple.svg?style=flat-square&logo=sentry)
![](https://img.shields.io/badge/Umami-orange.svg?style=flat-square&logo=umami)
![](https://img.shields.io/badge/Google%20Analytics%205-blue.svg?style=flat-square&logo=google-analytics)
![](https://img.shields.io/badge/Xata-blue.svg?style=flat-square&logo=xata)
![](https://img.shields.io/badge/Hono.js-blue.svg?style=flat-square&logo=hono)
![](https://img.shields.io/badge/Cloudflare%20R2-blue.svg?style=flat-square&logo=cloudflare)
![](https://img.shields.io/badge/Cloudflare%20Worker-blue.svg?style=flat-square&logo=cloudflare)
![](https://img.shields.io/badge/CloudFront-orange.svg?style=flat-square&logo=amazon-aws)
Expand All @@ -16,7 +16,15 @@

## Start Developing

### Env config

Copy `.env.example` and paste it, `FEC_API_TOKEN` needs to be obtained by registering in our console, the rest like Sentry do not need configuration.

```bash
nvm use

corepack enable

yarn install
yarn dev
```
Expand Down
10 changes: 9 additions & 1 deletion README.zh.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
![](https://img.shields.io/badge/Sentry-purple.svg?style=flat-square&logo=sentry)
![](https://img.shields.io/badge/Umami-orange.svg?style=flat-square&logo=umami)
![](https://img.shields.io/badge/Google%20Analytics%205-blue.svg?style=flat-square&logo=google-analytics)
![](https://img.shields.io/badge/Xata-blue.svg?style=flat-square&logo=xata)
![](https://img.shields.io/badge/Hono.js-blue.svg?style=flat-square&logo=hono)
![](https://img.shields.io/badge/Cloudflare%20R2-blue.svg?style=flat-square&logo=cloudflare)
![](https://img.shields.io/badge/Cloudflare%20Worker-blue.svg?style=flat-square&logo=cloudflare)
![](https://img.shields.io/badge/CloudFront-orange.svg?style=flat-square&logo=amazon-aws)
Expand All @@ -16,7 +16,15 @@

## 开始开发

### 配置环境变量

复制 `.env.example`并粘贴,`FEC_API_TOKEN`需在我们的控制台注册获取,其余如 Sentry 等无需配置。

```bash
nvm use

corepack enable

yarn install
yarn dev
```
Expand Down
14 changes: 3 additions & 11 deletions next.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@ const { withSentryConfig } = require("@sentry/nextjs");
const { GitRevisionPlugin } = require("git-revision-webpack-plugin");

const withBundleAnalyzer = require("@next/bundle-analyzer")({
enabled: process.env.NODE_ENV === "production",
enabled:
process.env.NODE_ENV === "production" &&
process.env.NEXT_PUBLIC_ENABLE_TRACK === "true",
});

const { i18n } = require("./next-i18next.config");
Expand All @@ -31,16 +33,6 @@ const nextConfig = {
loaderFile: "./src/utils/imageLoader.ts",
},
assetPrefix: isProd && STATIC_CDN_URL ? STATIC_CDN_URL : undefined,
experimental: {
swcPlugins: [
[
"next-superjson-plugin",
{
excluded: [],
},
],
],
},
sentry: {
// disableClientWebpackPlugin: true,
// disableServerWebpackPlugin: true,
Expand Down
28 changes: 13 additions & 15 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,30 +7,27 @@
"build": "next build && next-sitemap",
"start": "next start",
"lint": "next lint",
"generate-schama": "xata codegen",
"clean": "rm -rf .next && rm -rf out"
},
"dependencies": {
"@headlessui/react": "^2.1.3",
"@next/third-parties": "^14.2.7",
"@headlessui/react": "^2.1.5",
"@next/third-parties": "^14.2.8",
"@radix-ui/react-collapsible": "^1.1.0",
"@sentry/nextjs": "^7.119.0",
"@xata.io/client": "^0.29.5",
"autoprefixer": "^10.4.20",
"clsx": "^2.1.1",
"date-fns": "^3.6.0",
"embla-carousel-autoplay": "^8.2.0",
"embla-carousel-react": "^8.2.0",
"embla-carousel-autoplay": "^8.2.1",
"embla-carousel-react": "^8.2.1",
"eslint": "8.57.0",
"eslint-config-next": "14.2.7",
"eslint-config-next": "14.2.8",
"git-revision-webpack-plugin": "^5.0.0",
"i18next": "^23.14.0",
"lodash-es": "^4.17.21",
"next": "14.2.7",
"next": "14.2.8",
"next-i18next": "^15.3.1",
"next-sitemap": "^4.2.3",
"next-superjson-plugin": "^0.6.3",
"postcss": "^8.4.41",
"postcss": "^8.4.45",
"postcss-flexbugs-fixes": "^5.0.2",
"postcss-nested": "^6.2.0",
"postcss-preset-env": "^9.6.0",
Expand All @@ -39,18 +36,19 @@
"react-hot-toast": "^2.4.1",
"react-i18next": "^15.0.1",
"react-icons": "^5.3.0",
"superjson": "1.13.3",
"tailwindcss": "^3.4.10",
"typescript": "5.5.4"
"typescript": "5.5.4",
"wretch": "^2.9.0",
"zod": "^3.23.8"
},
"devDependencies": {
"@next/bundle-analyzer": "^14.2.7",
"@next/bundle-analyzer": "^14.2.8",
"@types/lodash-es": "^4.17.12",
"@types/node": "20.16.2",
"@types/node": "20.16.5",
"@types/react": "18.3.5",
"@types/react-dom": "18.3.0"
},
"packageManager": "yarn@4.0.2",
"packageManager": "yarn@4.4.1",
"nextBundleAnalysis": {
"budget": 358400,
"budgetPercentIncreaseRed": 20,
Expand Down
2 changes: 1 addition & 1 deletion public/locales/en/common.json
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@
},
"organization": {
"active": "Active Organizers",
"deactive": "Inactive Organizers",
"inactive": "Inactive Organizers",
"createdAt": "Established {{distance}} ago",
"firstTimeEvent": "First held on {{year}}/{{month}}/{{day}}",
"firstTimeShow": "First appeared on {{year}}/{{month}}/{{day}}",
Expand Down
2 changes: 1 addition & 1 deletion public/locales/zh-Hans/common.json
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@
},
"organization": {
"active": "活跃展商",
"deactive": "停止活动展商",
"inactive": "停止活动展商",
"createdAt": "已创立 {{distance}}",
"firstTimeEvent": "首次举办于 {{year}}年{{month}}月{{day}}日",
"firstTimeShow": "首次出现于 {{year}}年{{month}}月{{day}}日",
Expand Down
14 changes: 14 additions & 0 deletions src/api/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import wretch from "wretch";
import QueryStringAddon from "wretch/addons/queryString";

wretch.options({ mode: "cors" });

const HOST =
process.env.NEXT_PUBLIC_REGION === "CN"
? "https://api.furrycons.cn"
: "https://api.furryeventchina.com";

const wfetch = wretch(HOST, { cache: "default" })
.auth(`Bearer ${process.env.FEC_API_TOKEN}`)
.addon(QueryStringAddon);
export default wfetch;
26 changes: 6 additions & 20 deletions src/components/SimpleEventCard/index.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { sendTrack } from "@/utils/track";
import { Event } from "@/xata/xata";
import Link from "next/link";
import { format } from "date-fns";
import { EventType } from "@/types/event";

function SimpleEventCard({ event }: { event: Event }) {
function SimpleEventCard({ event }: { event: EventType }) {
return (
<Link
key={event.id}
Expand All @@ -19,27 +19,13 @@ function SimpleEventCard({ event }: { event: Event }) {
}
className="rounded-xl shadow relative flex justify-center items-center group bg-white"
>
{/* <div className="rounded-xl duration-500 transition group-hover:border-gray-400 w-full h-full absolute brightness-75 hover:brightness-100">
<Image
alt="活动背景"
src={getEventCoverUrl(event)}
width={350}
className="h-full w-full object-cover rounded-xl overflow-hidden"
autoFormat
/>
</div> */}
<div className="z-10 relative pointer-events-none p-2">
<h4 className="tracking-wide text-slate-700 font-bold text-base text-center group-hover:text-red-400 transition">{`${event.city} · ${event.name}`}</h4>
<h4 className="tracking-wide text-slate-700 font-bold text-base text-center group-hover:text-red-400 transition">{`${event.addressExtra?.city} · ${event.name}`}</h4>
<p className="text-center text-slate-600">{event.organization?.name}</p>
{event.startDate && event.endDate && (
{event.startAt && event.endAt && (
<p className="text-center text-slate-600 text-sm">
{event.startDate && (
<span>{format(event.startDate, "MM月dd日")}</span>
)}
-
{event.endDate && (
<span>{format(event.endDate, "MM月dd日")}</span>
)}
{event.startAt && <span>{format(event.startAt, "MM月dd日")}</span>}-
{event.endAt && <span>{format(event.endAt, "MM月dd日")}</span>}
</p>
)}
</div>
Expand Down
14 changes: 7 additions & 7 deletions src/components/eventCard/index.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { Event } from "@/xata/xata";
import Link from "next/link";
import React, { useEffect } from "react";
import styles from "@/components/eventCard/index.module.css";
Expand All @@ -10,6 +9,7 @@ import { sendTrack } from "@/utils/track";
import { getEventCoverImgPath } from "@/utils/imageLoader";
import { format } from "date-fns";
import { zhCN } from "date-fns/locale";
import { EventType } from "@/types/event";

let instancesCount = 0;

Expand All @@ -19,7 +19,7 @@ export default function EventCard({
fallbackWidth,
fallbackHeight,
}: {
event: Event;
event: EventType;
sizes?: string;
fallbackWidth?: number;
fallbackHeight?: number;
Expand Down Expand Up @@ -115,7 +115,7 @@ export default function EventCard({
event.organization?.logoUrl ? "pl-1" : "pl-2"
)}
>
{event.city}
{event.addressExtra?.city}
</span>
</div>
</div>
Expand All @@ -131,14 +131,14 @@ export default function EventCard({
<h4 className=" font-bold text-base md:text-2xl">{event.name}</h4>
<h5 className="text-sm md:text-lg">{event.organization?.name}</h5>
<div className="text-xs md:text-base">
{event.startDate && event.endDate && (
{event.startAt && event.endAt && (
<div className="flex items-center" suppressHydrationWarning>
<BsCalendar2DateFill className="mr-1 flex-shrink-0 text-sm" />
{event.startDate && event.endDate
? `${format(event.startDate, "yyyy/MM/dd", {
{event.startAt && event.endAt
? `${format(event.startAt, "yyyy/MM/dd", {
locale: zhCN,
})} -
${format(event.endDate, "yyyy/MM/dd", { locale: zhCN })}`
${format(event.endAt, "yyyy/MM/dd", { locale: zhCN })}`
: null}
</div>
)}
Expand Down
2 changes: 1 addition & 1 deletion src/components/organizationStatus/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export function getOranizationStatusConfig(status: string) {
switch (status) {
case "active":
return { label: "活跃", color: "text-green-400" };
case "deactive":
case "inactive":
return { label: "停止活动", color: "text-red-400" };
default:
return { label: "未知状态", color: "text-gray-400" };
Expand Down
39 changes: 39 additions & 0 deletions src/pages/500.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import { sendTrack } from "@/utils/track";
import Link from "next/link";
import { useEffect } from "react";

export default function Custom500() {
useEffect(() => {
sendTrack({
eventName: "Viewed 500 page",
eventValue: {
href: window.location.href,
},
});
}, []);

return (
<main className="grid min-h-full place-items-center bg-white rounded-2xl px-6 py-24 sm:py-32 lg:px-8">
<div className="text-center">
<p className="text-base font-semibold text-red-400">500</p>
<h1 className="mt-4 text-3xl font-bold tracking-tight text-red-400 sm:text-5xl">
遭遇内部错误...
</h1>
<p className="mt-6 text-base leading-7 text-gray-600">
Who is my fearless hero?
</p>
<div className="mt-10 flex items-center justify-center gap-x-6">
<Link
href="/"
className="rounded-md bg-red-400 px-3.5 py-2.5 text-sm font-semibold text-white shadow-sm hover:bg-red-500 focus-visible:outline focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-indigo-600"
>
回到首页
</Link>
{/* <a href="#" className="text-sm font-semibold text-gray-900">
通知管理员 <span aria-hidden="true">&rarr;</span>
</a> */}
</div>
</div>
</main>
);
}
Loading

0 comments on commit 1d0fc46

Please sign in to comment.