@financial-times/qanda-ui 0.0.1-beta.1
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/.prettierrc +3 -0
- package/.toolkitrc.yml +34 -0
- package/.vscode/settings.json +4 -0
- package/CODEOWNERS +3 -0
- package/README.md +161 -0
- package/babel.config.json +10 -0
- package/dist/index.html +4 -0
- package/dist/index.js +2 -0
- package/dist/index.js.LICENSE.txt +15 -0
- package/dist/mockServiceWorker.js +307 -0
- package/jest.setup.ts +15 -0
- package/package.json +115 -0
- package/server.js +17 -0
- package/src/client/styles.scss +61 -0
- package/src/components/Author.tsx +45 -0
- package/src/components/CountdownTimer.tsx +73 -0
- package/src/components/Network.tsx +19 -0
- package/src/components/Qanda.tsx +51 -0
- package/src/components/QandaBlock.tsx +63 -0
- package/src/components/QandaContainer.tsx +60 -0
- package/src/components/QandaOComments.tsx +60 -0
- package/src/components/QandaProvider.tsx +13 -0
- package/src/components/QuestionForm.tsx +122 -0
- package/src/components/Status.tsx +20 -0
- package/src/components/Stream.tsx +49 -0
- package/src/components/UITestBar.tsx +76 -0
- package/src/components/UpdatesButton.tsx +45 -0
- package/src/components/UserInfo.tsx +57 -0
- package/src/index.tsx +58 -0
- package/src/services/comments-api.ts +217 -0
- package/src/services/custom-sse.ts +101 -0
- package/src/services/mocks/api-endpoints.ts +36 -0
- package/src/services/mocks/mock-comments.json +307 -0
- package/src/services/mocks/msw-browser.ts +4 -0
- package/src/services/mocks/msw-server.ts +4 -0
- package/src/store/index.ts +41 -0
- package/src/store/network.ts +23 -0
- package/src/store/qa.ts +22 -0
- package/src/store/questionSlice.ts +37 -0
- package/src/store/stream.ts +21 -0
- package/src/store/updateComments.ts +60 -0
- package/src/store/user.ts +55 -0
- package/src/types/async-operation.d.ts +4 -0
- package/src/types/comment.d.ts +19 -0
- package/src/types/globals.d.ts +1 -0
- package/src/types/modules.d.ts +1 -0
- package/src/types/o-types.d.ts +2 -0
- package/src/types/qanda.d.ts +7 -0
- package/src/types/sse-events.d.ts +6 -0
- package/src/types/x-dash.d.ts +6 -0
- package/src/utils/auth.ts +9 -0
- package/src/utils/mocks/update.ts +168 -0
- package/src/utils/qandas.ts +21 -0
- package/tsconfig.json +26 -0
- package/webpack.common.js +60 -0
- package/webpack.dev.js +26 -0
- package/webpack.prod.js +6 -0
package/.prettierrc
ADDED
package/.toolkitrc.yml
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
plugins:
|
|
2
|
+
- '@dotcom-tool-kit/component'
|
|
3
|
+
- '@dotcom-tool-kit/jest'
|
|
4
|
+
- '@dotcom-tool-kit/webpack'
|
|
5
|
+
- '@dotcom-tool-kit/node'
|
|
6
|
+
commands:
|
|
7
|
+
test:local:
|
|
8
|
+
- Jest
|
|
9
|
+
test:ci:
|
|
10
|
+
- Jest
|
|
11
|
+
build:local:
|
|
12
|
+
- Webpack
|
|
13
|
+
run:local:
|
|
14
|
+
- Webpack
|
|
15
|
+
- Node
|
|
16
|
+
publish:tag:
|
|
17
|
+
- NpmPublish
|
|
18
|
+
options:
|
|
19
|
+
plugins:
|
|
20
|
+
dotcom-tool-kit:
|
|
21
|
+
allowNativeFetch: true
|
|
22
|
+
'@dotcom-tool-kit/circleci':
|
|
23
|
+
cimgNodeVersions:
|
|
24
|
+
- '22.4'
|
|
25
|
+
- '23.9'
|
|
26
|
+
tasks:
|
|
27
|
+
Jest:
|
|
28
|
+
configPath: jest.config.js
|
|
29
|
+
Webpack:
|
|
30
|
+
configPath: webpack.prod.js
|
|
31
|
+
envName: production
|
|
32
|
+
Node:
|
|
33
|
+
entry: server.js
|
|
34
|
+
useDoppler: false
|
package/CODEOWNERS
ADDED
package/README.md
ADDED
|
@@ -0,0 +1,161 @@
|
|
|
1
|
+
# QandA-UI
|
|
2
|
+
|
|
3
|
+
A library for the Live Q&A client-side component
|
|
4
|
+
|
|
5
|
+
## Features
|
|
6
|
+
|
|
7
|
+
## Usage
|
|
8
|
+
|
|
9
|
+
This library exports a class which can be used to construct a new instance of QandaUI and exposes methods to initialise that and to destroy it.
|
|
10
|
+
|
|
11
|
+
You can pass the necessary settings to Qanda UI in either the JS or in the container element.
|
|
12
|
+
|
|
13
|
+
### Example:
|
|
14
|
+
|
|
15
|
+
```jsx
|
|
16
|
+
<div class="qanda"></div>
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
```js
|
|
20
|
+
import QandaUI from '@financial-times/qanda-ui';
|
|
21
|
+
|
|
22
|
+
const qandaEl = document.querySelector('.qanda');
|
|
23
|
+
const qandaUI = new QandaUI(qandaEl, {
|
|
24
|
+
storyId: '71539bd7-1818-4193-8a58-d5a4d914a012',
|
|
25
|
+
useStaging: true,
|
|
26
|
+
title: 'Lorem ipsum title',
|
|
27
|
+
commentsAPIHost: 'https://comments-api-local.ft.com',
|
|
28
|
+
commentsAPIVersion: 'v1',
|
|
29
|
+
});
|
|
30
|
+
qandaUI.init();
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
Alternatively
|
|
34
|
+
|
|
35
|
+
```jsx
|
|
36
|
+
<div
|
|
37
|
+
class="qanda"
|
|
38
|
+
data-qanda-storyId="71539bd7-1818-4193-8a58-d5a4d914a012"
|
|
39
|
+
data-qanda-useStaging="true"
|
|
40
|
+
data-qanda-title="Article title"
|
|
41
|
+
data-qanda-commentsAPIHost="https://comments-api.ft.com"
|
|
42
|
+
data-qanda-commentsAPIVersion="v1"
|
|
43
|
+
></div>
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
```js
|
|
47
|
+
import QandaUI from '@financial-times/qanda-ui';
|
|
48
|
+
const qandaEl = document.querySelector('.qanda');
|
|
49
|
+
const qandaUI = new QandaUI(qandaEl);
|
|
50
|
+
qandaUI.init();
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
### Parameters
|
|
54
|
+
|
|
55
|
+
- storyId: (required) string, the ID of the article used for Live Q&A
|
|
56
|
+
- useStaging: (optional) boolean, set to true if you want to use the staging Coral
|
|
57
|
+
- title: (required) string, the article title, needed to set up Coral properly
|
|
58
|
+
- commentsAPIHost: (required) string, the host of the API to be used (include the protocol)
|
|
59
|
+
- commentsAPIVersion: (required) string, the version of the API to be used
|
|
60
|
+
|
|
61
|
+
### Instance Methods
|
|
62
|
+
|
|
63
|
+
- `myInstance.init()` - render the Qanda UI
|
|
64
|
+
- `myInstance.destroy()` - remove the Qanda instance
|
|
65
|
+
|
|
66
|
+
## Development
|
|
67
|
+
|
|
68
|
+
### Prerequisites
|
|
69
|
+
|
|
70
|
+
- Node.js
|
|
71
|
+
- npm
|
|
72
|
+
|
|
73
|
+
### Installation
|
|
74
|
+
|
|
75
|
+
```sh
|
|
76
|
+
npm install
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
### Running the Development Environment
|
|
80
|
+
|
|
81
|
+
To start the development server, run:
|
|
82
|
+
|
|
83
|
+
```sh
|
|
84
|
+
npm run dev
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
This will start the server on `https://local.ft.com:3005`.
|
|
88
|
+
|
|
89
|
+
Add on `?storyID=somestoryID` to show the details for a particular article.
|
|
90
|
+
|
|
91
|
+
### Customization
|
|
92
|
+
|
|
93
|
+
You can customize the demo application by modifying the configuration files in the `demo/config.ts` or altering the settings in `demo/index.jsx`.
|
|
94
|
+
|
|
95
|
+
These are the config settings you can work with:
|
|
96
|
+
|
|
97
|
+
- `export const USE_STAGING = true;` // use Coral staging or production
|
|
98
|
+
- `export const USE_LOCAL_API = true;` // use local next-comments-api or live
|
|
99
|
+
- `export const MOCK_SSE = true;` // use a dummy eventsource that lets you send mock events rather than listen to ones coming from next-comments-api
|
|
100
|
+
|
|
101
|
+
### Building and Running the Production Server
|
|
102
|
+
|
|
103
|
+
To build the project and run it via Express, run:
|
|
104
|
+
|
|
105
|
+
```sh
|
|
106
|
+
npm run build && npm start
|
|
107
|
+
```
|
|
108
|
+
|
|
109
|
+
This will start the server on `http://local.ft.com:3005`.
|
|
110
|
+
|
|
111
|
+
### Running Tests
|
|
112
|
+
|
|
113
|
+
To run the Jest tests, use:
|
|
114
|
+
|
|
115
|
+
```sh
|
|
116
|
+
npm run test
|
|
117
|
+
```
|
|
118
|
+
|
|
119
|
+
## Technology
|
|
120
|
+
|
|
121
|
+
This uses React, Redux and RTK Query to create the components and manage their states.
|
|
122
|
+
|
|
123
|
+
- RTK Query is used for API calls to `next-comments-api`.
|
|
124
|
+
- The store is used for non-API data that needs to be shared around the components
|
|
125
|
+
- The story ID and useStaging settings passed in when the Qanda compontent is set are saved into the Context.
|
|
126
|
+
|
|
127
|
+
### How updates work
|
|
128
|
+
|
|
129
|
+
In order to receive updates from the next comments API, we use an EventSource that listens to an EventEmitter endpoint on next-comments-api.
|
|
130
|
+
|
|
131
|
+
It is very similar to the process used in `next-live-event-api` for live blogs updates.
|
|
132
|
+
|
|
133
|
+
For full details, see https://github.com/Financial-Times/next-comments-api/blob/main/docs/liveqa.md#qanda-and-next-comments-api
|
|
134
|
+
|
|
135
|
+
When a new comment relevant to the Q&A is posted, Coral will send out a message via a webhook to the next-comments API.
|
|
136
|
+
|
|
137
|
+
The next-comments API will then fetch the rest of the data for the comments and publish the data to any listening clients.
|
|
138
|
+
|
|
139
|
+
## Project Structure
|
|
140
|
+
|
|
141
|
+
- `src/`: Contains the source code for the application.
|
|
142
|
+
- `components/`: React components used in the application.
|
|
143
|
+
- `store/`: Redux store configuration and slices.
|
|
144
|
+
- `client/`: Client-side utilities and configurations.
|
|
145
|
+
- `utils/`: Utility functions.
|
|
146
|
+
- `types/`: TypeScript type definitions.
|
|
147
|
+
- `dist/`: The output directory for the built project.
|
|
148
|
+
- `__mocks__/`: Mock data for testing.
|
|
149
|
+
|
|
150
|
+
## Contributing
|
|
151
|
+
|
|
152
|
+
1. Open a PR with your changes against the `main` branch
|
|
153
|
+
2. Get an approval from someone from your team
|
|
154
|
+
3. Ask for a StoryTelling team review in #storytelling-support
|
|
155
|
+
4. Once merged, tag a version in github and a new version of the package will be automatic released
|
|
156
|
+
5. Open a PR in next-article and one in FT-App with the latest version
|
|
157
|
+
6. Ask for a review from StoryTelling in #storytelling-support
|
|
158
|
+
|
|
159
|
+
## License
|
|
160
|
+
|
|
161
|
+
This project is licensed under the MIT License.
|
package/dist/index.html
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
<!doctype html><html lang="en"><head><meta charset="UTF-8"/><meta name="viewport" content="width=device-width,initial-scale=1"/><title>Live Q&A UI</title><style>.app-container {
|
|
2
|
+
text-align: center;
|
|
3
|
+
padding: 80px 20px;
|
|
4
|
+
}</style></head><body><div id="root" class="app-container"></div><script defer="defer" src="index.js"></script></body></html>
|