-
Notifications
You must be signed in to change notification settings - Fork 28
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into jb/redirect-from-unauthorized-page
- Loading branch information
Showing
49 changed files
with
1,853 additions
and
246 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
68 changes: 68 additions & 0 deletions
68
apps/course-builder-web/sanity/schemas/documents/article.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
import {MdArticle} from 'react-icons/md' | ||
import {defineField} from 'sanity' | ||
|
||
export default { | ||
name: 'article', | ||
type: 'document', | ||
title: 'Article', | ||
icon: MdArticle, | ||
fields: [ | ||
defineField({ | ||
name: 'title', | ||
title: 'Title', | ||
type: 'string', | ||
validation: (Rule) => Rule.required(), | ||
}), | ||
defineField({ | ||
name: 'state', | ||
title: 'Current State', | ||
type: 'string', | ||
validation: (Rule) => Rule.required(), | ||
initialValue: 'draft', | ||
options: { | ||
list: [ | ||
{title: 'draft', value: 'draft'}, | ||
{title: 'published', value: 'published'}, | ||
], | ||
}, | ||
}), | ||
defineField({ | ||
name: 'slug', | ||
title: 'Slug', | ||
type: 'slug', | ||
validation: (Rule) => Rule.required(), | ||
options: { | ||
source: 'title', | ||
maxLength: 96, | ||
}, | ||
}), | ||
{ | ||
name: 'body', | ||
title: 'Body', | ||
type: 'markdown', | ||
}, | ||
{ | ||
name: 'summary', | ||
title: 'Summary', | ||
type: 'markdown', | ||
}, | ||
{ | ||
name: 'concepts', | ||
title: 'Concepts', | ||
type: 'array', | ||
of: [ | ||
{ | ||
type: 'reference', | ||
to: [{type: 'concept'}], | ||
}, | ||
], | ||
}, | ||
defineField({ | ||
name: 'description', | ||
title: 'Short Description', | ||
description: 'Used as a short "SEO" summary on Twitter cards etc.', | ||
type: 'text', | ||
validation: (Rule) => Rule.max(160), | ||
}), | ||
], | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
import Link from 'next/link' | ||
import {Button} from '@coursebuilder/ui' | ||
import * as React from 'react' | ||
import {getServerAuthSession} from '@/server/auth' | ||
import {getAbility} from '@/lib/ability' | ||
import ReactMarkdown from 'react-markdown' | ||
import {getArticle} from '@/lib/articles' | ||
import {notFound} from 'next/navigation' | ||
|
||
export default async function ArticlePage({ | ||
params, | ||
}: { | ||
params: {article: string} | ||
}) { | ||
const session = await getServerAuthSession() | ||
const ability = getAbility({user: session?.user}) | ||
const article = await getArticle(params.article) | ||
|
||
console.log('******', {article}) | ||
|
||
if (!article) { | ||
notFound() | ||
} | ||
|
||
return ( | ||
<div> | ||
{ability.can('edit', 'Article') ? ( | ||
<div className="flex h-9 w-full items-center justify-between bg-muted px-1"> | ||
<div /> | ||
<Button asChild className="h-7"> | ||
<Link href={`/articles/${article.slug || article._id}/edit`}> | ||
Edit | ||
</Link> | ||
</Button> | ||
</div> | ||
) : null} | ||
<article className="grid grid-cols-5 p-5 sm:p-10"> | ||
<div className="col-span-3"> | ||
<h1 className="text-3xl font-bold">{article.title}</h1> | ||
</div> | ||
<div className="col-span-2"> | ||
<ReactMarkdown className="prose dark:prose-invert"> | ||
{article.body} | ||
</ReactMarkdown> | ||
<ReactMarkdown>{article.summary}</ReactMarkdown> | ||
</div> | ||
</article> | ||
</div> | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
// ./app/api/chat/route.js | ||
import OpenAI from 'openai' | ||
import {OpenAIStream, StreamingTextResponse} from 'ai' | ||
|
||
const openai = new OpenAI({ | ||
apiKey: process.env.OPENAI_API_KEY, | ||
}) | ||
|
||
export const runtime = 'edge' | ||
|
||
export async function POST(req: Request) { | ||
const {messages} = await req.json() | ||
const response = await openai.chat.completions.create({ | ||
model: 'gpt-4', | ||
stream: true, | ||
messages, | ||
}) | ||
const stream = OpenAIStream(response) | ||
return new StreamingTextResponse(stream) | ||
} |
21 changes: 21 additions & 0 deletions
21
apps/course-builder-web/src/app/articles/[slug]/edit/page.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import * as React from 'react' | ||
import {getServerAuthSession} from '@/server/auth' | ||
import {getAbility} from '@/lib/ability' | ||
import {EditArticleForm} from '@/app/articles/_components/edit-article-form' | ||
import {getArticle} from '@/lib/articles' | ||
|
||
export default async function ArticleEditPage({ | ||
params, | ||
}: { | ||
params: {slug: string} | ||
}) { | ||
const session = await getServerAuthSession() | ||
const ability = getAbility({user: session?.user}) | ||
const article = await getArticle(params.slug) | ||
|
||
return article && ability.can('upload', 'Media') ? ( | ||
<div className="relative mx-auto flex h-full w-full flex-grow flex-col items-center justify-center"> | ||
<EditArticleForm key={article.slug} article={article} /> | ||
</div> | ||
) : null | ||
} |
Oops, something went wrong.