Skip to content

Commit a55887e

Browse files
fix: random ai generated code && fix progressbar
1 parent 088c92d commit a55887e

File tree

12 files changed

+369
-114
lines changed

12 files changed

+369
-114
lines changed

packages/api/schema.gql

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,14 @@ type Comment {
66
published: Boolean!
77
}
88

9+
type PaperComment {
10+
text: String!
11+
userId: ID!
12+
lastName: String!
13+
firstName: String!
14+
published: Boolean!
15+
}
16+
917
"""
1018
An object that can have comments
1119
"""
@@ -125,7 +133,7 @@ input PaperEntryInput {
125133
question: String!
126134
answer: String
127135
hint: String
128-
comments: [String!]!
136+
comments: [PaperCommentInput!]!
129137
}
130138

131139
type MutatePaperPayload {
@@ -503,6 +511,14 @@ type Report implements CommentableInterface {
503511
nextReportLink: String
504512
}
505513

514+
input PaperCommentInput {
515+
text: String!
516+
userId: ID!
517+
firstName: String!
518+
lastName: String!
519+
published: Boolean!
520+
}
521+
506522
"""
507523
Represents the current state of the report
508524
"""
@@ -730,7 +746,7 @@ type PaperFormData {
730746
question: String!
731747
answer: String
732748
hint: String
733-
comments: [String!]!
749+
comments: [PaperComment!]!
734750
}
735751

736752
type Paper {

packages/api/src/graphql.ts

Lines changed: 34 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -562,9 +562,26 @@ export type GqlPaper = {
562562
trainerId: Scalars['ID']['output'];
563563
};
564564

565+
export type GqlPaperComment = {
566+
__typename?: 'PaperComment';
567+
firstName: Scalars['String']['output'];
568+
lastName: Scalars['String']['output'];
569+
published: Scalars['Boolean']['output'];
570+
text: Scalars['String']['output'];
571+
userId: Scalars['ID']['output'];
572+
};
573+
574+
export type GqlPaperCommentInput = {
575+
firstName: Scalars['String']['input'];
576+
lastName: Scalars['String']['input'];
577+
published: Scalars['Boolean']['input'];
578+
text: Scalars['String']['input'];
579+
userId: Scalars['ID']['input'];
580+
};
581+
565582
export type GqlPaperEntryInput = {
566583
answer?: InputMaybe<Scalars['String']['input']>;
567-
comments: Array<Scalars['String']['input']>;
584+
comments: Array<GqlPaperCommentInput>;
568585
hint?: InputMaybe<Scalars['String']['input']>;
569586
id: Scalars['ID']['input'];
570587
question: Scalars['String']['input'];
@@ -574,7 +591,7 @@ export type GqlPaperEntryInput = {
574591
export type GqlPaperFormData = {
575592
__typename?: 'PaperFormData';
576593
answer?: Maybe<Scalars['String']['output']>;
577-
comments: Array<Scalars['String']['output']>;
594+
comments: Array<GqlPaperComment>;
578595
hint?: Maybe<Scalars['String']['output']>;
579596
id: Scalars['ID']['output'];
580597
question: Scalars['String']['output'];
@@ -959,6 +976,8 @@ export type GqlResolversTypes = ResolversObject<{
959976
Mutation: ResolverTypeWrapper<{}>;
960977
OAuthPayload: ResolverTypeWrapper<GqlOAuthPayload>;
961978
Paper: ResolverTypeWrapper<Paper>;
979+
PaperComment: ResolverTypeWrapper<GqlPaperComment>;
980+
PaperCommentInput: GqlPaperCommentInput;
962981
PaperEntryInput: GqlPaperEntryInput;
963982
PaperFormData: ResolverTypeWrapper<GqlPaperFormData>;
964983
PaperInput: GqlPaperInput;
@@ -1014,6 +1033,8 @@ export type GqlResolversParentTypes = ResolversObject<{
10141033
Mutation: {};
10151034
OAuthPayload: GqlOAuthPayload;
10161035
Paper: Paper;
1036+
PaperComment: GqlPaperComment;
1037+
PaperCommentInput: GqlPaperCommentInput;
10171038
PaperEntryInput: GqlPaperEntryInput;
10181039
PaperFormData: GqlPaperFormData;
10191040
PaperInput: GqlPaperInput;
@@ -1231,9 +1252,18 @@ export type GqlPaperResolvers<ContextType = Context, ParentType extends GqlResol
12311252
__isTypeOf?: IsTypeOfResolverFn<ParentType, ContextType>;
12321253
}>;
12331254

1255+
export type GqlPaperCommentResolvers<ContextType = Context, ParentType extends GqlResolversParentTypes['PaperComment'] = GqlResolversParentTypes['PaperComment']> = ResolversObject<{
1256+
firstName?: Resolver<GqlResolversTypes['String'], ParentType, ContextType>;
1257+
lastName?: Resolver<GqlResolversTypes['String'], ParentType, ContextType>;
1258+
published?: Resolver<GqlResolversTypes['Boolean'], ParentType, ContextType>;
1259+
text?: Resolver<GqlResolversTypes['String'], ParentType, ContextType>;
1260+
userId?: Resolver<GqlResolversTypes['ID'], ParentType, ContextType>;
1261+
__isTypeOf?: IsTypeOfResolverFn<ParentType, ContextType>;
1262+
}>;
1263+
12341264
export type GqlPaperFormDataResolvers<ContextType = Context, ParentType extends GqlResolversParentTypes['PaperFormData'] = GqlResolversParentTypes['PaperFormData']> = ResolversObject<{
12351265
answer?: Resolver<Maybe<GqlResolversTypes['String']>, ParentType, ContextType>;
1236-
comments?: Resolver<Array<GqlResolversTypes['String']>, ParentType, ContextType>;
1266+
comments?: Resolver<Array<GqlResolversTypes['PaperComment']>, ParentType, ContextType>;
12371267
hint?: Resolver<Maybe<GqlResolversTypes['String']>, ParentType, ContextType>;
12381268
id?: Resolver<GqlResolversTypes['ID'], ParentType, ContextType>;
12391269
question?: Resolver<GqlResolversTypes['String'], ParentType, ContextType>;
@@ -1387,6 +1417,7 @@ export type GqlResolvers<ContextType = Context> = ResolversObject<{
13871417
Mutation?: GqlMutationResolvers<ContextType>;
13881418
OAuthPayload?: GqlOAuthPayloadResolvers<ContextType>;
13891419
Paper?: GqlPaperResolvers<ContextType>;
1420+
PaperComment?: GqlPaperCommentResolvers<ContextType>;
13901421
PaperFormData?: GqlPaperFormDataResolvers<ContextType>;
13911422
PrintPayload?: GqlPrintPayloadResolvers<ContextType>;
13921423
PublishCommentsPayload?: GqlPublishCommentsPayloadResolvers<ContextType>;

packages/components/src/comment-bubble-layout.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ export const CommentBubbleLayout: React.FC<CommentBubbleLayoutProps> = ({
9898
return (
9999
<MessageContainer right={right}>
100100
<Bubble right={right}>
101-
<Author>{author}:</Author>
101+
<Author>{author}</Author>
102102
{updateMessage ? (
103103
<MessageInput
104104
value={msg}

packages/frontend/src/components/comment-box.tsx

Lines changed: 54 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,25 @@
11
import React from 'react'
22

3-
import { Comment, useCommentBoxDataQuery, UserInterface } from '../graphql'
3+
import { Comment, PaperComment, useCommentBoxDataQuery, UserInterface } from '../graphql'
44
import CommentBubble from './comment-bubble'
55
import Loader from './loader'
66

7+
type TransformedCommentArray =
8+
| Array<
9+
Pick<Comment, 'id' | 'text' | 'published'> & {
10+
user: Pick<UserInterface, 'id' | 'firstName' | 'lastName'>
11+
}
12+
>
13+
| Array<Pick<PaperComment, 'text' | 'published' | 'lastName' | 'firstName' | 'userId'>>
14+
15+
type TransformedComment =
16+
| (Pick<Comment, 'id' | 'text' | 'published'> & {
17+
user: Pick<UserInterface, 'id' | 'firstName' | 'lastName'>
18+
})
19+
| Pick<PaperComment, 'text' | 'published' | 'lastName' | 'firstName' | 'userId'>
20+
721
interface CommentBoxProps {
8-
comments?: (Pick<Comment, 'text' | 'id' | 'published'> & {
9-
user: Pick<UserInterface, 'id' | 'firstName' | 'lastName'>
10-
})[]
22+
comments?: TransformedCommentArray
1123
updateMessage?: (message: string, commentId: string) => void
1224
}
1325

@@ -20,18 +32,50 @@ const CommentBox: React.FunctionComponent<CommentBoxProps> = ({ comments, update
2032

2133
const { currentUser } = data
2234

35+
const getFirstName = (comment: TransformedComment) => {
36+
if ('user' in comment) {
37+
return comment.user.firstName
38+
} else {
39+
return comment.firstName
40+
}
41+
}
42+
43+
const getLastName = (comment: TransformedComment) => {
44+
if ('user' in comment) {
45+
return comment.user.lastName
46+
} else {
47+
return comment.lastName
48+
}
49+
}
50+
51+
const getUserId = (comment: TransformedComment) => {
52+
if ('user' in comment) {
53+
return comment.user.id
54+
} else {
55+
return comment.userId
56+
}
57+
}
58+
59+
const getId = (comment: TransformedComment) => {
60+
if ('id' in comment) {
61+
return comment.id
62+
} else {
63+
return comment.userId
64+
}
65+
}
66+
2367
return (
2468
<>
2569
{comments
2670
? comments.map((comment) => (
2771
<CommentBubble
28-
key={comment.id}
29-
author={`${comment.user.firstName} ${comment.user.lastName}`}
72+
key={getId(comment)}
73+
author={`${getFirstName(comment)} ${getLastName(comment)}`}
3074
message={comment.text}
31-
id={comment.user.id}
32-
right={comment.user.id !== currentUser?.id}
33-
updateMessage={comment.user.id === currentUser?.id && !comment.published ? updateMessage : undefined}
34-
commentId={comment.id}
75+
id={getUserId(comment)}
76+
right={getUserId(comment) !== currentUser?.id}
77+
updateMessage={getUserId(comment) === currentUser?.id && !comment.published ? updateMessage : undefined}
78+
commentId={getId(comment)}
3579
/>
3680
))
3781
: null}

packages/frontend/src/components/comment-section.tsx

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,24 @@ import { useForm } from 'react-hook-form'
33

44
import { ErrorText, Input, Spacer, StyledTextInputLabel } from '@lara/components'
55

6-
import { Comment, UserInterface } from '../graphql'
6+
import { Comment, PaperComment, UserInterface } from '../graphql'
77
import strings from '../locales/localization'
88
import CommentBox from './comment-box'
99

10+
type TransformedCommentArray =
11+
| Array<
12+
Pick<Comment, 'id' | 'text' | 'published'> & {
13+
user: Pick<UserInterface, 'id' | 'firstName' | 'lastName'>
14+
}
15+
>
16+
| Array<Pick<PaperComment, 'text' | 'published' | 'lastName' | 'firstName' | 'userId'>>
17+
1018
interface CommentSectionProps {
11-
comments: (Pick<Comment, 'id' | 'text' | 'published'> & {
12-
user: Pick<UserInterface, 'id' | 'firstName' | 'lastName'>
13-
})[]
19+
comments: TransformedCommentArray
1420
onSubmit: onSubmitType
1521
displayTextInput: boolean
1622
bottomSpace?: boolean
23+
spacingM?: boolean
1724
updateMessage?: (message: string, commentId: string) => void
1825
}
1926

@@ -23,6 +30,7 @@ const CommentSection: React.FunctionComponent<CommentSectionProps> = ({
2330
comments,
2431
bottomSpace,
2532
displayTextInput,
33+
spacingM,
2634
onSubmit: submit,
2735
updateMessage,
2836
}) => {
@@ -43,7 +51,7 @@ const CommentSection: React.FunctionComponent<CommentSectionProps> = ({
4351
<>
4452
<CommentBox comments={comments} updateMessage={updateMessage} />
4553
{displayTextInput && (
46-
<Spacer x="l" bottom={bottomSpace ? 'l' : undefined}>
54+
<Spacer x={spacingM ? 'm' : 'l'} bottom={bottomSpace ? 'l' : undefined}>
4755
<form onSubmit={onSubmit} onBlur={onSubmit}>
4856
<StyledTextInputLabel valid={!errors.comment}>{strings.report.comments.addComment}</StyledTextInputLabel>
4957
<Input

0 commit comments

Comments
 (0)