adding metadata
This commit is contained in:
parent
613d7ed2f4
commit
b6b3b75434
53
app/(app)/event/[naddr]/layout.tsx
Normal file
53
app/(app)/event/[naddr]/layout.tsx
Normal file
@ -0,0 +1,53 @@
|
||||
import type { Metadata, ResolvingMetadata } from "next";
|
||||
import { get } from "@/lib/server-actions/events/cache";
|
||||
|
||||
type Props = {
|
||||
params: { naddr: string };
|
||||
searchParams: { [key: string]: string | string[] | undefined };
|
||||
};
|
||||
|
||||
export async function generateMetadata(
|
||||
{ params, searchParams }: Props,
|
||||
parent: ResolvingMetadata,
|
||||
): Promise<Metadata> {
|
||||
// read route params
|
||||
const identifier = params.naddr;
|
||||
|
||||
// fetch data
|
||||
const event = await get(identifier);
|
||||
|
||||
// optionally access and extend (rather than replace) parent metadata
|
||||
const previousImages = (await parent).openGraph?.images || [];
|
||||
if (!event) {
|
||||
return {
|
||||
title: "Flockstr Event",
|
||||
openGraph: {
|
||||
images: previousImages,
|
||||
},
|
||||
};
|
||||
}
|
||||
const title = `${event.name} | Flockstr`;
|
||||
return {
|
||||
title: title,
|
||||
description: event.description,
|
||||
openGraph: {
|
||||
title: title,
|
||||
description: event.description,
|
||||
images: [event.image, ...previousImages],
|
||||
},
|
||||
twitter: {
|
||||
title: title,
|
||||
description: event.description,
|
||||
images: [event.image],
|
||||
card: "summary_large_image",
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
export default function metadataLayout({
|
||||
children,
|
||||
}: {
|
||||
children: React.ReactNode;
|
||||
}) {
|
||||
<>{children}</>;
|
||||
}
|
@ -1,7 +1,5 @@
|
||||
"use client";
|
||||
import { useState } from "react";
|
||||
import Image from "next/image";
|
||||
import Link from "next/link";
|
||||
import { useEffect } from "react";
|
||||
import { nip19 } from "nostr-tools";
|
||||
import useEvents from "@/lib/hooks/useEvents";
|
||||
import Spinner from "@/components/spinner";
|
||||
@ -19,6 +17,8 @@ import LocationContainer from "./_components/LocationContainer";
|
||||
import AnnouncementsContainer from "./_components/AnnouncementsContainer";
|
||||
import DiscussionContainer from "./_components/DiscussionContainer";
|
||||
import AttendeesContainer from "./_components/AttendeesContainer";
|
||||
import { add, get } from "@/lib/server-actions/events/cache";
|
||||
import { BANNER } from "@/constants";
|
||||
|
||||
export default function EventPage({
|
||||
params: { naddr },
|
||||
@ -41,6 +41,29 @@ export default function EventPage({
|
||||
},
|
||||
});
|
||||
const event = events[0];
|
||||
useEffect(() => {
|
||||
console.log("EFFECT CALLED", event);
|
||||
if (event) {
|
||||
const { tags, content } = event;
|
||||
const name = getTagValues("name", tags) ?? "Untitled";
|
||||
const image =
|
||||
getTagValues("image", tags) ??
|
||||
getTagValues("picture", tags) ??
|
||||
getTagValues("banner", tags) ??
|
||||
BANNER;
|
||||
console.log("setting event");
|
||||
add({
|
||||
identifier: naddr,
|
||||
name: name,
|
||||
description: content,
|
||||
image: image,
|
||||
});
|
||||
(async () => {
|
||||
const res = await get(naddr);
|
||||
console.log("RESPONE", res);
|
||||
})();
|
||||
}
|
||||
}, [event]);
|
||||
|
||||
if (!event) {
|
||||
return (
|
||||
|
8
lib/clients/redis/index.ts
Normal file
8
lib/clients/redis/index.ts
Normal file
@ -0,0 +1,8 @@
|
||||
import { Redis } from "@upstash/redis";
|
||||
|
||||
const redis = new Redis({
|
||||
url: "https://us1-new-mako-37785.upstash.io",
|
||||
token: process.env.UPSTASH_REDIS_REST_TOKEN as string,
|
||||
});
|
||||
|
||||
export { redis };
|
34
lib/server-actions/events/cache/index.ts
vendored
Normal file
34
lib/server-actions/events/cache/index.ts
vendored
Normal file
@ -0,0 +1,34 @@
|
||||
"use server";
|
||||
import { redis } from "@/lib/clients/redis";
|
||||
import { z } from "zod";
|
||||
|
||||
const eventSchema = z.object({
|
||||
identifier: z.string(),
|
||||
name: z.string(),
|
||||
description: z.string(),
|
||||
image: z.string(),
|
||||
});
|
||||
|
||||
export async function get(identifier: string) {
|
||||
const data = await redis.get(identifier);
|
||||
console.log("Data", data);
|
||||
try {
|
||||
const parsedData = eventSchema.parse({ identifier, ...(data as Object) });
|
||||
return parsedData;
|
||||
} catch (err) {
|
||||
console.log("Error", err);
|
||||
return;
|
||||
}
|
||||
}
|
||||
export async function add(data: z.infer<typeof eventSchema>) {
|
||||
let { identifier, name, description, image } = data;
|
||||
try {
|
||||
redis.set(identifier, { name, description, image });
|
||||
return {
|
||||
success: true,
|
||||
};
|
||||
} catch (err) {
|
||||
console.log("Error", err);
|
||||
return;
|
||||
}
|
||||
}
|
@ -1,5 +1,9 @@
|
||||
/** @type {import('next').NextConfig} */
|
||||
const nextConfig = {
|
||||
experimental: {
|
||||
serverActions: true,
|
||||
swcPlugins: ["next-superjson-plugin"],
|
||||
},
|
||||
async rewrites() {
|
||||
return [
|
||||
{
|
||||
|
@ -32,6 +32,7 @@
|
||||
"@radix-ui/react-tooltip": "^1.0.7",
|
||||
"@react-google-maps/api": "^2.19.2",
|
||||
"@tailwindcss/container-queries": "^0.1.1",
|
||||
"@upstash/redis": "^1.24.3",
|
||||
"aws-sdk": "^2.1475.0",
|
||||
"buffer": "^6.0.3",
|
||||
"class-variance-authority": "^0.7.0",
|
||||
|
Loading…
x
Reference in New Issue
Block a user