diff --git a/website/src/app/page.module.css b/website/src/app/page.module.css index 4329015..27d2ede 100644 --- a/website/src/app/page.module.css +++ b/website/src/app/page.module.css @@ -206,6 +206,49 @@ line-height: 1.5; } +.hydrationSection { + padding: 6rem 15em; + min-height: 50vh; + display: flex; + align-items: center; + justify-content: center; + position: relative; + border-top: 1px solid var(--gray-alpha-200); +} + +.hydrationContainer { + display: flex; + gap: 4rem; + justify-content: space-between; + align-items: center; + width: 100%; + max-width: 1200px; +} + +.hydrationCode { + flex: 1; + min-width: 45%; +} + +.hydrationText { + flex: 1; + padding: 2rem; +} + +.hydrationText h2 { + color: #ff0080; + margin: 0 0 1.5rem 0; + font-size: 2rem; +} + +.hydrationText p { + color: #fff; + opacity: 0.8; + margin: 1rem 0; + font-size: 1.1rem; + line-height: 1.6; +} + @media (max-width: 1200px) { .pillars { padding: 4rem 2rem; @@ -220,4 +263,22 @@ max-width: 400px; margin: 0 auto; } -} \ No newline at end of file + + .hydrationSection { + padding: 4rem 2rem; + } + + .hydrationContainer { + flex-direction: column; + gap: 2rem; + } + + .hydrationCode { + width: 100%; + } + + .hydrationText { + width: 100%; + padding: 1rem; + } +} diff --git a/website/src/app/page.tsx b/website/src/app/page.tsx index e5a73d1..b8ab9c9 100644 --- a/website/src/app/page.tsx +++ b/website/src/app/page.tsx @@ -2,9 +2,12 @@ import styles from "./page.module.css"; import dynamic from 'next/dynamic'; const CodeExample = dynamic( - () => import('../components/CodeExample') + () => import('../components/CodeExample'), + { ssr: false } ); +import { simpleExample, hydrationExample } from '../components/CodeExample'; + export default function Home() { return (
@@ -25,7 +28,7 @@ export default function Home() {

- +
@@ -48,6 +51,28 @@ export default function Home() { + +
+
+
+ +
+
+

Smart Hydration

+

+ Unicord's hydration system automatically manages Discord object lifecycles. + The context.hydrate method intelligently fetches and caches Discord objects + like messages, users, and guilds, ensuring your bot stays efficient while + keeping your code clean and predictable. +

+

+ In this example, we're hydrating a message object to calculate ping times, + demonstrating how Unicord handles complex Discord API interactions with + simple, intuitive code. +

+
+
+
); diff --git a/website/src/components/CodeExample.tsx b/website/src/components/CodeExample.tsx index 7f2c1dc..7fb94e6 100644 --- a/website/src/components/CodeExample.tsx +++ b/website/src/components/CodeExample.tsx @@ -1,10 +1,38 @@ 'use client'; -import { useRef } from 'react'; import Editor from "@monaco-editor/react"; import styles from './CodeExample.module.css'; -const exampleCode = `\ +type CodeExampleProps = { + code: string; + height?: string | number; +} + +export default function CodeExample({ code, height = "100%" }: CodeExampleProps) { + return ( +
+ +
+ ); +} + +// Export the example code snippets for reuse +export const simpleExample = `\ import { Client, type Context } from 'unicord'; // Initialize and configure @@ -28,25 +56,14 @@ client.chatCommands.register('ping', (context: Context, args) => { // Connect client.connect();`; -export default function CodeExample() { - return ( -
- -
- ); -} +export const hydrationExample = `\ +client.chatCommands.register('ping', async (context: Context, args: any[]) => { + // Hydrate the message id from the context + const { message } = await context.hydrate(context, [Expectation.Message]); + // Send a message to the channel + const response = await context.reply(\`Pong!: got \${args.join(', ')}\`, true); + // Calculate the time it took to send the message + const time = message.timestamp.getTime() - message.timestamp.getTime(); + // Edit the message to include the time + await context.editMessage(response, \`Pong! Latency: \${time}ms\`); +});`;