From f9f404a1169c5509006b5009ecd2f0e6a6ec374d Mon Sep 17 00:00:00 2001 From: Thibault Le Ouay Date: Tue, 7 Nov 2023 21:43:44 +0100 Subject: [PATCH] =?UTF-8?q?=E2=8C=9B=20add=20suspense=20=20(#447)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * ⌛ * ⌛ * ⌛ * chore: suspense * feat: widget docs and suspense * chore: docs * chore: bump version * feat: add props to package.json --------- Co-authored-by: mxkaske --- apps/web/src/app/page.tsx | 75 +-------------- apps/web/src/app/play/page.tsx | 2 +- .../components/layout/marketing-footer.tsx | 5 +- .../layout/status-widget-suspense.tsx | 21 +++++ apps/web/src/components/marketing/example.tsx | 48 ++++++++++ apps/web/src/components/marketing/hero.tsx | 76 ++++++++++++++++ apps/web/src/components/tracker.tsx | 2 +- apps/web/src/lib/github.ts | 1 + packages/react/README.md | 91 +++++++++++++++++-- packages/react/package.json | 11 ++- packages/react/src/widget.tsx | 2 +- 11 files changed, 246 insertions(+), 88 deletions(-) create mode 100644 apps/web/src/components/layout/status-widget-suspense.tsx create mode 100644 apps/web/src/components/marketing/example.tsx create mode 100644 apps/web/src/components/marketing/hero.tsx diff --git a/apps/web/src/app/page.tsx b/apps/web/src/app/page.tsx index da708bd2..42f333e9 100644 --- a/apps/web/src/app/page.tsx +++ b/apps/web/src/app/page.tsx @@ -1,89 +1,22 @@ -import Link from "next/link"; -import { ClerkProvider } from "@clerk/nextjs"; -import { ChevronRight } from "lucide-react"; - -import { Badge, Button } from "@openstatus/ui"; - import { Shell } from "@/components/dashboard/shell"; import { MarketingLayout } from "@/components/layout/marketing-layout"; import { Cards, SpecialCard } from "@/components/marketing/cards"; +import { Example } from "@/components/marketing/example"; import { FAQs } from "@/components/marketing/faqs"; +import { Hero } from "@/components/marketing/hero"; import { Partners } from "@/components/marketing/partners"; import { Plans } from "@/components/marketing/plans"; import { Stats } from "@/components/marketing/stats"; -import { Tracker } from "@/components/tracker"; import { cardConfig, specialCardConfig } from "@/config/features"; -import { getGitHubStars } from "@/lib/github"; -import { getHomeMonitorListData } from "@/lib/tb"; -import { numberFormatter } from "@/lib/utils"; export const revalidate = 600; export default async function Page() { - const data = await getHomeMonitorListData(); - const stars = await getGitHubStars(); return (
- - - - Announcement Post - - -

- Open-source monitoring service -

-

- OpenStatus is an open source monitoring services with incident - managements. -

- {/* much better than using flex without text alignment, text stays center even thought not same length */} -
-
- -
-
- -
-
-
- -

Status

- -
- {data && ( - - )} -
-
+ + diff --git a/apps/web/src/app/play/page.tsx b/apps/web/src/app/play/page.tsx index 6fd10b20..0e4e01d3 100644 --- a/apps/web/src/app/play/page.tsx +++ b/apps/web/src/app/play/page.tsx @@ -13,7 +13,7 @@ export default async function PlayPage() { {data && ( diff --git a/apps/web/src/components/layout/marketing-footer.tsx b/apps/web/src/components/layout/marketing-footer.tsx index d0bd6040..fb622b2b 100644 --- a/apps/web/src/components/layout/marketing-footer.tsx +++ b/apps/web/src/components/layout/marketing-footer.tsx @@ -1,10 +1,9 @@ import Link from "next/link"; import { ArrowUpRight } from "lucide-react"; -import { StatusWidget } from "@openstatus/react"; - import { cn } from "@/lib/utils"; import { Shell } from "../dashboard/shell"; +import { StatusWidgetContainer } from "./status-widget-suspense"; interface Props { className?: string; @@ -16,7 +15,7 @@ export function MarketingFooter({ className }: Props) {
- +

Community

diff --git a/apps/web/src/components/layout/status-widget-suspense.tsx b/apps/web/src/components/layout/status-widget-suspense.tsx new file mode 100644 index 00000000..45999bd4 --- /dev/null +++ b/apps/web/src/components/layout/status-widget-suspense.tsx @@ -0,0 +1,21 @@ +import { Suspense } from "react"; + +import type { StatusWidgetProps } from "@openstatus/react"; +import { StatusWidget } from "@openstatus/react"; + +export function StatusWidgetFallback() { + return ( +
+ + +
+ ); +} + +export function StatusWidgetContainer(props: StatusWidgetProps) { + return ( + }> + + + ); +} diff --git a/apps/web/src/components/marketing/example.tsx b/apps/web/src/components/marketing/example.tsx new file mode 100644 index 00000000..3aa99e21 --- /dev/null +++ b/apps/web/src/components/marketing/example.tsx @@ -0,0 +1,48 @@ +import { Suspense } from "react"; +import Link from "next/link"; + +import { Button } from "@openstatus/ui"; + +import { Shell } from "@/components/dashboard/shell"; +import { Tracker } from "@/components/tracker"; +import { getHomeMonitorListData } from "@/lib/tb"; + +export async function Example() { + return ( + +

Status

+ +
+ }> + + +
+
+ ); +} + +function ExampleTrackerFallback() { + return ( + + ); +} + +async function ExampleTracker() { + const data = await getHomeMonitorListData(); + if (!data) return null; + return ( + + ); +} diff --git a/apps/web/src/components/marketing/hero.tsx b/apps/web/src/components/marketing/hero.tsx new file mode 100644 index 00000000..d2388474 --- /dev/null +++ b/apps/web/src/components/marketing/hero.tsx @@ -0,0 +1,76 @@ +import { Suspense } from "react"; +import Link from "next/link"; +import { ChevronRight } from "lucide-react"; + +import { Badge, Button } from "@openstatus/ui"; + +import { Shell } from "@/components/dashboard/shell"; +import { getGitHubStars } from "@/lib/github"; +import { numberFormatter } from "@/lib/utils"; + +export function Hero() { + return ( + + + + Announcement Post + + +

+ Open-source monitoring service +

+

+ OpenStatus is an open source monitoring services with incident + managements. +

+ {/* much better than using flex without text alignment, text stays center even thought not same length */} +
+
+ +
+
+ +
+
+
+ ); +} + +function StarsBadgeFallback() { + return ( + + ~ + + ); +} + +async function StarsBadge() { + const stars = await getGitHubStars(); + return ( + <> + + {numberFormatter(stars)} + + + {stars} + + + ); +} diff --git a/apps/web/src/components/tracker.tsx b/apps/web/src/components/tracker.tsx index d1e6c80f..56ee16ef 100644 --- a/apps/web/src/components/tracker.tsx +++ b/apps/web/src/components/tracker.tsx @@ -157,7 +157,7 @@ const Bar = ({

{getStatus(ratio).label}

{context === "play" ? ( diff --git a/apps/web/src/lib/github.ts b/apps/web/src/lib/github.ts index b63f836c..c78e0174 100644 --- a/apps/web/src/lib/github.ts +++ b/apps/web/src/lib/github.ts @@ -7,6 +7,7 @@ const schema = z.object({ export async function getGitHubStars() { const res = await fetch( "https://api.github.com/repos/openstatusHQ/openstatus", + { next: { revalidate: 600 } }, // 10min ); const json = await res.json(); const github = schema.safeParse(json); diff --git a/packages/react/README.md b/packages/react/README.md index 606bb17d..1c2c33e0 100644 --- a/packages/react/README.md +++ b/packages/react/README.md @@ -1,24 +1,97 @@ ## Status Widget -Create an account on [openstatus.dev](https://openstatus.dev) and integrate a -simple wiget into your React Application. +Create an account on [openstatus.dev](https://openstatus.dev), start monitoring +your endpoints and include your own StatusWidget into your React Application. + +![Image of StatusWidget on openstatus.dev](https://openstatus.dev/assets/changelog/status-widget.png) ### Install ```bash npm install @openstatus/react +pnpm add @openstatus/react +yarn add @openstatus/react +bun add @openstatus/react ``` -```bash -pnpm add @openstatus/react +### How to use the StatusWidget in your Next.js App Router + +#### Include the styles.css + +If you are using tailwind, extend your config with: + +```js +// tailwind.config.js +module.exports = { + content: [ + "./app/**/*.{tsx,ts,mdx,md}", + // OpenStatus Widget + "./node_modules/@openstatus/react/**/*.{js,ts,jsx,tsx}", + ], + theme: { + extend: {}, + }, + plugins: [], +}; ``` -```bash -yarn add @openstatus/react +Otherwise, include the styles in your App: + +```tsx +// app/layout.tsx +import "@openstatus/react/dist/styles.css"; ``` -```bash -bun add @openstatus/react +The `StatusWidget` is a React Server Component. Include the `slug` to your +status-page. + +```tsx +import { StatusWidget } from "@openstatus/react"; + +export function Page() { + return ; +} ``` -Learn more [here](https://docs.openstatus.dev/packages/react). +### Headless getStatus utility function + +If you would like to style it yourself, you can use the `getStatus` function to +access the type response of the api call to: + +`https://api.openstatus.dev/public/status/:slug` + +Learn more about our supported +[API endpoints](https://docs.openstatus.dev/api-reference/auth). + +```ts +import { getStatus } from "@openstatus/react"; + +// React Server Component +async function CustomStatusWidget() { + const res = await getStatus("slug"); + // ^StatusResponse = { status: Status } + + const { status } = res; + // ^Status = "unknown" | "operational" | "degraded_performance" | "partial_outage" | "major_outage" | "under_maintenance" + + return
{/* customize */}
; +} +``` + +```ts +export type Status = + | "operational" + | "degraded_performance" + | "partial_outage" + | "major_outage" + | "under_maintenance" + | "unknown"; +``` + +Learn more in the [docs](https://docs.openstatus.dev/packages/react). + +#### About OpenStatus + +OpenStatus is an open source monitoring services with incident managements. + +Follow our journey [@openstatusHQ](https://x.com/openstatusHQ). diff --git a/packages/react/package.json b/packages/react/package.json index 1999a6f9..43188fc4 100644 --- a/packages/react/package.json +++ b/packages/react/package.json @@ -1,6 +1,12 @@ { "name": "@openstatus/react", - "version": "0.0.1", + "version": "0.0.2", + "repository": { + "type": "git", + "url": "https://github.com/openstatusHQ/openstatus.git" + }, + "keywords": ["openstatus", "react", "monitoring"], + "homepage": "https://github.com/openstatusHQ/openstatus#readme", "main": "./dist/index.js", "types": "./dist/index.d.ts", "module": "./dist/index.mjs", @@ -9,7 +15,8 @@ ], "license": "MIT", "scripts": { - "dev":"tsup && pnpm run build:tailwind", + "dev":"tsup --watch && pnpm run dev:tailwind", + "dev:tailwind": "tailwindcss -i ./src/styles.css -o ./dist/styles.css --watch", "build:tailwind": "tailwindcss -i ./src/styles.css -o ./dist/styles.css --minify", "build": "tsup && pnpm run build:tailwind" }, diff --git a/packages/react/src/widget.tsx b/packages/react/src/widget.tsx index f0491720..08d20a7a 100644 --- a/packages/react/src/widget.tsx +++ b/packages/react/src/widget.tsx @@ -23,7 +23,7 @@ export async function getStatus(slug: string): Promise { return { status: "unknown" }; } -type StatusWidgetProps = { +export type StatusWidgetProps = { slug: string; href?: string; }; -- 2.51.2