@quesmed/types-rn 2.5.15 → 2.5.17

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.5.15",
3
+ "version": "2.5.17",
4
4
  "description": "Typescript types for Quesmed",
5
5
  "keywords": [
6
6
  "quesmed",
@@ -1,5 +1,7 @@
1
- import { EUserLearningStatus, Id, IUser, IUserConceptStatus, IUserStationStatus, IUserVideoStatus } from '../../../models';
2
- import { graphqlNormalize, RestrictedData } from '../../types';
1
+ import { ApolloCache } from '@apollo/client';
2
+ import { EUserLearningStatus, IUser, IUserConceptStatus, IUserStationStatus, IUserVideoStatus, Id } from '../../../models';
3
+ import { ApolloUpdateOptions, ApolloUpdateResultRestricted } from '../../apollo';
4
+ import { RestrictedData, graphqlNormalize } from '../../types';
3
5
  export declare const RESET_PROGRESS: import("@apollo/client").DocumentNode;
4
6
  export interface IResetProgressVar {
5
7
  questions?: boolean;
@@ -45,15 +47,18 @@ export type IUpsertUserConceptStatusVar = {
45
47
  };
46
48
  export type IUpsertUserConceptStatusData = RestrictedData<graphqlNormalize & IUserConceptStatus[], 'upsertUserConceptStatus'>;
47
49
  export declare const UPSERT_USER_CONCEPT_STATUS: import("@apollo/client").DocumentNode;
50
+ export declare const updateCacheOnConceptLearningStatusUpdate: (topicId: number, prevStatus?: EUserLearningStatus | null) => (cache: ApolloCache<any>, result: ApolloUpdateResultRestricted<IUpsertUserConceptStatusData>, options: ApolloUpdateOptions) => void;
48
51
  export type IUpsertUserStationStatusVar = {
49
52
  osceStationIds: Id[];
50
53
  status: EUserLearningStatus;
51
54
  };
52
55
  export type IUpsertUserStationStatusData = RestrictedData<graphqlNormalize & IUserStationStatus[], 'upsertUserStationStatus'>;
53
56
  export declare const UPSERT_USER_STATION_STATUS: import("@apollo/client").DocumentNode;
57
+ export declare const updateCacheOnStationLearningStatusUpdate: (cache: ApolloCache<any>, result: ApolloUpdateResultRestricted<IUpsertUserStationStatusData>, options: ApolloUpdateOptions) => void;
54
58
  export type IUpsertUserVideoStatusVar = {
55
59
  videoIds: Id[];
56
60
  status: EUserLearningStatus;
57
61
  };
58
62
  export type IUpsertUserVideoStatusData = RestrictedData<graphqlNormalize & IUserVideoStatus[], 'upsertUserVideoStatus'>;
59
63
  export declare const UPSERT_USER_VIDEO_STATUS: import("@apollo/client").DocumentNode;
64
+ export declare const updateCacheOnVideoLearningStatusUpdate: (prevStatus?: EUserLearningStatus | null, topicId?: number) => (cache: ApolloCache<any>, result: ApolloUpdateResultRestricted<IUpsertUserVideoStatusData>, options: ApolloUpdateOptions) => void;
@@ -1,7 +1,8 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.UPSERT_USER_VIDEO_STATUS = exports.UPSERT_USER_STATION_STATUS = exports.UPSERT_USER_CONCEPT_STATUS = exports.TOC_ACCEPT = exports.RENEW_TOKEN = exports.UPDATE_USER = exports.DELETE_USER = exports.RESET_PROGRESS = void 0;
3
+ exports.updateCacheOnVideoLearningStatusUpdate = exports.UPSERT_USER_VIDEO_STATUS = exports.updateCacheOnStationLearningStatusUpdate = exports.UPSERT_USER_STATION_STATUS = exports.updateCacheOnConceptLearningStatusUpdate = exports.UPSERT_USER_CONCEPT_STATUS = exports.TOC_ACCEPT = exports.RENEW_TOKEN = exports.UPDATE_USER = exports.DELETE_USER = exports.RESET_PROGRESS = void 0;
4
4
  const client_1 = require("@apollo/client");
5
+ const models_1 = require("../../../models");
5
6
  exports.RESET_PROGRESS = (0, client_1.gql) `
6
7
  mutation ResetProgress($questions: Boolean, $cards: Boolean) {
7
8
  restricted {
@@ -68,10 +69,88 @@ exports.UPSERT_USER_CONCEPT_STATUS = (0, client_1.gql) `
68
69
  }
69
70
  }
70
71
  `;
72
+ const STATUS_CONCEPT_FRAGMENT = (0, client_1.gql) `
73
+ fragment ConceptStatus on Concept {
74
+ status
75
+ }
76
+ `;
77
+ const TOPIC_CONCEPT_STATUS_STATS_FRAGMENT = (0, client_1.gql) `
78
+ fragment TopicConceptStatusStats on Topic {
79
+ unreadConcepts
80
+ completedConcepts
81
+ revisingConcepts
82
+ urgentConcepts
83
+ }
84
+ `;
85
+ const getConceptStatsFieldName = (status) => {
86
+ switch (status) {
87
+ case models_1.EUserLearningStatus.URGENT:
88
+ return 'urgentConcepts';
89
+ case models_1.EUserLearningStatus.REVISING:
90
+ return 'revisingConcepts';
91
+ case models_1.EUserLearningStatus.COMPLETED:
92
+ return 'completedConcepts';
93
+ case models_1.EUserLearningStatus.UNREAD:
94
+ default:
95
+ return 'unreadConcepts';
96
+ }
97
+ };
98
+ const getConceptUpdatedFieldNames = (newStatus, prevStatus) => [
99
+ getConceptStatsFieldName(prevStatus),
100
+ getConceptStatsFieldName(newStatus),
101
+ ];
102
+ const updateCacheOnConceptLearningStatusUpdate = (topicId, prevStatus) => (cache, result, options) => {
103
+ const { upsertUserConceptStatus } = result?.data?.restricted || {};
104
+ const { variables } = options || {};
105
+ if (!variables || !upsertUserConceptStatus) {
106
+ return;
107
+ }
108
+ const { conceptIds, status } = variables;
109
+ conceptIds.forEach((id) => {
110
+ cache.writeFragment({
111
+ id: cache.identify({ id, __typename: 'Concept' }),
112
+ data: {
113
+ status,
114
+ },
115
+ fragment: STATUS_CONCEPT_FRAGMENT,
116
+ });
117
+ });
118
+ const prevData = cache.readFragment({
119
+ id: cache.identify({
120
+ id: topicId,
121
+ __typename: 'Topic',
122
+ }),
123
+ fragment: TOPIC_CONCEPT_STATUS_STATS_FRAGMENT,
124
+ });
125
+ if (prevData) {
126
+ const [prevStatName, newStatName] = getConceptUpdatedFieldNames(status, prevStatus);
127
+ const newData = {
128
+ ...prevData,
129
+ [newStatName]: (prevData[newStatName] || 0) + conceptIds.length,
130
+ };
131
+ if (prevStatus !== undefined &&
132
+ prevStatus !== null &&
133
+ prevData[prevStatName]) {
134
+ newData[prevStatName] =
135
+ (prevData[prevStatName] || 0) - conceptIds.length;
136
+ }
137
+ cache.writeFragment({
138
+ id: cache.identify({ id: topicId, __typename: 'Topic' }),
139
+ data: {
140
+ ...newData,
141
+ },
142
+ fragment: TOPIC_CONCEPT_STATUS_STATS_FRAGMENT,
143
+ });
144
+ }
145
+ };
146
+ exports.updateCacheOnConceptLearningStatusUpdate = updateCacheOnConceptLearningStatusUpdate;
71
147
  exports.UPSERT_USER_STATION_STATUS = (0, client_1.gql) `
72
148
  mutation UpsertUserStationStatus($osceStationIds: [Int!]!, $status: Int!) {
73
149
  restricted {
74
- upsertUserStationStatus(osceStationIds: $osceStationIds, status: $status) {
150
+ upsertUserStationStatus(
151
+ osceStationIds: $osceStationIds
152
+ status: $status
153
+ ) {
75
154
  id
76
155
  status
77
156
  osceStationId
@@ -81,6 +160,29 @@ exports.UPSERT_USER_STATION_STATUS = (0, client_1.gql) `
81
160
  }
82
161
  }
83
162
  `;
163
+ const STATION_CONCEPT_FRAGMENT = (0, client_1.gql) `
164
+ fragment StationStatus on OsceStation {
165
+ status
166
+ }
167
+ `;
168
+ const updateCacheOnStationLearningStatusUpdate = (cache, result, options) => {
169
+ const { upsertUserStationStatus } = result?.data?.restricted || {};
170
+ const { variables } = options || {};
171
+ if (!variables || !upsertUserStationStatus) {
172
+ return;
173
+ }
174
+ const { osceStationIds, status } = variables;
175
+ osceStationIds.forEach((id) => {
176
+ cache.writeFragment({
177
+ id: cache.identify({ id, __typename: 'OsceStation' }),
178
+ data: {
179
+ status,
180
+ },
181
+ fragment: STATION_CONCEPT_FRAGMENT,
182
+ });
183
+ });
184
+ };
185
+ exports.updateCacheOnStationLearningStatusUpdate = updateCacheOnStationLearningStatusUpdate;
84
186
  exports.UPSERT_USER_VIDEO_STATUS = (0, client_1.gql) `
85
187
  mutation UpsertUserVideoStatus($videoIds: [Int!]!, $status: Int!) {
86
188
  restricted {
@@ -94,3 +196,80 @@ exports.UPSERT_USER_VIDEO_STATUS = (0, client_1.gql) `
94
196
  }
95
197
  }
96
198
  `;
199
+ const VIDEO_STATUS_FRAGMENT = (0, client_1.gql) `
200
+ fragment VideoStatus on Video {
201
+ status
202
+ }
203
+ `;
204
+ const TOPIC_VIDEO_STATUS_STATS_FRAGMENT = (0, client_1.gql) `
205
+ fragment TopicVideoStatusStats on Topic {
206
+ unwatchedVideos
207
+ completedVideos
208
+ revisingVideos
209
+ urgentVideos
210
+ }
211
+ `;
212
+ const getVideoStatsFieldName = (status) => {
213
+ switch (status) {
214
+ case models_1.EUserLearningStatus.URGENT:
215
+ return 'urgentVideos';
216
+ case models_1.EUserLearningStatus.REVISING:
217
+ return 'revisingVideos';
218
+ case models_1.EUserLearningStatus.COMPLETED:
219
+ return 'completedVideos';
220
+ case models_1.EUserLearningStatus.UNREAD:
221
+ default:
222
+ return 'unwatchedVideos';
223
+ }
224
+ };
225
+ const getVideoUpdatedFieldNames = (newStatus, prevStatus) => [
226
+ getVideoStatsFieldName(prevStatus),
227
+ getVideoStatsFieldName(newStatus),
228
+ ];
229
+ const updateCacheOnVideoLearningStatusUpdate = (prevStatus, topicId) => (cache, result, options) => {
230
+ const { upsertUserVideoStatus } = result?.data?.restricted || {};
231
+ const { variables } = options || {};
232
+ if (!variables || !upsertUserVideoStatus) {
233
+ return;
234
+ }
235
+ const { videoIds, status } = variables;
236
+ videoIds.forEach((id) => {
237
+ cache.writeFragment({
238
+ id: cache.identify({ id, __typename: 'Video' }),
239
+ data: {
240
+ status,
241
+ },
242
+ fragment: VIDEO_STATUS_FRAGMENT,
243
+ });
244
+ });
245
+ if (!topicId) {
246
+ return;
247
+ }
248
+ const prevData = cache.readFragment({
249
+ id: cache.identify({
250
+ id: topicId,
251
+ __typename: 'Topic',
252
+ }),
253
+ fragment: TOPIC_VIDEO_STATUS_STATS_FRAGMENT,
254
+ });
255
+ if (prevData) {
256
+ const [prevStatName, newStatName] = getVideoUpdatedFieldNames(status, prevStatus);
257
+ const newData = {
258
+ ...prevData,
259
+ [newStatName]: (prevData[newStatName] || 0) + videoIds.length,
260
+ };
261
+ if (prevStatus !== undefined &&
262
+ prevStatus !== null &&
263
+ prevData[prevStatName]) {
264
+ newData[prevStatName] = (prevData[prevStatName] || 0) - videoIds.length;
265
+ }
266
+ cache.writeFragment({
267
+ id: cache.identify({ id: topicId, __typename: 'Topic' }),
268
+ data: {
269
+ ...newData,
270
+ },
271
+ fragment: TOPIC_VIDEO_STATUS_STATS_FRAGMENT,
272
+ });
273
+ }
274
+ };
275
+ exports.updateCacheOnVideoLearningStatusUpdate = updateCacheOnVideoLearningStatusUpdate;
@@ -724,7 +724,6 @@ exports.FLAGGED_QUESTIONS = (0, client_1.gql) `
724
724
  concept {
725
725
  id
726
726
  name
727
- status
728
727
  topic {
729
728
  name
730
729
  typeId