@financial-times/qanda-ui 0.0.1-beta.47 → 0.0.1-beta.48

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/cjs/index.js CHANGED
@@ -21,9 +21,8 @@ class QandaUI {
21
21
  throw new Error('Required properties are missing');
22
22
  }
23
23
  const storyId = options?.storyId ?? containerElement.dataset.qandaStoryid;
24
- const useStaging = options?.useStaging ??
25
- containerElement.dataset.qandaUsestaging === 'true' ??
26
- false;
24
+ const stagingData = containerElement.dataset.qandaUsestaging === 'true' ? true : false;
25
+ const useStaging = options?.useStaging ?? stagingData;
27
26
  const title = options?.title ?? containerElement.dataset.qandaTitle;
28
27
  const commentsAPIHost = options?.commentsAPIHost ?? containerElement.dataset.qandaCommentsapihost;
29
28
  const commentsAPIVersion = options?.commentsAPIVersion ??
@@ -3,7 +3,7 @@
3
3
  Object.defineProperty(exports, "__esModule", { value: true });
4
4
  exports.updateComments = void 0;
5
5
  const comments_api_1 = require("../services/comments-api");
6
- const stream_1 = require("../store/stream");
6
+ const stream_1 = require("./stream");
7
7
  const qandas_1 = require("../utils/qandas");
8
8
  const updateComments = (dispatch, updatedComments, storyId, useStaging, commentsAPIUrl) => {
9
9
  if (!updatedComments.length) {
@@ -15,12 +15,15 @@ const updateComments = (dispatch, updatedComments, storyId, useStaging, comments
15
15
  dispatch(comments_api_1.nextCommentsApi.util.updateQueryData('getQandAStream',
16
16
  // Updates happen only for the live stream, so we pass the status as 'live' hardcoded
17
17
  { storyId, useStaging, commentsAPIUrl, status: 'live' }, (draft) => {
18
- // NB - if the same comment is updated more than once, the most recent thing added to the array will be the one that is shown
18
+ // NB - if the same comment is updated more than once, the most recent thing added to the array will be the one that is shown, as each update is the full question and answer block
19
+ // this will check if a question already exists in the store, and if so, it will update the object and move to the top of the array so that we don't have duplicates and it is in the right order
19
20
  for (let c = 0; c < updatedComments.length; c++) {
20
21
  const commentId = updatedComments[c].id;
21
22
  const commentIndex = draft.qandas.findIndex((d) => d.id === commentId);
22
23
  if (commentIndex > -1) {
23
24
  draft.qandas[commentIndex] = updatedComments[c];
25
+ const commentToMove = draft.qandas.splice(commentIndex, 1);
26
+ draft.qandas.unshift(commentToMove[0]);
24
27
  }
25
28
  else {
26
29
  draft.qandas.unshift(updatedComments[c]);
package/dist/esm/index.js CHANGED
@@ -14,9 +14,8 @@ class QandaUI {
14
14
  throw new Error('Required properties are missing');
15
15
  }
16
16
  const storyId = options?.storyId ?? containerElement.dataset.qandaStoryid;
17
- const useStaging = options?.useStaging ??
18
- containerElement.dataset.qandaUsestaging === 'true' ??
19
- false;
17
+ const stagingData = containerElement.dataset.qandaUsestaging === 'true' ? true : false;
18
+ const useStaging = options?.useStaging ?? stagingData;
20
19
  const title = options?.title ?? containerElement.dataset.qandaTitle;
21
20
  const commentsAPIHost = options?.commentsAPIHost ?? containerElement.dataset.qandaCommentsapihost;
22
21
  const commentsAPIVersion = options?.commentsAPIVersion ??
@@ -1,6 +1,6 @@
1
1
  // PURPOSE: move the comments saved in updatedComments into the main comments array for the stream and then clear out the updatedComments array, and update the lastAnsweredQuestionId in the store
2
2
  import { nextCommentsApi } from '../services/comments-api';
3
- import { setLatestAnsweredQuestionId } from '../store/stream';
3
+ import { setLatestAnsweredQuestionId } from './stream';
4
4
  import { getLatestAnsweredQuestion } from '../utils/qandas';
5
5
  export const updateComments = (dispatch, updatedComments, storyId, useStaging, commentsAPIUrl) => {
6
6
  if (!updatedComments.length) {
@@ -12,12 +12,15 @@ export const updateComments = (dispatch, updatedComments, storyId, useStaging, c
12
12
  dispatch(nextCommentsApi.util.updateQueryData('getQandAStream',
13
13
  // Updates happen only for the live stream, so we pass the status as 'live' hardcoded
14
14
  { storyId, useStaging, commentsAPIUrl, status: 'live' }, (draft) => {
15
- // NB - if the same comment is updated more than once, the most recent thing added to the array will be the one that is shown
15
+ // NB - if the same comment is updated more than once, the most recent thing added to the array will be the one that is shown, as each update is the full question and answer block
16
+ // this will check if a question already exists in the store, and if so, it will update the object and move to the top of the array so that we don't have duplicates and it is in the right order
16
17
  for (let c = 0; c < updatedComments.length; c++) {
17
18
  const commentId = updatedComments[c].id;
18
19
  const commentIndex = draft.qandas.findIndex((d) => d.id === commentId);
19
20
  if (commentIndex > -1) {
20
21
  draft.qandas[commentIndex] = updatedComments[c];
22
+ const commentToMove = draft.qandas.splice(commentIndex, 1);
23
+ draft.qandas.unshift(commentToMove[0]);
21
24
  }
22
25
  else {
23
26
  draft.qandas.unshift(updatedComments[c]);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@financial-times/qanda-ui",
3
- "version": "0.0.1-beta.47",
3
+ "version": "0.0.1-beta.48",
4
4
  "description": "Components for the Live Q&A (AKA Ask an Expert) UI",
5
5
  "main": "dist/cjs/index.js",
6
6
  "module": "dist/esm/index.js",