Skip to content

Commit

Permalink
chore: single codemirror component
Browse files Browse the repository at this point in the history
instead of using multiple components and being confused all the time, now it is just the one
  • Loading branch information
joelhooks committed Jan 8, 2024
1 parent 28d49ff commit e04099c
Show file tree
Hide file tree
Showing 7 changed files with 69 additions and 164 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import {useCallback, useEffect, useState} from 'react'
import {markdown} from '@codemirror/lang-markdown'
import YPartyKitProvider from 'y-partykit/provider'
import {useSession} from 'next-auth/react'
import {SearchCursor} from '@codemirror/search'
import {SearchCursor, SearchQuery} from '@codemirror/search'
import {Decoration} from '@codemirror/view'
import {FeedbackMarker} from '@/lib/feedback-marker'

Expand Down Expand Up @@ -145,14 +145,20 @@ const useCodemirror = ({
for (let marker of markers) {
let cursor = new SearchCursor(view.state.doc, marker.originalText)

let query = new SearchQuery({
search: marker.originalText,
caseSensitive: false,
})

console.log('-----', query.getCursor(view.state.doc).next())

while (!cursor.done) {
cursor.next()
console.log('+++++', query.getCursor(view.state.doc).next())
const highlight_decoration = Decoration.mark({
attributes: {style: 'background-color: yellow'},
})

console.log({cursor, highlight_decoration})

view.dispatch({
effects: highlight_effect.of([
highlight_decoration.range(
Expand Down Expand Up @@ -198,6 +204,7 @@ const useCodemirror = ({
// Set up awareness

return () => {
provider?.doc?.destroy()
provider?.destroy()
view?.destroy()
}
Expand Down
157 changes: 0 additions & 157 deletions apps/course-builder-web/src/app/articles/_components/codemirror.tsx

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,14 @@ import {api} from '@/trpc/react'
import {useRouter} from 'next/navigation'
import {ArticleAssistant} from './article-assistant'
import Link from 'next/link'
import {CodemirrorEditor} from './codemirror'
import {ImagePlusIcon, ZapIcon} from 'lucide-react'
import {CloudinaryUploadWidget} from './cloudinary-upload-widget'
import {CloudinaryMediaBrowser} from './cloudinary-media-browser'
import {cn} from '@/lib/utils'
import {Article} from '@/lib/articles'
import {useSocket} from '@/hooks/use-socket'
import {FeedbackMarker} from '@/lib/feedback-marker'
import {CodemirrorEditor} from '@/app/_components/codemirror'

const ArticleFormSchema = z.object({
title: z.string().min(2).max(90),
Expand Down
42 changes: 42 additions & 0 deletions apps/course-builder-web/src/app/articles/page.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import {CardTitle, CardHeader, CardContent, Card} from '@coursebuilder/ui'
import {getServerAuthSession} from '@/server/auth'
import {getAbility} from '@/lib/ability'
import * as React from 'react'
import Link from 'next/link'
import {sanityQuery} from '@/server/sanity.server'

export default async function ArticlesIndexPage() {
const session = await getServerAuthSession()
const ability = getAbility({user: session?.user})
const articles = await sanityQuery<
{
_id: string
title: string
slug: string
}[]
>(`*[_type == "article"]{
_id,
title,
"slug": slug.current,
}`)

return (
<div className="grid h-full flex-grow grid-cols-5 gap-3 bg-muted p-5">
<div className="col-span-3 flex h-full flex-grow flex-col space-y-2">
<h2 className="text-lg font-bold">Articles</h2>
{articles.map((article) => (
<Card key={article._id}>
<CardHeader>
<CardTitle>
<Link href={`/${article.slug || article._id}`}>
{article.title}
</Link>
</CardTitle>
</CardHeader>
<CardContent></CardContent>
</Card>
))}
</div>
</div>
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,13 @@ import {useRouter} from 'next/navigation'
import {type Tip} from '@/lib/tips'
import {TipAssistant} from './tip-assistant'
import Link from 'next/link'
import {CodemirrorEditor} from '@/app/tips/_components/codemirror'
import {ImagePlusIcon, ZapIcon} from 'lucide-react'
import {CloudinaryUploadWidget} from './cloudinary-upload-widget'
import {CloudinaryMediaBrowser} from './cloudinary-media-browser'
import {cn} from '@/lib/utils'
import {FeedbackMarker} from '@/lib/feedback-marker'
import {useSocket} from '@/hooks/use-socket'
import {CodemirrorEditor} from '@/app/_components/codemirror'

const NewTipFormSchema = z.object({
title: z.string().min(2).max(90),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export const generateFeedbackMarkers = inngest.createFunction(
name: 'Generate Feedback Markers',
debounce: {
key: 'event.data.resourceId',
period: '5s',
period: '15s',
},
},
{event: BODY_TEXT_UPDATED},
Expand Down Expand Up @@ -47,6 +47,10 @@ export const generateFeedbackMarkers = inngest.createFunction(
* don't waste our time with feedback that is not actionable
* harsh feedback is OK, no need to spare our feelings
* act like the authority that you are
* do keep the feedback premium and useful
* do exclude feedback that is marginal or not actionable
* focus on ideas over grammar
* limit the feedback to the the top three issues
## Feedback Marker Zod Schema
Expand All @@ -72,7 +76,7 @@ export const generateFeedbackMarkers = inngest.createFunction(
${JSON.stringify(event.data.currentFeedback)}
## Template\n\n{markers:[{"originalText": "quoted from the text", "feedback": "useful feedback", "fullSuggestedChange": "rewritten text that captures the feedback meaningfully", "level": "critical", "type": "grammar"}]}`,
## Template\n\n{markers:[{"originalText": "quoted from the text", "feedback": "useful feedback", "fullSuggestedChange": "rewritten text that captures the feedback meaningfully", "level": "how much attention is needed?", "type": "a single word that describes the type of change"}]}`,
role: 'system',
},
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,15 @@ export const articleChat = inngest.createFunction(
})

if (messages.length === 1 && systemPrompt) {
if (event.data.currentFeedback) {
messages = [
{
content: JSON.stringify(event.data.currentFeedback),
role: 'assistant',
},
...messages,
]
}
messages = [systemPrompt, ...messages]
}

Expand Down

0 comments on commit e04099c

Please sign in to comment.