@quesmed/types-rn 2.2.96 → 2.2.98

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.96",
3
+ "version": "2.2.98",
4
4
  "description": "Typescript types for Quesmed",
5
5
  "keywords": [
6
6
  "quesmed",
@@ -24,7 +24,9 @@ export interface ISaveTodosVar {
24
24
  todos: ITodoInput[];
25
25
  }
26
26
  export declare type ISaveTodosData = RestrictedData<(graphqlNormalize & ITodo)[], 'saveTodos'>;
27
+ export declare const optimisticUpdatedSaveTodo: (todo: ITodo, cardIndex: number, todoInput: ITodoInput) => ISaveTodosData;
27
28
  export declare function saveTodosCache(cache: ApolloCache<any>, result: ApolloUpdateResultRestricted<ISaveTodosData>, options: ApolloUpdateOptions): void;
29
+ export declare const optimisticSaveTodos: (todo: ITodo, cardIndex: number, todoInput: ITodoInput) => ISaveTodosData;
28
30
  export declare const ADD_TO_DAILY_STACK: import("@apollo/client").DocumentNode;
29
31
  export interface IAddToDailyStackVar {
30
32
  conceptIds: Id[];
@@ -37,8 +39,8 @@ export interface IRemoveFromDailyStackVar {
37
39
  conceptId?: Id;
38
40
  }
39
41
  export declare type IRemoveFromDailyStackData = RestrictedData<(graphqlNormalize & IUserCompletedCard)[], 'removeFromDailyStack'>;
40
- export declare const updateCacheRemoveFromDailyStack: (userId?: number | undefined) => (cache: ApolloCache<any>, result: ApolloUpdateResultRestricted<IRemoveFromDailyStackData>) => void;
41
- export declare const updateCacheAddToDailyStack: (userId?: number | undefined) => (cache: ApolloCache<any>, result: ApolloUpdateResultRestricted<IAddToDailyStackData>) => void;
42
+ export declare const updateCacheOnRemoveFromDailyStack: (cache: ApolloCache<any>, result: ApolloUpdateResultRestricted<IRemoveFromDailyStackData>, options: ApolloUpdateOptions) => void;
43
+ export declare const updateCacheOnAddToDailyStack: (cache: ApolloCache<any>, result: ApolloUpdateResultRestricted<IAddToDailyStackData>) => void;
42
44
  export declare const REFRESH_DAILY_TASK: import("@apollo/client").DocumentNode;
43
45
  export declare type IRefreshDailyTaskVar = null;
44
46
  export declare type IRefreshDailyTaskData = RestrictedData<graphqlNormalize & ITodo, 'refreshDailyTask'>;
@@ -1,8 +1,9 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.REFRESH_DAILY_TASK = exports.updateCacheAddToDailyStack = exports.updateCacheRemoveFromDailyStack = exports.REMOVE_FROM_DAILY_STACK = exports.ADD_TO_DAILY_STACK = exports.saveTodosCache = exports.SAVE_TODO = exports.BUILD_TODO = void 0;
3
+ exports.REFRESH_DAILY_TASK = exports.updateCacheOnAddToDailyStack = exports.updateCacheOnRemoveFromDailyStack = exports.REMOVE_FROM_DAILY_STACK = exports.ADD_TO_DAILY_STACK = exports.optimisticSaveTodos = exports.saveTodosCache = exports.optimisticUpdatedSaveTodo = exports.SAVE_TODO = exports.BUILD_TODO = void 0;
4
4
  const client_1 = require("@apollo/client");
5
5
  const fragments_1 = require("../../fragments");
6
+ const restricted_1 = require("../../query/restricted");
6
7
  exports.BUILD_TODO = (0, client_1.gql) `
7
8
  mutation BuildTodo($buildTodo: BuildTodoInput!) {
8
9
  restricted {
@@ -54,6 +55,23 @@ exports.SAVE_TODO = (0, client_1.gql) `
54
55
  }
55
56
  }
56
57
  `;
58
+ const optimisticUpdatedSaveTodo = (todo, cardIndex, todoInput) => {
59
+ const { score, timeTaken } = todoInput;
60
+ const { marks } = todo;
61
+ const newMarks = [...marks];
62
+ newMarks[cardIndex] = { ...marks[cardIndex], score, timeTaken };
63
+ return {
64
+ restricted: {
65
+ saveTodos: [
66
+ {
67
+ ...todo,
68
+ marks: newMarks,
69
+ },
70
+ ],
71
+ },
72
+ };
73
+ };
74
+ exports.optimisticUpdatedSaveTodo = optimisticUpdatedSaveTodo;
57
75
  function saveTodosCache(cache, result, options) {
58
76
  const { saveTodos } = result?.data?.restricted || {};
59
77
  if (!options.variables || !saveTodos) {
@@ -78,6 +96,23 @@ function saveTodosCache(cache, result, options) {
78
96
  }
79
97
  }
80
98
  exports.saveTodosCache = saveTodosCache;
99
+ const optimisticSaveTodos = (todo, cardIndex, todoInput) => {
100
+ const { score, timeTaken } = todoInput;
101
+ const { marks } = todo;
102
+ const newMarks = [...marks];
103
+ newMarks[cardIndex] = { ...marks[cardIndex], score, timeTaken };
104
+ return {
105
+ restricted: {
106
+ saveTodos: [
107
+ {
108
+ ...todo,
109
+ marks: newMarks,
110
+ },
111
+ ],
112
+ },
113
+ };
114
+ };
115
+ exports.optimisticSaveTodos = optimisticSaveTodos;
81
116
  exports.ADD_TO_DAILY_STACK = (0, client_1.gql) `
82
117
  ${fragments_1.PICTURE_FIELDS}
83
118
  mutation AddToDailyStack($conceptIds: [Int!]!) {
@@ -135,49 +170,85 @@ exports.REMOVE_FROM_DAILY_STACK = (0, client_1.gql) `
135
170
  }
136
171
  }
137
172
  `;
138
- const updateCacheRemoveFromDailyStack = (userId) => (cache, result) => {
173
+ const updateCacheOnRemoveFromDailyStack = (cache, result, options) => {
139
174
  const { removeFromDailyStack } = result.data?.restricted || {};
140
- const prevData = cache.readFragment({
141
- id: cache.identify({ id: userId, __typename: 'User' }),
142
- fragment: fragments_1.COMPLETED_CARDS,
175
+ const { variables } = options || {};
176
+ const { todoId } = variables || {};
177
+ if (!removeFromDailyStack || !removeFromDailyStack.length) {
178
+ return;
179
+ }
180
+ const toRemove = new Set(removeFromDailyStack.map(({ cardId }) => cardId));
181
+ const prevData = cache.readQuery({
182
+ query: restricted_1.USER_COMPLETED_DATA,
143
183
  });
144
- if (prevData && removeFromDailyStack && removeFromDailyStack.length) {
145
- const toRemove = new Set(removeFromDailyStack.map(({ id }) => id));
146
- if (toRemove.size === 0 || !userId) {
147
- return;
148
- }
149
- const newCompletedCards = prevData.completedCards.filter(({ id }) => !toRemove.has(id));
150
- cache.writeFragment({
151
- id: cache.identify({ id: userId, __typename: 'User' }),
184
+ if (prevData) {
185
+ const newCompletedCards = prevData.restricted.user.completedCards.filter(({ cardId }) => !toRemove.has(cardId));
186
+ cache.writeQuery({
187
+ query: restricted_1.USER_COMPLETED_DATA,
152
188
  data: {
153
- completedCardsCount: newCompletedCards.length,
154
- completedCards: newCompletedCards,
189
+ ...prevData,
190
+ restricted: {
191
+ ...prevData.restricted,
192
+ user: {
193
+ ...prevData.restricted.user,
194
+ completedCards: newCompletedCards,
195
+ completedCardsCount: newCompletedCards.length,
196
+ },
197
+ },
155
198
  },
156
- fragment: fragments_1.COMPLETED_CARDS,
157
199
  });
158
200
  }
201
+ if (todoId) {
202
+ const prevData = cache.readQuery({
203
+ variables: { id: todoId },
204
+ query: restricted_1.TODO,
205
+ });
206
+ if (prevData) {
207
+ const { marks } = prevData.restricted.todo;
208
+ cache.writeQuery({
209
+ query: restricted_1.TODO,
210
+ data: {
211
+ ...prevData,
212
+ restricted: {
213
+ ...prevData.restricted,
214
+ todo: {
215
+ ...prevData.restricted.todo,
216
+ marks: marks.filter(({ cardId }) => !toRemove.has(Number(cardId))),
217
+ },
218
+ },
219
+ },
220
+ });
221
+ }
222
+ }
159
223
  };
160
- exports.updateCacheRemoveFromDailyStack = updateCacheRemoveFromDailyStack;
161
- const updateCacheAddToDailyStack = (userId) => (cache, result) => {
224
+ exports.updateCacheOnRemoveFromDailyStack = updateCacheOnRemoveFromDailyStack;
225
+ const updateCacheOnAddToDailyStack = (cache, result) => {
162
226
  const { addToDailyStack } = result.data?.restricted || {};
163
- const prevData = cache.readFragment({
164
- id: cache.identify({ id: userId, __typename: 'User' }),
165
- fragment: fragments_1.COMPLETED_CARDS,
227
+ const prevData = cache.readQuery({
228
+ query: restricted_1.USER_COMPLETED_DATA,
166
229
  });
167
- const { completedCards = [] } = prevData || {};
168
- if (addToDailyStack) {
169
- const newCompletedCards = [...completedCards, ...addToDailyStack];
170
- cache.writeFragment({
171
- id: cache.identify({ id: userId, __typename: 'User' }),
230
+ if (prevData && addToDailyStack) {
231
+ const newCompletedCards = [
232
+ ...prevData.restricted.user.completedCards,
233
+ ...addToDailyStack,
234
+ ];
235
+ cache.writeQuery({
236
+ query: restricted_1.USER_COMPLETED_DATA,
172
237
  data: {
173
- completedCardsCount: newCompletedCards.length,
174
- completedCards: newCompletedCards,
238
+ ...prevData,
239
+ restricted: {
240
+ ...prevData.restricted,
241
+ user: {
242
+ ...prevData.restricted.user,
243
+ completedCards: newCompletedCards,
244
+ completedCardsCount: newCompletedCards.length,
245
+ },
246
+ },
175
247
  },
176
- fragment: fragments_1.COMPLETED_CARDS,
177
248
  });
178
249
  }
179
250
  };
180
- exports.updateCacheAddToDailyStack = updateCacheAddToDailyStack;
251
+ exports.updateCacheOnAddToDailyStack = updateCacheOnAddToDailyStack;
181
252
  exports.REFRESH_DAILY_TASK = (0, client_1.gql) `
182
253
  ${fragments_1.PICTURE_FIELDS}
183
254
  mutation RefreshDailyTask {
@@ -1,3 +1,4 @@
1
1
  import { ApolloClient } from '@apollo/client';
2
- import { IMarksheetInput } from './restricted';
2
+ import { IMarksheetInput, ITodoInput } from './restricted';
3
3
  export declare const saveSampleMarksheets: (client: ApolloClient<any>, marksheetInput: IMarksheetInput, questionIndex: number) => void;
4
+ export declare const saveSampleTodoMark: (client: ApolloClient<any>, todoInput: ITodoInput, markId: number) => void;
@@ -1,6 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.saveSampleMarksheets = void 0;
3
+ exports.saveSampleTodoMark = exports.saveSampleMarksheets = void 0;
4
+ const client_1 = require("@apollo/client");
4
5
  const query_1 = require("../query");
5
6
  const saveSampleMarksheets = (client, marksheetInput, questionIndex) => {
6
7
  const { timeTaken, choiceId, mark, marksheetId } = marksheetInput;
@@ -35,3 +36,20 @@ const saveSampleMarksheets = (client, marksheetInput, questionIndex) => {
35
36
  }
36
37
  };
37
38
  exports.saveSampleMarksheets = saveSampleMarksheets;
39
+ const saveSampleTodoMark = (client, todoInput, markId) => {
40
+ const { timeTaken, score } = todoInput;
41
+ client.writeFragment({
42
+ id: `TodoMark:${markId}`,
43
+ data: {
44
+ score,
45
+ timeTaken: timeTaken,
46
+ },
47
+ fragment: (0, client_1.gql) `
48
+ fragment UpdatedTodoMark on TodoMark {
49
+ score
50
+ timeTaken
51
+ }
52
+ `,
53
+ });
54
+ };
55
+ exports.saveSampleTodoMark = saveSampleTodoMark;