Skip to content
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

Add new setInput message #1333

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
pass the value param through the component tree
  • Loading branch information
Rich Baird committed Mar 19, 2024
commit 2655c438e0a23476b65efb45c887dc05b3c210ea
8 changes: 7 additions & 1 deletion components/CommentBox.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ interface CommentBoxProps {
className?: string;
onSubmit: (comment: IComment | IReply) => void;
onDiscussionCreateRequest?: () => Promise<string>;
value?: string;
}

export default function CommentBox({
Expand All @@ -25,6 +26,7 @@ export default function CommentBox({
className = '',
onSubmit,
onDiscussionCreateRequest,
value,
}: CommentBoxProps) {
const { t } = useGiscusTranslation();
const [isPreview, setIsPreview] = useState(false);
Expand Down Expand Up @@ -54,7 +56,11 @@ export default function CommentBox({
}
setLastInput(input);
}
}, [isPreview, input, lastInput, token, context]);
if (value && value !== input) {
const processed = processCommentBody(value);
setInput(processed);
}
}, [isPreview, input, lastInput, token, context, value]);

const reset = useCallback(() => {
setInput('');
Expand Down
4 changes: 3 additions & 1 deletion components/Giscus.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,10 @@ import ReactButtons from './ReactButtons';
interface IGiscusProps {
onDiscussionCreateRequest?: () => Promise<string>;
onError?: (message: string) => void;
value?: string;
}

export default function Giscus({ onDiscussionCreateRequest, onError }: IGiscusProps) {
export default function Giscus({ onDiscussionCreateRequest, onError, value }: IGiscusProps) {
const { token, origin } = useContext(AuthContext);
const { t } = useGiscusTranslation();
const {
Expand Down Expand Up @@ -66,6 +67,7 @@ export default function Giscus({ onDiscussionCreateRequest, onError }: IGiscusPr
context={repo}
onSubmit={addNewComment}
onDiscussionCreateRequest={handleDiscussionCreateRequest}
value={value}
/>
);

Expand Down
9 changes: 7 additions & 2 deletions components/Widget.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,10 @@ import { getToken } from '../services/giscus/token';
interface IWidgetProps {
origin: string;
session: string;
value: string;
}

export default function Widget({ origin, session }: IWidgetProps) {
export default function Widget({ origin, session, value }: IWidgetProps) {
const [token, setToken] = useState('');
const [createDiscussionPromise, setCreateDiscussionPromise] = useState<Promise<string>>();
const { repo, repoId, categoryId, description, backLink, term, number } =
Expand Down Expand Up @@ -75,7 +76,11 @@ export default function Widget({ origin, session }: IWidgetProps) {

return ready ? (
<AuthContext.Provider value={{ token, origin, getLoginUrl, onSignOut: handleSignOut }}>
<Giscus onDiscussionCreateRequest={handleDiscussionCreateRequest} onError={handleError} />
<Giscus
onDiscussionCreateRequest={handleDiscussionCreateRequest}
onError={handleError}
value={value}
/>
</AuthContext.Provider>
) : null;
}