sel-chat-coach / src /app /docs /api /page.tsx
james-d-taboola's picture
feat: Change coach ad prompt threshold from 15 to 6 messages and hide UI elements
651c1af
'use client';
import { useEffect, useState } from 'react';
import yaml from 'js-yaml';
import SwaggerUI from '@/components/SwaggerUIWrapper';
export default function APIDocsPage() {
const [spec, setSpec] = useState<any>(null);
const [error, setError] = useState<string | null>(null);
useEffect(() => {
// Fetch and parse the OpenAPI spec
fetch('/docs/openapi.yaml')
.then(res => {
if (!res.ok) {
throw new Error(`Failed to load OpenAPI spec: ${res.statusText}`);
}
return res.text();
})
.then(text => {
const parsed = yaml.load(text);
setSpec(parsed);
})
.catch(err => {
console.error('Error loading OpenAPI spec:', err);
setError(err.message);
});
}, []);
if (error) {
return (
<div style={{ padding: '2rem' }}>
<h1>API Documentation</h1>
<div style={{ color: 'red', marginTop: '1rem' }}>
<strong>Error:</strong> {error}
</div>
<p style={{ marginTop: '1rem' }}>
Make sure the OpenAPI spec file exists at <code>/docs/openapi.yaml</code>
</p>
</div>
);
}
if (!spec) {
return (
<div style={{ padding: '2rem' }}>
<h1>API Documentation</h1>
<p>Loading API specification...</p>
</div>
);
}
return (
<div style={{ maxWidth: '1400px', margin: '0 auto' }}>
<SwaggerUI spec={spec} />
</div>
);
}