-
Notifications
You must be signed in to change notification settings - Fork 2
View proposal with tiptap docs #484
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
valentin0h
wants to merge
12
commits into
dev
Choose a base branch
from
tiptap-view-proposal-doc-ui
base: dev
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+266
−148
Open
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
815c7ea
Hook up view proposal with tiptap docs
valentin0h 2dff17d
Use TipTap generateText for proposal content preview
valentin0h 0572e9f
Use TipTap generateText for proposal content preview
valentin0h 0b6090f
extract proposal content utils and add DocumentNotAvailable component
valentin0h 8d5c1d3
no document state
valentin0h 721082d
simplify proposal content utils and update translations
valentin0h eca8c7a
simplify
valentin0h a5a164f
handle malformed tiptap json gracefully
valentin0h 20deddd
update jsdocs
valentin0h 03b41c6
empty vs not loaded
valentin0h 3a90527
always use existing collab id
valentin0h b63431d
fix tests
valentin0h File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
27 changes: 27 additions & 0 deletions
27
apps/app/src/components/decisions/DocumentNotAvailable.tsx
This file contains hidden or 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,27 @@ | ||
| 'use client'; | ||
|
|
||
| import { cn } from '@op/ui/utils'; | ||
| import { LuFileQuestion } from 'react-icons/lu'; | ||
|
|
||
| import { useTranslations } from '@/lib/i18n'; | ||
|
|
||
| /** Shown when document content failed to load from the collaboration server. */ | ||
| export function DocumentNotAvailable({ className }: { className?: string }) { | ||
| const t = useTranslations(); | ||
|
|
||
| return ( | ||
| <div | ||
| className={cn( | ||
| 'flex flex-col items-center justify-center gap-3 py-8 text-center', | ||
| className, | ||
| )} | ||
| > | ||
| <div className="flex size-8 items-center justify-center rounded-full bg-neutral-gray1"> | ||
| <LuFileQuestion className="size-4 text-neutral-gray4" /> | ||
| </div> | ||
| <p className="text-sm text-neutral-gray4"> | ||
| {t('Content could not be loaded')} | ||
| </p> | ||
| </div> | ||
| ); | ||
| } |
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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,56 @@ | ||
| import type { proposalEncoder } from '@op/api/encoders'; | ||
| import { getTextPreview } from '@op/core'; | ||
| import { defaultViewerExtensions } from '@op/ui/RichTextEditor'; | ||
| import { type JSONContent, generateText } from '@tiptap/core'; | ||
| import type { Content } from '@tiptap/react'; | ||
| import type { z } from 'zod'; | ||
|
|
||
| type Proposal = z.infer<typeof proposalEncoder>; | ||
| type DocumentContent = NonNullable<Proposal['documentContent']>; | ||
|
|
||
| /** | ||
| * Extracts content from proposal documentContent for use with RichTextViewer. | ||
| * Returns Content for rendering, or null if no content available. | ||
| */ | ||
| export function getProposalContent( | ||
| documentContent?: DocumentContent, | ||
| ): Content | null { | ||
| if (!documentContent) { | ||
| return null; | ||
| } | ||
|
|
||
| if (documentContent.type === 'json') { | ||
| return { | ||
| type: 'doc', | ||
| content: documentContent.content, | ||
| } as JSONContent; | ||
| } | ||
|
|
||
| return documentContent.content; | ||
| } | ||
|
|
||
| /** Extracts plain text preview from proposal content. */ | ||
| export function getProposalContentPreview( | ||
| documentContent?: DocumentContent, | ||
| ): string | null { | ||
| if (!documentContent) { | ||
| return null; | ||
| } | ||
|
|
||
| if (documentContent.type === 'json') { | ||
| try { | ||
| const doc = { | ||
| type: 'doc', | ||
| content: documentContent.content as JSONContent[], | ||
| }; | ||
| const text = generateText(doc, defaultViewerExtensions); | ||
| return text.trim(); | ||
| } catch { | ||
| return null; | ||
| } | ||
| } | ||
|
|
||
| return ( | ||
| getTextPreview({ content: documentContent.content, maxLines: 3 }) ?? '' | ||
| ); | ||
| } |
This file contains hidden or 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 hidden or 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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We shouldn't end up in this state, but if we handle it by creating a new doc.