@magmamath/students-features 0.6.7-rc.1 → 0.6.7-rc.2
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/dist/commonjs/features/endOfAssignment/components/Modal/Modal.js +1 -0
- package/dist/commonjs/features/endOfAssignment/components/Modal/Modal.js.map +1 -1
- package/dist/commonjs/index.js +0 -12
- package/dist/commonjs/index.js.map +1 -1
- package/dist/commonjs/lib/effector/createControllerEffect.js.map +1 -1
- package/dist/commonjs/lib/helpers/helpers.js.map +1 -1
- package/dist/commonjs/shared/translation/localization/en.json +0 -5
- package/dist/commonjs/shared/translation/localization/gb.json +0 -5
- package/dist/commonjs/shared/translation/localization/sw.json +0 -5
- package/dist/module/features/endOfAssignment/components/Modal/Modal.js +2 -1
- package/dist/module/features/endOfAssignment/components/Modal/Modal.js.map +1 -1
- package/dist/module/index.js +0 -1
- package/dist/module/index.js.map +1 -1
- package/dist/module/lib/effector/createControllerEffect.js.map +1 -1
- package/dist/module/shared/translation/localization/en.json +0 -5
- package/dist/module/shared/translation/localization/gb.json +0 -5
- package/dist/module/shared/translation/localization/sw.json +0 -5
- package/dist/typescript/commonjs/features/endOfAssignment/components/Modal/Modal.d.ts.map +1 -1
- package/dist/typescript/commonjs/index.d.ts +0 -1
- package/dist/typescript/commonjs/index.d.ts.map +1 -1
- package/dist/typescript/commonjs/lib/effector/createControllerEffect.d.ts +1 -1
- package/dist/typescript/commonjs/lib/effector/createControllerEffect.d.ts.map +1 -1
- package/dist/typescript/commonjs/lib/helpers/helpers.d.ts.map +1 -1
- package/dist/typescript/commonjs/shared/translation/constants.d.ts +0 -15
- package/dist/typescript/commonjs/shared/translation/constants.d.ts.map +1 -1
- package/dist/typescript/commonjs/shared/translation/model.d.ts +0 -10
- package/dist/typescript/commonjs/shared/translation/model.d.ts.map +1 -1
- package/dist/typescript/module/features/endOfAssignment/components/Modal/Modal.d.ts.map +1 -1
- package/dist/typescript/module/index.d.ts +0 -1
- package/dist/typescript/module/index.d.ts.map +1 -1
- package/dist/typescript/module/lib/effector/createControllerEffect.d.ts +1 -1
- package/dist/typescript/module/lib/effector/createControllerEffect.d.ts.map +1 -1
- package/dist/typescript/module/lib/helpers/helpers.d.ts.map +1 -1
- package/dist/typescript/module/shared/translation/constants.d.ts +0 -15
- package/dist/typescript/module/shared/translation/constants.d.ts.map +1 -1
- package/dist/typescript/module/shared/translation/model.d.ts +0 -10
- package/dist/typescript/module/shared/translation/model.d.ts.map +1 -1
- package/package.json +5 -3
- package/src/features/endOfAssignment/components/Modal/Modal.tsx +2 -1
- package/src/index.ts +0 -1
- package/src/lib/effector/createControllerEffect.ts +41 -41
- package/src/lib/helpers/helpers.ts +1 -1
- package/src/shared/translation/localization/en.json +0 -5
- package/src/shared/translation/localization/gb.json +0 -5
- package/src/shared/translation/localization/sw.json +0 -5
- package/dist/commonjs/features/gifCelebrations/GifCelebrations.js +0 -62
- package/dist/commonjs/features/gifCelebrations/GifCelebrations.js.map +0 -1
- package/dist/commonjs/features/gifCelebrations/assets/confetti.webp +0 -0
- package/dist/commonjs/features/gifCelebrations/assets/gifFallback.gif +0 -0
- package/dist/commonjs/features/gifCelebrations/components/Backdrop.js +0 -44
- package/dist/commonjs/features/gifCelebrations/components/Backdrop.js.map +0 -1
- package/dist/commonjs/features/gifCelebrations/components/ContentContainer.js +0 -46
- package/dist/commonjs/features/gifCelebrations/components/ContentContainer.js.map +0 -1
- package/dist/commonjs/features/gifCelebrations/components/Gif.js +0 -91
- package/dist/commonjs/features/gifCelebrations/components/Gif.js.map +0 -1
- package/dist/commonjs/features/gifCelebrations/components/Progress.js +0 -96
- package/dist/commonjs/features/gifCelebrations/components/Progress.js.map +0 -1
- package/dist/commonjs/features/gifCelebrations/constants.js +0 -34
- package/dist/commonjs/features/gifCelebrations/constants.js.map +0 -1
- package/dist/commonjs/features/gifCelebrations/helpers.js +0 -114
- package/dist/commonjs/features/gifCelebrations/helpers.js.map +0 -1
- package/dist/commonjs/features/gifCelebrations/index.js +0 -20
- package/dist/commonjs/features/gifCelebrations/index.js.map +0 -1
- package/dist/commonjs/features/gifCelebrations/model/GifCelebrations.cache.js +0 -38
- package/dist/commonjs/features/gifCelebrations/model/GifCelebrations.cache.js.map +0 -1
- package/dist/commonjs/features/gifCelebrations/model/GifCelebrations.model.js +0 -150
- package/dist/commonjs/features/gifCelebrations/model/GifCelebrations.model.js.map +0 -1
- package/dist/commonjs/features/gifCelebrations/model/GifCelebrationsApi.js +0 -14
- package/dist/commonjs/features/gifCelebrations/model/GifCelebrationsApi.js.map +0 -1
- package/dist/commonjs/features/gifCelebrations/types/model.types.js +0 -6
- package/dist/commonjs/features/gifCelebrations/types/model.types.js.map +0 -1
- package/dist/commonjs/react-app-env.d.js +0 -2
- package/dist/commonjs/react-app-env.d.js.map +0 -1
- package/dist/commonjs/shared/constants.js +0 -9
- package/dist/commonjs/shared/constants.js.map +0 -1
- package/dist/commonjs/types/common.types.js +0 -2
- package/dist/commonjs/types/common.types.js.map +0 -1
- package/dist/module/features/gifCelebrations/GifCelebrations.js +0 -55
- package/dist/module/features/gifCelebrations/GifCelebrations.js.map +0 -1
- package/dist/module/features/gifCelebrations/assets/confetti.webp +0 -0
- package/dist/module/features/gifCelebrations/assets/gifFallback.gif +0 -0
- package/dist/module/features/gifCelebrations/components/Backdrop.js +0 -36
- package/dist/module/features/gifCelebrations/components/Backdrop.js.map +0 -1
- package/dist/module/features/gifCelebrations/components/ContentContainer.js +0 -38
- package/dist/module/features/gifCelebrations/components/ContentContainer.js.map +0 -1
- package/dist/module/features/gifCelebrations/components/Gif.js +0 -83
- package/dist/module/features/gifCelebrations/components/Gif.js.map +0 -1
- package/dist/module/features/gifCelebrations/components/Progress.js +0 -88
- package/dist/module/features/gifCelebrations/components/Progress.js.map +0 -1
- package/dist/module/features/gifCelebrations/constants.js +0 -30
- package/dist/module/features/gifCelebrations/constants.js.map +0 -1
- package/dist/module/features/gifCelebrations/helpers.js +0 -103
- package/dist/module/features/gifCelebrations/helpers.js.map +0 -1
- package/dist/module/features/gifCelebrations/index.js +0 -5
- package/dist/module/features/gifCelebrations/index.js.map +0 -1
- package/dist/module/features/gifCelebrations/model/GifCelebrations.cache.js +0 -33
- package/dist/module/features/gifCelebrations/model/GifCelebrations.cache.js.map +0 -1
- package/dist/module/features/gifCelebrations/model/GifCelebrations.model.js +0 -145
- package/dist/module/features/gifCelebrations/model/GifCelebrations.model.js.map +0 -1
- package/dist/module/features/gifCelebrations/model/GifCelebrationsApi.js +0 -9
- package/dist/module/features/gifCelebrations/model/GifCelebrationsApi.js.map +0 -1
- package/dist/module/features/gifCelebrations/types/model.types.js +0 -4
- package/dist/module/features/gifCelebrations/types/model.types.js.map +0 -1
- package/dist/module/react-app-env.d.js +0 -2
- package/dist/module/react-app-env.d.js.map +0 -1
- package/dist/module/shared/constants.js +0 -5
- package/dist/module/shared/constants.js.map +0 -1
- package/dist/module/types/common.types.js +0 -2
- package/dist/module/types/common.types.js.map +0 -1
- package/dist/typescript/commonjs/features/gifCelebrations/GifCelebrations.d.ts +0 -10
- package/dist/typescript/commonjs/features/gifCelebrations/GifCelebrations.d.ts.map +0 -1
- package/dist/typescript/commonjs/features/gifCelebrations/components/Backdrop.d.ts +0 -10
- package/dist/typescript/commonjs/features/gifCelebrations/components/Backdrop.d.ts.map +0 -1
- package/dist/typescript/commonjs/features/gifCelebrations/components/ContentContainer.d.ts +0 -10
- package/dist/typescript/commonjs/features/gifCelebrations/components/ContentContainer.d.ts.map +0 -1
- package/dist/typescript/commonjs/features/gifCelebrations/components/Gif.d.ts +0 -10
- package/dist/typescript/commonjs/features/gifCelebrations/components/Gif.d.ts.map +0 -1
- package/dist/typescript/commonjs/features/gifCelebrations/components/Progress.d.ts +0 -10
- package/dist/typescript/commonjs/features/gifCelebrations/components/Progress.d.ts.map +0 -1
- package/dist/typescript/commonjs/features/gifCelebrations/constants.d.ts +0 -26
- package/dist/typescript/commonjs/features/gifCelebrations/constants.d.ts.map +0 -1
- package/dist/typescript/commonjs/features/gifCelebrations/helpers.d.ts +0 -29
- package/dist/typescript/commonjs/features/gifCelebrations/helpers.d.ts.map +0 -1
- package/dist/typescript/commonjs/features/gifCelebrations/index.d.ts +0 -3
- package/dist/typescript/commonjs/features/gifCelebrations/index.d.ts.map +0 -1
- package/dist/typescript/commonjs/features/gifCelebrations/model/GifCelebrations.cache.d.ts +0 -19
- package/dist/typescript/commonjs/features/gifCelebrations/model/GifCelebrations.cache.d.ts.map +0 -1
- package/dist/typescript/commonjs/features/gifCelebrations/model/GifCelebrations.model.d.ts +0 -26
- package/dist/typescript/commonjs/features/gifCelebrations/model/GifCelebrations.model.d.ts.map +0 -1
- package/dist/typescript/commonjs/features/gifCelebrations/model/GifCelebrationsApi.d.ts +0 -6
- package/dist/typescript/commonjs/features/gifCelebrations/model/GifCelebrationsApi.d.ts.map +0 -1
- package/dist/typescript/commonjs/features/gifCelebrations/types/model.types.d.ts +0 -45
- package/dist/typescript/commonjs/features/gifCelebrations/types/model.types.d.ts.map +0 -1
- package/dist/typescript/commonjs/shared/constants.d.ts +0 -2
- package/dist/typescript/commonjs/shared/constants.d.ts.map +0 -1
- package/dist/typescript/commonjs/types/common.types.d.ts +0 -5
- package/dist/typescript/commonjs/types/common.types.d.ts.map +0 -1
- package/dist/typescript/module/features/gifCelebrations/GifCelebrations.d.ts +0 -10
- package/dist/typescript/module/features/gifCelebrations/GifCelebrations.d.ts.map +0 -1
- package/dist/typescript/module/features/gifCelebrations/components/Backdrop.d.ts +0 -10
- package/dist/typescript/module/features/gifCelebrations/components/Backdrop.d.ts.map +0 -1
- package/dist/typescript/module/features/gifCelebrations/components/ContentContainer.d.ts +0 -10
- package/dist/typescript/module/features/gifCelebrations/components/ContentContainer.d.ts.map +0 -1
- package/dist/typescript/module/features/gifCelebrations/components/Gif.d.ts +0 -10
- package/dist/typescript/module/features/gifCelebrations/components/Gif.d.ts.map +0 -1
- package/dist/typescript/module/features/gifCelebrations/components/Progress.d.ts +0 -10
- package/dist/typescript/module/features/gifCelebrations/components/Progress.d.ts.map +0 -1
- package/dist/typescript/module/features/gifCelebrations/constants.d.ts +0 -26
- package/dist/typescript/module/features/gifCelebrations/constants.d.ts.map +0 -1
- package/dist/typescript/module/features/gifCelebrations/helpers.d.ts +0 -29
- package/dist/typescript/module/features/gifCelebrations/helpers.d.ts.map +0 -1
- package/dist/typescript/module/features/gifCelebrations/index.d.ts +0 -3
- package/dist/typescript/module/features/gifCelebrations/index.d.ts.map +0 -1
- package/dist/typescript/module/features/gifCelebrations/model/GifCelebrations.cache.d.ts +0 -19
- package/dist/typescript/module/features/gifCelebrations/model/GifCelebrations.cache.d.ts.map +0 -1
- package/dist/typescript/module/features/gifCelebrations/model/GifCelebrations.model.d.ts +0 -26
- package/dist/typescript/module/features/gifCelebrations/model/GifCelebrations.model.d.ts.map +0 -1
- package/dist/typescript/module/features/gifCelebrations/model/GifCelebrationsApi.d.ts +0 -6
- package/dist/typescript/module/features/gifCelebrations/model/GifCelebrationsApi.d.ts.map +0 -1
- package/dist/typescript/module/features/gifCelebrations/types/model.types.d.ts +0 -45
- package/dist/typescript/module/features/gifCelebrations/types/model.types.d.ts.map +0 -1
- package/dist/typescript/module/shared/constants.d.ts +0 -2
- package/dist/typescript/module/shared/constants.d.ts.map +0 -1
- package/dist/typescript/module/types/common.types.d.ts +0 -5
- package/dist/typescript/module/types/common.types.d.ts.map +0 -1
- package/src/features/gifCelebrations/GifCelebrations.tsx +0 -75
- package/src/features/gifCelebrations/assets/confetti.webp +0 -0
- package/src/features/gifCelebrations/assets/gifFallback.gif +0 -0
- package/src/features/gifCelebrations/components/Backdrop.tsx +0 -41
- package/src/features/gifCelebrations/components/ContentContainer.tsx +0 -44
- package/src/features/gifCelebrations/components/Gif.tsx +0 -89
- package/src/features/gifCelebrations/components/Progress.tsx +0 -106
- package/src/features/gifCelebrations/constants.ts +0 -32
- package/src/features/gifCelebrations/helpers.ts +0 -144
- package/src/features/gifCelebrations/index.ts +0 -2
- package/src/features/gifCelebrations/model/GifCelebrations.cache.ts +0 -51
- package/src/features/gifCelebrations/model/GifCelebrations.model.ts +0 -192
- package/src/features/gifCelebrations/model/GifCelebrationsApi.ts +0 -10
- package/src/features/gifCelebrations/types/model.types.ts +0 -53
- package/src/react-app-env.d.ts +0 -6
- package/src/shared/constants.ts +0 -3
- package/src/types/common.types.ts +0 -4
|
@@ -1,192 +0,0 @@
|
|
|
1
|
-
import { createEffect, createEvent, createStore, sample, Store } from 'effector'
|
|
2
|
-
import { GifCelebrationsApi } from './GifCelebrationsApi'
|
|
3
|
-
import {
|
|
4
|
-
CustomLocalStorage,
|
|
5
|
-
GifCelebrationsModelProps,
|
|
6
|
-
GifObject,
|
|
7
|
-
GifsStructure,
|
|
8
|
-
ProblemsGifsTable,
|
|
9
|
-
} from '../types/model.types'
|
|
10
|
-
import { GifCelebrationsCache } from './GifCelebrations.cache'
|
|
11
|
-
import { generateProblemsGifsTable, shouldRefreshGifs } from '../helpers'
|
|
12
|
-
import { GET_GIFS_TIMEOUT, MIN_PROBLEMS_TO_SHOW_GIF, GIFS_FETCHED_KEY } from '../constants'
|
|
13
|
-
|
|
14
|
-
type HandleGifSelectionProps = {
|
|
15
|
-
gifsGroups: GifsStructure
|
|
16
|
-
resolvedProblemsAmount: number
|
|
17
|
-
problemsGifsTable: ProblemsGifsTable
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
export class GifCelebrationsModel {
|
|
21
|
-
public readonly api: GifCelebrationsApi
|
|
22
|
-
public readonly cache: GifCelebrationsCache
|
|
23
|
-
|
|
24
|
-
public readonly $problemsAmount: Store<number>
|
|
25
|
-
public readonly $resolvedProblemsAmount: Store<number>
|
|
26
|
-
|
|
27
|
-
public readonly play = createEvent()
|
|
28
|
-
public readonly stop = createEvent()
|
|
29
|
-
|
|
30
|
-
public readonly resetGifTriggerable = createEvent()
|
|
31
|
-
public readonly setGifTriggerable = createEvent<boolean>()
|
|
32
|
-
public readonly $isGifTriggerable = createStore<boolean>(false)
|
|
33
|
-
.reset(this.resetGifTriggerable)
|
|
34
|
-
.reset(this.stop)
|
|
35
|
-
.on(
|
|
36
|
-
this.setGifTriggerable,
|
|
37
|
-
(_, isGifCelebrationMayBeTriggered) => isGifCelebrationMayBeTriggered,
|
|
38
|
-
)
|
|
39
|
-
|
|
40
|
-
public readonly resetProblemsGifsTable = createEvent()
|
|
41
|
-
public readonly $problemsGifsTable = createStore<ProblemsGifsTable | null>(null).reset(
|
|
42
|
-
this.resetProblemsGifsTable,
|
|
43
|
-
)
|
|
44
|
-
|
|
45
|
-
public readonly setActiveGif = createEvent<GifObject>()
|
|
46
|
-
public readonly $activeGif = createStore<GifObject | null>(null)
|
|
47
|
-
.reset(this.stop)
|
|
48
|
-
.reset(this.resetGifTriggerable)
|
|
49
|
-
.on(this.setActiveGif, (_, gif) => gif)
|
|
50
|
-
|
|
51
|
-
private readonly localStorage: typeof localStorage | CustomLocalStorage
|
|
52
|
-
|
|
53
|
-
public readonly initialize = createEvent()
|
|
54
|
-
|
|
55
|
-
constructor({
|
|
56
|
-
api,
|
|
57
|
-
problemsAmount,
|
|
58
|
-
resolvedProblemsAmount,
|
|
59
|
-
customLocalStorage,
|
|
60
|
-
customGetCachePathMethod,
|
|
61
|
-
customPrefetchMethod,
|
|
62
|
-
}: GifCelebrationsModelProps) {
|
|
63
|
-
this.api = new GifCelebrationsApi(api)
|
|
64
|
-
this.cache = new GifCelebrationsCache({ customGetCachePathMethod, customPrefetchMethod })
|
|
65
|
-
|
|
66
|
-
this.$problemsAmount = problemsAmount
|
|
67
|
-
this.$resolvedProblemsAmount = resolvedProblemsAmount
|
|
68
|
-
|
|
69
|
-
this.localStorage = customLocalStorage || localStorage
|
|
70
|
-
this.setupEventHandlers()
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
private failedGetGifxTimeout: NodeJS.Timeout | null = null
|
|
74
|
-
|
|
75
|
-
private setupEventHandlers() {
|
|
76
|
-
sample({
|
|
77
|
-
clock: this.initialize,
|
|
78
|
-
source: this.cache.$gifs,
|
|
79
|
-
filter: (gifs) => {
|
|
80
|
-
if (!gifs) return true
|
|
81
|
-
|
|
82
|
-
const gifsFetchedTimestamp = this.localStorage.getItem(GIFS_FETCHED_KEY)
|
|
83
|
-
return shouldRefreshGifs(gifsFetchedTimestamp)
|
|
84
|
-
},
|
|
85
|
-
target: this.api.getGifsFx,
|
|
86
|
-
})
|
|
87
|
-
|
|
88
|
-
sample({
|
|
89
|
-
source: this.api.getGifsFx.doneData,
|
|
90
|
-
filter: (response) => response.ok,
|
|
91
|
-
fn: (response) => response.data,
|
|
92
|
-
target: this.cache.initialSet,
|
|
93
|
-
})
|
|
94
|
-
|
|
95
|
-
sample({
|
|
96
|
-
source: this.api.getGifsFx.doneData,
|
|
97
|
-
filter: (response) => response.ok,
|
|
98
|
-
target: createEffect(() => {
|
|
99
|
-
this.localStorage.setItem(GIFS_FETCHED_KEY, new Date().toISOString())
|
|
100
|
-
}),
|
|
101
|
-
})
|
|
102
|
-
|
|
103
|
-
sample({
|
|
104
|
-
clock: [this.initialize, this.api.getGifsFx.doneData],
|
|
105
|
-
source: {
|
|
106
|
-
gifs: this.cache.$gifs,
|
|
107
|
-
problemsAmount: this.$problemsAmount,
|
|
108
|
-
resolvedProblemsAmount: this.$resolvedProblemsAmount,
|
|
109
|
-
},
|
|
110
|
-
filter: ({ problemsAmount, gifs }) => !!(problemsAmount >= MIN_PROBLEMS_TO_SHOW_GIF && gifs),
|
|
111
|
-
fn: ({ problemsAmount, resolvedProblemsAmount, gifs }) => {
|
|
112
|
-
if (!gifs) return null
|
|
113
|
-
return generateProblemsGifsTable(problemsAmount, resolvedProblemsAmount, gifs)
|
|
114
|
-
},
|
|
115
|
-
target: this.$problemsGifsTable,
|
|
116
|
-
})
|
|
117
|
-
|
|
118
|
-
sample({
|
|
119
|
-
source: this.$problemsGifsTable,
|
|
120
|
-
filter: (problemsGifsTable) => !!problemsGifsTable,
|
|
121
|
-
fn: (problemsGifsTable) => {
|
|
122
|
-
if (!problemsGifsTable) return []
|
|
123
|
-
return Object.values(problemsGifsTable).map((gif) => gif.url)
|
|
124
|
-
},
|
|
125
|
-
target: this.cache.prefetchGifs,
|
|
126
|
-
})
|
|
127
|
-
|
|
128
|
-
sample({
|
|
129
|
-
clock: this.play,
|
|
130
|
-
source: {
|
|
131
|
-
isGifCelebrationMayBeTriggered: this.$isGifTriggerable,
|
|
132
|
-
gifsGroups: this.cache.$gifs,
|
|
133
|
-
resolvedProblemsAmount: this.$resolvedProblemsAmount,
|
|
134
|
-
problemsGifsTable: this.$problemsGifsTable,
|
|
135
|
-
},
|
|
136
|
-
filter: ({
|
|
137
|
-
isGifCelebrationMayBeTriggered,
|
|
138
|
-
gifsGroups,
|
|
139
|
-
resolvedProblemsAmount,
|
|
140
|
-
problemsGifsTable,
|
|
141
|
-
}) =>
|
|
142
|
-
!!(
|
|
143
|
-
isGifCelebrationMayBeTriggered &&
|
|
144
|
-
gifsGroups &&
|
|
145
|
-
resolvedProblemsAmount !== undefined &&
|
|
146
|
-
problemsGifsTable
|
|
147
|
-
),
|
|
148
|
-
fn: (sources) => sources as HandleGifSelectionProps,
|
|
149
|
-
target: this.updateGifShownStatus,
|
|
150
|
-
})
|
|
151
|
-
|
|
152
|
-
this.api.getGifsFx.fail.watch(() => {
|
|
153
|
-
this.failedGetGifxTimeout = setTimeout(() => {
|
|
154
|
-
this.api.getGifsFx()
|
|
155
|
-
}, GET_GIFS_TIMEOUT)
|
|
156
|
-
})
|
|
157
|
-
|
|
158
|
-
this.api.getGifsFx.done.watch(() => {
|
|
159
|
-
if (this.failedGetGifxTimeout) {
|
|
160
|
-
clearTimeout(this.failedGetGifxTimeout)
|
|
161
|
-
this.failedGetGifxTimeout = null
|
|
162
|
-
}
|
|
163
|
-
})
|
|
164
|
-
}
|
|
165
|
-
|
|
166
|
-
private readonly updateGifShownStatus = createEffect(
|
|
167
|
-
({ gifsGroups, resolvedProblemsAmount, problemsGifsTable }: HandleGifSelectionProps) => {
|
|
168
|
-
const gifToShow = problemsGifsTable[resolvedProblemsAmount]
|
|
169
|
-
const groupName = gifToShow.group
|
|
170
|
-
|
|
171
|
-
const gifsInGroup = gifsGroups[groupName]
|
|
172
|
-
const selectedGifIndex = gifsInGroup?.findIndex((gif) => gif.url === gifToShow.url)
|
|
173
|
-
|
|
174
|
-
if (!gifsInGroup || selectedGifIndex === -1) {
|
|
175
|
-
console.warn(`Gif with URL ${gifToShow.url} not found in group ${groupName}`)
|
|
176
|
-
return
|
|
177
|
-
}
|
|
178
|
-
|
|
179
|
-
const updatedGifsInGroup = gifsInGroup.map((gif, index) => ({
|
|
180
|
-
...gif,
|
|
181
|
-
isShown: index === selectedGifIndex ? true : gif.isShown,
|
|
182
|
-
}))
|
|
183
|
-
|
|
184
|
-
this.cache.set({
|
|
185
|
-
...gifsGroups,
|
|
186
|
-
[groupName]: updatedGifsInGroup,
|
|
187
|
-
})
|
|
188
|
-
|
|
189
|
-
this.setActiveGif(gifToShow)
|
|
190
|
-
},
|
|
191
|
-
)
|
|
192
|
-
}
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import { createControllerEffect } from './../../../lib/effector/createControllerEffect'
|
|
2
|
-
import { GifCelebrationApiRequests } from '../types/model.types'
|
|
3
|
-
|
|
4
|
-
export class GifCelebrationsApi {
|
|
5
|
-
public readonly getGifsFx
|
|
6
|
-
|
|
7
|
-
constructor(api: GifCelebrationApiRequests) {
|
|
8
|
-
this.getGifsFx = createControllerEffect(() => api.getGifs())
|
|
9
|
-
}
|
|
10
|
-
}
|
|
@@ -1,53 +0,0 @@
|
|
|
1
|
-
import { Store } from 'effector'
|
|
2
|
-
|
|
3
|
-
export type CustomGetCachePathMethod = (uri: string) => Promise<string | null>
|
|
4
|
-
export type CustomPrefetchMethod = (gifs: string[] | string) => Promise<unknown>
|
|
5
|
-
export type CustomLocalStorage = {
|
|
6
|
-
setItem: (key: string, value: string) => void
|
|
7
|
-
getItem: (key: string) => string | null | undefined
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
export type GroupNumber = number
|
|
11
|
-
|
|
12
|
-
export type GifCelebrationApiRequests = {
|
|
13
|
-
getGifs: () => Promise<GifResponse>
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
export type GifCelebrationsModelProps = {
|
|
17
|
-
api: GifCelebrationApiRequests
|
|
18
|
-
problemsAmount: Store<number>
|
|
19
|
-
resolvedProblemsAmount: Store<number>
|
|
20
|
-
customLocalStorage?: CustomLocalStorage
|
|
21
|
-
customPrefetchMethod?: CustomPrefetchMethod
|
|
22
|
-
customGetCachePathMethod?: CustomGetCachePathMethod
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
export type GifsGroup = string[]
|
|
26
|
-
export type GroupNumberString = `group${GroupNumber}`
|
|
27
|
-
export type GifsGroups = Record<GroupNumberString, GifsGroup>
|
|
28
|
-
|
|
29
|
-
export type GifObject = {
|
|
30
|
-
url: string
|
|
31
|
-
group: GroupNumberString
|
|
32
|
-
isShown?: boolean
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
export type GifsStructure = Record<GroupNumberString, GifObject[]>
|
|
36
|
-
/**
|
|
37
|
-
* Usually, the response contains 3 groups of gifs:
|
|
38
|
-
* - group1: early celebrations
|
|
39
|
-
* - group2: mid celebrations
|
|
40
|
-
* - group3: party
|
|
41
|
-
*/
|
|
42
|
-
export type GifResponse = {
|
|
43
|
-
data: GifsGroups
|
|
44
|
-
ok: boolean
|
|
45
|
-
}
|
|
46
|
-
export type GifsPayload = {
|
|
47
|
-
group: number
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
export type ProblemsGifsTable = Record<number, GifObject>
|
|
51
|
-
export type ProgressValue = 0 | 1 | 2
|
|
52
|
-
|
|
53
|
-
export type TextComponentType = (text: string) => React.ReactNode
|
package/src/react-app-env.d.ts
DELETED
package/src/shared/constants.ts
DELETED