|
1 |
| -import React, { useCallback, useState } from "react" |
| 1 | +import React, { useCallback, useState, useEffect } from "react" |
2 | 2 |
|
3 | 3 | import { Post, ImageUpload } from "@fider/models"
|
4 | 4 | import { Avatar, UserName, Button, Form, MultiImageUploader } from "@fider/components"
|
@@ -33,6 +33,12 @@ export const CommentInput = (props: CommentInputProps) => {
|
33 | 33 | const [isSignInModalOpen, setIsSignInModalOpen] = useState(false)
|
34 | 34 | const [attachments, setAttachments] = useState<ImageUpload[]>([])
|
35 | 35 | const [error, setError] = useState<Failure | undefined>(undefined)
|
| 36 | + const [isClient, setIsClient] = useState(false) |
| 37 | + |
| 38 | + // Check if we're running on the client after component mounts |
| 39 | + useEffect(() => { |
| 40 | + setIsClient(true) |
| 41 | + }, []) |
36 | 42 |
|
37 | 43 | const hideModal = () => setIsSignInModalOpen(false)
|
38 | 44 | const clearError = () => setError(undefined)
|
@@ -76,21 +82,30 @@ export const CommentInput = (props: CommentInputProps) => {
|
76 | 82 | <UserName user={Fider.session.user} />
|
77 | 83 | </div>
|
78 | 84 | )}
|
79 |
| - <CommentEditor |
80 |
| - disabled={!Fider.session.isAuthenticated} |
81 |
| - onChange={commentChanged} |
82 |
| - onFocus={editorFocused} |
83 |
| - initialValue={getContentFromCache()} |
84 |
| - placeholder={i18n._("showpost.commentinput.placeholder", { message: "Leave a comment" })} |
85 |
| - /> |
86 |
| - |
87 |
| - {hasContent && ( |
| 85 | + |
| 86 | + {/* Only render interactive components on the client side */} |
| 87 | + {isClient ? ( |
88 | 88 | <>
|
89 |
| - <MultiImageUploader field="attachments" maxUploads={2} onChange={setAttachments} /> |
90 |
| - <Button variant="primary" onClick={submit}> |
91 |
| - <Trans id="action.submit">Submit</Trans> |
92 |
| - </Button> |
| 89 | + <CommentEditor |
| 90 | + disabled={!Fider.session.isAuthenticated} |
| 91 | + onChange={commentChanged} |
| 92 | + onFocus={editorFocused} |
| 93 | + initialValue={getContentFromCache()} |
| 94 | + placeholder={i18n._("showpost.commentinput.placeholder", { message: "Leave a comment" })} |
| 95 | + /> |
| 96 | + |
| 97 | + {hasContent && ( |
| 98 | + <> |
| 99 | + <MultiImageUploader field="attachments" maxUploads={2} onChange={setAttachments} /> |
| 100 | + <Button variant="primary" onClick={submit}> |
| 101 | + <Trans id="action.submit">Submit</Trans> |
| 102 | + </Button> |
| 103 | + </> |
| 104 | + )} |
93 | 105 | </>
|
| 106 | + ) : ( |
| 107 | + // Simple placeholder for SSR |
| 108 | + <div className="comment-input-placeholder p-2">{i18n._("showpost.commentinput.placeholder", { message: "Leave a comment" })}</div> |
94 | 109 | )}
|
95 | 110 | </Form>
|
96 | 111 | </div>
|
|
0 commit comments