@streamlayer/feature-gamification
Advanced tools
Comparing version 0.21.0 to 0.21.1
import { createMapStore } from '@streamlayer/sdk-web-interfaces'; | ||
import { deepmerge } from '@fastify/deepmerge'; | ||
import { computed } from 'nanostores'; | ||
import { getQuestionByUser } from './queries'; | ||
const mergeArray = (options) => (target, source) => { | ||
let i = 0; | ||
const tl = target.length; | ||
const sl = source.length; | ||
const il = Math.max(tl, sl); | ||
const result = new Array(il); | ||
for (i = 0; i < il; ++i) { | ||
if (i < sl) { | ||
result[i] = options.deepmerge(target[i], source[i]); | ||
} | ||
else { | ||
result[i] = options.clone(target[i]); | ||
} | ||
} | ||
return result; | ||
}; | ||
const mergeQuestion = deepmerge({ mergeArray }); | ||
export const detail = (transport, $openedQuestionId, $feedList) => { | ||
@@ -30,5 +48,20 @@ const $store = computed([$openedQuestionId, $feedList], (openedQuestion, feedList) => { | ||
const updateExtendedQuestion = (question) => { | ||
$extendedStore.set({ data: question }); | ||
const currentQuestion = $extendedStore.get().data; | ||
if (currentQuestion) { | ||
/** | ||
* We do not merge youVoted property, because it | ||
* can be overwritten by the subscription response, | ||
* which does not include user-specific data. | ||
*/ | ||
for (const answer of question?.answers || []) { | ||
if (answer.youVoted !== true) { | ||
// eslint-disable-next-line @typescript-eslint/ban-ts-comment | ||
// @ts-ignore | ||
delete answer.youVoted; | ||
} | ||
} | ||
} | ||
$extendedStore.set({ data: mergeQuestion(currentQuestion, question) }); | ||
}; | ||
return { $store, $extendedStore, updateExtendedQuestion }; | ||
}; |
{ | ||
"name": "@streamlayer/feature-gamification", | ||
"version": "0.21.0", | ||
"version": "0.21.1", | ||
"peerDependencies": { | ||
"@bufbuild/protobuf": "^1.4.2", | ||
"@streamlayer/sl-eslib": "^5.53.5", | ||
"@fastify/deepmerge": "*", | ||
"nanostores": "^0.9.5", | ||
"@streamlayer/sdk-web-interfaces": "^0.18.10", | ||
"@streamlayer/sdk-web-core": "^0.17.3", | ||
"@streamlayer/sdk-web-api": "^0.0.1", | ||
"@streamlayer/sdk-web-types": "^0.18.0", | ||
"@streamlayer/sdk-web-storage": "^0.3.10", | ||
"@streamlayer/sdk-web-notifications": "^0.10.9", | ||
"@streamlayer/sdk-web-logger": "^0.5.10" | ||
"@streamlayer/sdk-web-core": "^0.17.4", | ||
"@streamlayer/sdk-web-interfaces": "^0.18.11", | ||
"@streamlayer/sdk-web-logger": "^0.0.1", | ||
"@streamlayer/sdk-web-notifications": "^0.10.10", | ||
"@streamlayer/sdk-web-storage": "^0.0.1", | ||
"@streamlayer/sdk-web-types": "^0.18.1" | ||
}, | ||
@@ -16,0 +17,0 @@ "devDependencies": { |
73803
1344
11