@quesmed/types-rn 2.2.91 → 2.2.92

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@quesmed/types-rn",
3
- "version": "2.2.91",
3
+ "version": "2.2.92",
4
4
  "description": "Typescript types for Quesmed",
5
5
  "keywords": [
6
6
  "quesmed",
@@ -9,15 +9,21 @@ interface LikeData {
9
9
  }
10
10
  export declare const getLikeData: (like: EQuestionLike, item: LikeData) => LikeData;
11
11
  export declare const getQuestionTypeName: (typeId: EQuestionType) => string;
12
+ export declare const updatedCommentsOnAdd: (newComment: IQuestionComment, comments: IQuestionComment[], parentId?: number | undefined) => IQuestionComment[];
13
+ export declare const updateCommentsOnRemove: (comments: IQuestionComment[], commentId: number, parentId?: number | undefined) => IQuestionComment[];
14
+ export declare const updatedCommentsInMarksheetQuestion: (cache: ApolloCache<any>, questionComments: IQuestionComment, marksheetId: number, questionId: number, parentId?: number | undefined) => void;
15
+ export declare const updatedCommentsInQuestion: (cache: ApolloCache<any>, questionComments: IQuestionComment, questionId: number, parentId?: number | undefined) => void;
16
+ export declare const updatedRemoveCommentsInMarksheetQuestion: (cache: ApolloCache<any>, marksheetId: number, questionId: number, commentId: number, parentId?: number | undefined) => void;
17
+ export declare const updatedRemoveCommentsInQuestion: (cache: ApolloCache<any>, questionId: number, commentId: number, parentId?: number | undefined) => void;
12
18
  export declare const QUESTION_LIKE: import("@apollo/client").DocumentNode;
13
- export declare const optimisticQuestionLike: (marksheetId: number, client: ApolloClient<any>, input: IQuestionLikeVar) => IQuestionLikeData;
19
+ export declare const optimisticQuestionLike: (client: ApolloClient<any>, input: IQuestionLikeVar, marksheetId?: number | undefined) => IQuestionLikeData;
14
20
  export interface IQuestionLikeVar {
15
21
  questionId: Id;
16
22
  like: EQuestionLike;
17
23
  }
18
24
  export declare type IQuestionLikeData = RestrictedData<graphqlNormalize & IQuestion, 'questionLike'>;
19
25
  export declare const QUESTION_COMMENTS: import("@apollo/client").DocumentNode;
20
- export declare const updateQuestionComments: (marksheetId: number) => (cache: ApolloCache<any>, result: ApolloUpdateResultRestricted<IQuestionCommentsData>, options: ApolloUpdateOptions) => void;
26
+ export declare const updateQuestionComments: (marksheetId?: number | undefined) => (cache: ApolloCache<any>, result: ApolloUpdateResultRestricted<IQuestionCommentsData>, options: ApolloUpdateOptions) => void;
21
27
  export declare const optimisticQuestionComment: (id: number, user: {
22
28
  id: number;
23
29
  displayName: string;
@@ -36,7 +42,7 @@ export interface IQuestionCommentsLikeVar {
36
42
  }
37
43
  export declare type IQuestionCommentsLikeData = RestrictedData<graphqlNormalize & IQuestionComment, 'questionCommentLike'>;
38
44
  export declare const QUESTION_COMMENT_REMOVE: import("@apollo/client").DocumentNode;
39
- export declare const updateQuestionCommentsRemove: (marksheetId: number) => (cache: ApolloCache<any>, result: ApolloUpdateResultRestricted<IQuestionCommentRemoveData>, options: ApolloUpdateOptions) => void;
45
+ export declare const updateQuestionCommentsRemove: (marksheetId?: number | undefined) => (cache: ApolloCache<any>, result: ApolloUpdateResultRestricted<IQuestionCommentRemoveData>, options: ApolloUpdateOptions) => void;
40
46
  export declare const optimisticQuestionCommentRemove: (comments: IQuestionComment[], input: IQuestionCommentRemoveVar, parentId?: number | undefined) => IQuestionCommentRemoveData;
41
47
  export interface IQuestionCommentRemoveVar {
42
48
  commentId: Id;
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.optimisticQuestionCommentRemove = exports.updateQuestionCommentsRemove = exports.QUESTION_COMMENT_REMOVE = exports.optimisticCommentLike = exports.QUESTION_COMMENT_LIKE = exports.optimisticQuestionComment = exports.updateQuestionComments = exports.QUESTION_COMMENTS = exports.optimisticQuestionLike = exports.QUESTION_LIKE = exports.getQuestionTypeName = exports.getLikeData = void 0;
3
+ exports.optimisticQuestionCommentRemove = exports.updateQuestionCommentsRemove = exports.QUESTION_COMMENT_REMOVE = exports.optimisticCommentLike = exports.QUESTION_COMMENT_LIKE = exports.optimisticQuestionComment = exports.updateQuestionComments = exports.QUESTION_COMMENTS = exports.optimisticQuestionLike = exports.QUESTION_LIKE = exports.updatedRemoveCommentsInQuestion = exports.updatedRemoveCommentsInMarksheetQuestion = exports.updatedCommentsInQuestion = exports.updatedCommentsInMarksheetQuestion = exports.updateCommentsOnRemove = exports.updatedCommentsOnAdd = exports.getQuestionTypeName = exports.getLikeData = void 0;
4
4
  const client_1 = require("@apollo/client");
5
5
  const models_1 = require("../../../models");
6
6
  const restricted_1 = require("../../query/restricted");
@@ -43,6 +43,161 @@ const getQuestionTypeName = (typeId) => {
43
43
  }
44
44
  };
45
45
  exports.getQuestionTypeName = getQuestionTypeName;
46
+ const updatedCommentsOnAdd = (newComment, comments, parentId) => {
47
+ if (parentId) {
48
+ const commentIndex = comments.findIndex(({ id }) => Number(id) === parentId);
49
+ const { replies = [], ...commentRest } = comments[commentIndex];
50
+ return [
51
+ ...comments.slice(0, commentIndex),
52
+ { ...commentRest, replies: [...replies, newComment] },
53
+ ...comments.slice(commentIndex + 1),
54
+ ];
55
+ }
56
+ return [...comments, newComment];
57
+ };
58
+ exports.updatedCommentsOnAdd = updatedCommentsOnAdd;
59
+ const updateCommentsOnRemove = (comments, commentId, parentId) => {
60
+ if (parentId) {
61
+ const commentIndex = comments.findIndex(({ id }) => Number(id) === Number(parentId));
62
+ const { replies = [], ...commentRest } = comments[commentIndex];
63
+ return [
64
+ ...comments.slice(0, commentIndex),
65
+ {
66
+ ...commentRest,
67
+ replies: replies.filter(({ id }) => Number(id) !== Number(commentId)),
68
+ },
69
+ ...comments.slice(commentIndex + 1),
70
+ ];
71
+ }
72
+ return comments.filter(({ id }) => Number(id) !== Number(commentId));
73
+ };
74
+ exports.updateCommentsOnRemove = updateCommentsOnRemove;
75
+ const updatedCommentsInMarksheetQuestion = (cache, questionComments, marksheetId, questionId, parentId) => {
76
+ const marksheetData = cache.readQuery({
77
+ variables: { id: marksheetId },
78
+ query: restricted_1.MARKSHEET,
79
+ });
80
+ if (marksheetData) {
81
+ const { marksheet } = marksheetData.restricted || {};
82
+ const { marks, ...marksheetRest } = marksheet;
83
+ const index = marks.findIndex(({ question }) => Number(question.id) === Number(questionId));
84
+ const { question, ...markRest } = marks[index];
85
+ const { comments = [], ...questionRest } = question;
86
+ cache.writeQuery({
87
+ query: restricted_1.MARKSHEET,
88
+ variables: { id: marksheetId },
89
+ data: {
90
+ ...marksheetData,
91
+ restricted: {
92
+ ...marksheetData.restricted,
93
+ marksheet: {
94
+ ...marksheetRest,
95
+ marks: [
96
+ ...marks.slice(0, index),
97
+ {
98
+ ...markRest,
99
+ question: {
100
+ ...questionRest,
101
+ comments: (0, exports.updatedCommentsOnAdd)(questionComments, comments, parentId),
102
+ },
103
+ },
104
+ ...marks.slice(index + 1),
105
+ ],
106
+ },
107
+ },
108
+ },
109
+ });
110
+ }
111
+ };
112
+ exports.updatedCommentsInMarksheetQuestion = updatedCommentsInMarksheetQuestion;
113
+ const updatedCommentsInQuestion = (cache, questionComments, questionId, parentId) => {
114
+ const questionData = cache.readQuery({
115
+ variables: { id: questionId },
116
+ query: restricted_1.QUESTION,
117
+ });
118
+ if (questionData) {
119
+ const { question } = questionData.restricted || {};
120
+ const { comments = [], ...questionRest } = question;
121
+ cache.writeQuery({
122
+ query: restricted_1.QUESTION,
123
+ variables: { id: questionId },
124
+ data: {
125
+ ...questionData,
126
+ restricted: {
127
+ ...questionData.restricted,
128
+ question: {
129
+ ...questionRest,
130
+ comments: (0, exports.updatedCommentsOnAdd)(questionComments, comments, parentId),
131
+ },
132
+ },
133
+ },
134
+ });
135
+ }
136
+ };
137
+ exports.updatedCommentsInQuestion = updatedCommentsInQuestion;
138
+ const updatedRemoveCommentsInMarksheetQuestion = (cache, marksheetId, questionId, commentId, parentId) => {
139
+ const marksheetData = cache.readQuery({
140
+ variables: { id: marksheetId },
141
+ query: restricted_1.MARKSHEET,
142
+ });
143
+ if (marksheetData) {
144
+ const { marksheet } = marksheetData.restricted || {};
145
+ const { marks, ...marksheetRest } = marksheet;
146
+ const index = marks.findIndex(({ question }) => Number(question.id) === Number(questionId));
147
+ const { question, ...markRest } = marks[index];
148
+ const { comments = [], ...questionRest } = question;
149
+ cache.writeQuery({
150
+ query: restricted_1.MARKSHEET,
151
+ variables: { id: marksheetId },
152
+ data: {
153
+ ...marksheetData,
154
+ restricted: {
155
+ ...marksheetData.restricted,
156
+ marksheet: {
157
+ ...marksheetRest,
158
+ marks: [
159
+ ...marks.slice(0, index),
160
+ {
161
+ ...markRest,
162
+ question: {
163
+ ...questionRest,
164
+ comments: (0, exports.updateCommentsOnRemove)(comments, commentId, parentId),
165
+ },
166
+ },
167
+ ...marks.slice(index + 1),
168
+ ],
169
+ },
170
+ },
171
+ },
172
+ });
173
+ }
174
+ };
175
+ exports.updatedRemoveCommentsInMarksheetQuestion = updatedRemoveCommentsInMarksheetQuestion;
176
+ const updatedRemoveCommentsInQuestion = (cache, questionId, commentId, parentId) => {
177
+ const questionData = cache.readQuery({
178
+ variables: { id: questionId },
179
+ query: restricted_1.QUESTION,
180
+ });
181
+ if (questionData) {
182
+ const { question } = questionData.restricted || {};
183
+ const { comments = [], ...questionRest } = question;
184
+ cache.writeQuery({
185
+ query: restricted_1.QUESTION,
186
+ variables: { id: questionId },
187
+ data: {
188
+ ...questionData,
189
+ restricted: {
190
+ ...questionData.restricted,
191
+ question: {
192
+ ...questionRest,
193
+ comments: (0, exports.updateCommentsOnRemove)(comments, commentId, parentId),
194
+ },
195
+ },
196
+ },
197
+ });
198
+ }
199
+ };
200
+ exports.updatedRemoveCommentsInQuestion = updatedRemoveCommentsInQuestion;
46
201
  exports.QUESTION_LIKE = (0, client_1.gql) `
47
202
  mutation QuestionLike($questionId: Int!, $like: Int!) {
48
203
  restricted {
@@ -56,16 +211,25 @@ exports.QUESTION_LIKE = (0, client_1.gql) `
56
211
  }
57
212
  }
58
213
  `;
59
- const optimisticQuestionLike = (marksheetId, client, input) => {
214
+ const optimisticQuestionLike = (client, input, marksheetId) => {
60
215
  const { questionId, like } = input;
61
- const data = client.readQuery({
62
- variables: { id: marksheetId },
63
- query: restricted_1.MARKSHEET,
64
- });
65
- const { marksheet } = data?.restricted || {};
66
- const { marks = [] } = marksheet || {};
67
- const { question } = marks.find(({ question }) => Number(question.id) === Number(questionId)) ||
68
- {};
216
+ let question;
217
+ if (marksheetId) {
218
+ const data = client.readQuery({
219
+ variables: { id: marksheetId },
220
+ query: restricted_1.MARKSHEET,
221
+ });
222
+ const { marksheet } = data?.restricted || {};
223
+ const { marks = [] } = marksheet || {};
224
+ question = marks.find(({ question }) => Number(question.id) === Number(questionId))?.question;
225
+ }
226
+ else {
227
+ const data = client.readQuery({
228
+ variables: { id: Number(questionId) },
229
+ query: restricted_1.QUESTION,
230
+ });
231
+ question = data?.restricted.question;
232
+ }
69
233
  if (question) {
70
234
  const { typeId } = question;
71
235
  return {
@@ -131,50 +295,11 @@ const updateQuestionComments = (marksheetId) => (cache, result, options) => {
131
295
  }
132
296
  const { questionId, parentId } = variables;
133
297
  try {
134
- const prevData = cache.readQuery({
135
- variables: { id: marksheetId },
136
- query: restricted_1.MARKSHEET,
137
- });
138
- if (prevData) {
139
- const { marksheet } = prevData.restricted || {};
140
- const { marks, ...marksheetRest } = marksheet;
141
- const index = marks.findIndex(({ question }) => Number(question.id) === Number(questionId));
142
- const { question, ...markRest } = marks[index];
143
- const { comments = [], ...questionRest } = question;
144
- let newComments;
145
- if (parentId) {
146
- const commentIndex = comments.findIndex(({ id }) => Number(id) === parentId);
147
- const { replies = [], ...commentRest } = comments[commentIndex];
148
- newComments = [
149
- ...comments.slice(0, commentIndex),
150
- { ...commentRest, replies: [...replies, questionComments] },
151
- ...comments.slice(commentIndex + 1),
152
- ];
153
- }
154
- else {
155
- newComments = [...comments, questionComments];
156
- }
157
- cache.writeQuery({
158
- query: restricted_1.MARKSHEET,
159
- variables: { id: marksheetId },
160
- data: {
161
- ...prevData,
162
- restricted: {
163
- ...prevData.restricted,
164
- marksheet: {
165
- ...marksheetRest,
166
- marks: [
167
- ...marks.slice(0, index),
168
- {
169
- ...markRest,
170
- question: { ...questionRest, comments: newComments },
171
- },
172
- ...marks.slice(index + 1),
173
- ],
174
- },
175
- },
176
- },
177
- });
298
+ if (marksheetId) {
299
+ (0, exports.updatedCommentsInMarksheetQuestion)(cache, questionComments, marksheetId, questionId, parentId);
300
+ }
301
+ else {
302
+ (0, exports.updatedCommentsInQuestion)(cache, questionComments, questionId, parentId);
178
303
  }
179
304
  }
180
305
  catch (error) {
@@ -299,53 +424,11 @@ const updateQuestionCommentsRemove = (marksheetId) => (cache, result, options) =
299
424
  }
300
425
  const { questionId, id: commentId, parentId } = questionCommentRemove;
301
426
  try {
302
- const prevData = cache.readQuery({
303
- variables: { id: marksheetId },
304
- query: restricted_1.MARKSHEET,
305
- });
306
- if (prevData) {
307
- const { marksheet } = prevData.restricted || {};
308
- const { marks, ...marksheetRest } = marksheet;
309
- const index = marks.findIndex(({ question }) => Number(question.id) === Number(questionId));
310
- const { question, ...markRest } = marks[index];
311
- const { comments = [], ...questionRest } = question;
312
- let newComments;
313
- if (parentId) {
314
- const commentIndex = comments.findIndex(({ id }) => Number(id) === Number(parentId));
315
- const { replies = [], ...commentRest } = comments[commentIndex];
316
- newComments = [
317
- ...comments.slice(0, commentIndex),
318
- {
319
- ...commentRest,
320
- replies: replies.filter(({ id }) => Number(id) !== Number(commentId)),
321
- },
322
- ...comments.slice(commentIndex + 1),
323
- ];
324
- }
325
- else {
326
- newComments = comments.filter(({ id }) => Number(id) !== Number(commentId));
327
- }
328
- cache.writeQuery({
329
- query: restricted_1.MARKSHEET,
330
- variables: { id: marksheetId },
331
- data: {
332
- ...prevData,
333
- restricted: {
334
- ...prevData.restricted,
335
- marksheet: {
336
- ...marksheetRest,
337
- marks: [
338
- ...marks.slice(0, index),
339
- {
340
- ...markRest,
341
- question: { ...questionRest, comments: newComments },
342
- },
343
- ...marks.slice(index + 1),
344
- ],
345
- },
346
- },
347
- },
348
- });
427
+ if (marksheetId) {
428
+ (0, exports.updatedRemoveCommentsInMarksheetQuestion)(cache, marksheetId, questionId, commentId, parentId);
429
+ }
430
+ else {
431
+ (0, exports.updatedRemoveCommentsInQuestion)(cache, questionId, commentId, parentId);
349
432
  }
350
433
  }
351
434
  catch (error) {