PageContainer.js 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691
  1. import { Container } from 'unstated';
  2. import * as entities from 'entities';
  3. import * as toastr from 'toastr';
  4. import { pagePathUtils } from '@growi/core';
  5. import loggerFactory from '~/utils/logger';
  6. import { toastError } from '../util/apiNotification';
  7. import {
  8. DetachCodeBlockInterceptor,
  9. RestoreCodeBlockInterceptor,
  10. } from '../util/interceptor/detach-code-blocks';
  11. import {
  12. DrawioInterceptor,
  13. } from '../util/interceptor/drawio-interceptor';
  14. const { isTrashPage } = pagePathUtils;
  15. const logger = loggerFactory('growi:services:PageContainer');
  16. /**
  17. * Service container related to Page
  18. * @extends {Container} unstated Container
  19. */
  20. export default class PageContainer extends Container {
  21. constructor(appContainer) {
  22. super();
  23. this.appContainer = appContainer;
  24. this.appContainer.registerContainer(this);
  25. this.state = {};
  26. const mainContent = document.querySelector('#content-main');
  27. if (mainContent == null) {
  28. logger.debug('#content-main element is not exists');
  29. return;
  30. }
  31. const revisionId = mainContent.getAttribute('data-page-revision-id');
  32. const path = decodeURI(mainContent.getAttribute('data-path'));
  33. this.state = {
  34. // local page data
  35. markdown: null, // will be initialized after initStateMarkdown()
  36. pageId: mainContent.getAttribute('data-page-id'),
  37. revisionId,
  38. revisionCreatedAt: +mainContent.getAttribute('data-page-revision-created'),
  39. path,
  40. tocHtml: '',
  41. isBookmarked: false,
  42. sumOfBookmarks: 0,
  43. seenUsers: [],
  44. seenUserIds: [],
  45. sumOfSeenUsers: [],
  46. isLiked: false,
  47. likers: [],
  48. likerIds: [],
  49. sumOfLikers: 0,
  50. createdAt: mainContent.getAttribute('data-page-created-at'),
  51. updatedAt: mainContent.getAttribute('data-page-updated-at'),
  52. deletedAt: mainContent.getAttribute('data-page-deleted-at') || null,
  53. isUserPage: JSON.parse(mainContent.getAttribute('data-page-user')) != null,
  54. isTrashPage: isTrashPage(path),
  55. isDeleted: JSON.parse(mainContent.getAttribute('data-page-is-deleted')),
  56. isDeletable: JSON.parse(mainContent.getAttribute('data-page-is-deletable')),
  57. isNotCreatable: JSON.parse(mainContent.getAttribute('data-page-is-not-creatable')),
  58. isAbleToDeleteCompletely: JSON.parse(mainContent.getAttribute('data-page-is-able-to-delete-completely')),
  59. isPageExist: mainContent.getAttribute('data-page-id') != null,
  60. pageUser: JSON.parse(mainContent.getAttribute('data-page-user')),
  61. tags: null,
  62. hasChildren: JSON.parse(mainContent.getAttribute('data-page-has-children')),
  63. templateTagData: mainContent.getAttribute('data-template-tags') || null,
  64. shareLinksNumber: mainContent.getAttribute('data-share-links-number'),
  65. shareLinkId: JSON.parse(mainContent.getAttribute('data-share-link-id') || null),
  66. // latest(on remote) information
  67. remoteRevisionId: revisionId,
  68. revisionIdHackmdSynced: mainContent.getAttribute('data-page-revision-id-hackmd-synced') || null,
  69. lastUpdateUsername: mainContent.getAttribute('data-page-last-update-username') || null,
  70. deleteUsername: mainContent.getAttribute('data-page-delete-username') || null,
  71. pageIdOnHackmd: mainContent.getAttribute('data-page-id-on-hackmd') || null,
  72. hasDraftOnHackmd: !!mainContent.getAttribute('data-page-has-draft-on-hackmd'),
  73. isHackmdDraftUpdatingInRealtime: false,
  74. isConflictingOnSave: false,
  75. isConflictDiffModalOpen: false,
  76. revisionsOnConflict: {},
  77. };
  78. // parse creator, lastUpdateUser and revisionAuthor
  79. try {
  80. this.state.creator = JSON.parse(mainContent.getAttribute('data-page-creator'));
  81. }
  82. catch (e) {
  83. logger.warn('The data of \'data-page-creator\' is invalid', e);
  84. }
  85. try {
  86. this.state.revisionAuthor = JSON.parse(mainContent.getAttribute('data-page-revision-author'));
  87. }
  88. catch (e) {
  89. logger.warn('The data of \'data-page-revision-author\' is invalid', e);
  90. }
  91. const { interceptorManager } = this.appContainer;
  92. interceptorManager.addInterceptor(new DetachCodeBlockInterceptor(appContainer), 10); // process as soon as possible
  93. interceptorManager.addInterceptor(new DrawioInterceptor(appContainer), 20);
  94. interceptorManager.addInterceptor(new RestoreCodeBlockInterceptor(appContainer), 900); // process as late as possible
  95. this.initStateMarkdown();
  96. this.checkAndUpdateImageUrlCached(this.state.likers);
  97. const { isSharedUser } = this.appContainer;
  98. // see https://dev.growi.org/5fabddf8bbeb1a0048bcb9e9
  99. const isAbleToGetAttachedInformationAboutPages = this.state.isPageExist && !isSharedUser;
  100. if (isAbleToGetAttachedInformationAboutPages) {
  101. // We don't retrieve bookmarks in the initial page load
  102. // as it is stored in a separate collection to like and seen user
  103. // data so it has a separate api endpoint.
  104. this.initialPageLoad();
  105. this.retrieveBookmarkInfo();
  106. }
  107. this.setTocHtml = this.setTocHtml.bind(this);
  108. this.save = this.save.bind(this);
  109. this.checkAndUpdateImageUrlCached = this.checkAndUpdateImageUrlCached.bind(this);
  110. this.emitJoinPageRoomRequest = this.emitJoinPageRoomRequest.bind(this);
  111. this.emitJoinPageRoomRequest();
  112. this.addWebSocketEventHandlers = this.addWebSocketEventHandlers.bind(this);
  113. this.addWebSocketEventHandlers();
  114. const unlinkPageButton = document.getElementById('unlink-page-button');
  115. if (unlinkPageButton != null) {
  116. unlinkPageButton.addEventListener('click', async() => {
  117. try {
  118. const res = await this.appContainer.apiPost('/pages.unlink', { path });
  119. window.location.href = encodeURI(`${res.path}?unlinked=true`);
  120. }
  121. catch (err) {
  122. toastError(err);
  123. }
  124. });
  125. }
  126. }
  127. /**
  128. * Workaround for the mangling in production build to break constructor.name
  129. */
  130. static getClassName() {
  131. return 'PageContainer';
  132. }
  133. get isAbleToOpenPageEditor() {
  134. const { isNotCreatable, isTrashPage } = this.state;
  135. const { isGuestUser } = this.appContainer;
  136. return (!isNotCreatable && !isTrashPage && !isGuestUser);
  137. }
  138. /**
  139. * whether to display reaction buttons
  140. * ex.) like, bookmark
  141. */
  142. get isAbleToShowPageReactionButtons() {
  143. const { isTrashPage, isPageExist } = this.state;
  144. const { isSharedUser } = this.appContainer;
  145. return (!isTrashPage && isPageExist && !isSharedUser);
  146. }
  147. /**
  148. * whether to display tag labels
  149. */
  150. get isAbleToShowTagLabel() {
  151. const { isUserPage } = this.state;
  152. const { isSharedUser } = this.appContainer;
  153. return (!isUserPage && !isSharedUser);
  154. }
  155. /**
  156. * whether to display page management
  157. * ex.) duplicate, rename
  158. */
  159. get isAbleToShowPageManagement() {
  160. const { isPageExist, isTrashPage } = this.state;
  161. const { isSharedUser } = this.appContainer;
  162. return (isPageExist && !isTrashPage && !isSharedUser);
  163. }
  164. /**
  165. * whether to display pageEditorModeManager
  166. * ex.) view, edit, hackmd
  167. */
  168. get isAbleToShowPageEditorModeManager() {
  169. const { isNotCreatable, isTrashPage } = this.state;
  170. const { isSharedUser } = this.appContainer;
  171. return (!isNotCreatable && !isTrashPage && !isSharedUser);
  172. }
  173. /**
  174. * whether to display pageAuthors
  175. * ex.) creator, lastUpdateUser
  176. */
  177. get isAbleToShowPageAuthors() {
  178. const { isPageExist, isUserPage } = this.state;
  179. return (isPageExist && !isUserPage);
  180. }
  181. /**
  182. * whether to like button
  183. * not displayed on user page
  184. */
  185. get isAbleToShowLikeButtons() {
  186. const { isUserPage } = this.state;
  187. const { isSharedUser } = this.appContainer;
  188. return (!isUserPage && !isSharedUser);
  189. }
  190. /**
  191. * whether to Empty Trash Page
  192. * not displayed when guest user and not on trash page
  193. */
  194. get isAbleToShowEmptyTrashButton() {
  195. const { currentUser } = this.appContainer;
  196. const { path, hasChildren } = this.state;
  197. return (currentUser != null && currentUser.admin && path === '/trash' && hasChildren);
  198. }
  199. /**
  200. * whether to display trash management buttons
  201. * ex.) undo, delete completly
  202. * not displayed when guest user
  203. */
  204. get isAbleToShowTrashPageManagementButtons() {
  205. const { currentUser } = this.appContainer;
  206. const { isDeleted } = this.state;
  207. return (isDeleted && currentUser != null);
  208. }
  209. /**
  210. * initialize state for markdown data
  211. */
  212. initStateMarkdown() {
  213. let pageContent = '';
  214. const rawText = document.getElementById('raw-text-original');
  215. if (rawText) {
  216. pageContent = rawText.innerHTML;
  217. }
  218. const markdown = entities.decodeHTML(pageContent);
  219. this.state.markdown = markdown;
  220. }
  221. async initialPageLoad() {
  222. {
  223. const {
  224. data: {
  225. likerIds, sumOfLikers, isLiked, seenUserIds, sumOfSeenUsers, isSeen,
  226. },
  227. } = await this.appContainer.apiv3Get('/page/info', { _id: this.state.pageId });
  228. await this.setState({
  229. sumOfLikers,
  230. isLiked,
  231. likerIds,
  232. seenUserIds,
  233. sumOfSeenUsers,
  234. isSeen,
  235. });
  236. }
  237. await this.retrieveLikersAndSeenUsers();
  238. }
  239. async toggleLike() {
  240. {
  241. const toggledIsLiked = !this.state.isLiked;
  242. await this.appContainer.apiv3Put('/page/likes', { pageId: this.state.pageId, bool: toggledIsLiked });
  243. await this.setState(state => ({
  244. isLiked: toggledIsLiked,
  245. sumOfLikers: toggledIsLiked ? state.sumOfLikers + 1 : state.sumOfLikers - 1,
  246. likerIds: toggledIsLiked
  247. ? [...this.state.likerIds, this.appContainer.currentUserId]
  248. : state.likerIds.filter(id => id !== this.appContainer.currentUserId),
  249. }));
  250. }
  251. await this.retrieveLikersAndSeenUsers();
  252. }
  253. async retrieveLikersAndSeenUsers() {
  254. const { users } = await this.appContainer.apiGet('/users.list', { user_ids: [...this.state.likerIds, ...this.state.seenUserIds].join(',') });
  255. await this.setState({
  256. likers: users.filter(({ id }) => this.state.likerIds.includes(id)).slice(0, 15),
  257. seenUsers: users.filter(({ id }) => this.state.seenUserIds.includes(id)).slice(0, 15),
  258. });
  259. this.checkAndUpdateImageUrlCached(users);
  260. }
  261. async retrieveBookmarkInfo() {
  262. const response = await this.appContainer.apiv3Get('/bookmarks/info', { pageId: this.state.pageId });
  263. this.setState({
  264. sumOfBookmarks: response.data.sumOfBookmarks,
  265. isBookmarked: response.data.isBookmarked,
  266. });
  267. }
  268. async toggleBookmark() {
  269. const bool = !this.state.isBookmarked;
  270. await this.appContainer.apiv3Put('/bookmarks', { pageId: this.state.pageId, bool });
  271. return this.retrieveBookmarkInfo();
  272. }
  273. async checkAndUpdateImageUrlCached(users) {
  274. const noImageCacheUsers = users.filter((user) => { return user.imageUrlCached == null });
  275. if (noImageCacheUsers.length === 0) {
  276. return;
  277. }
  278. const noImageCacheUserIds = noImageCacheUsers.map((user) => { return user.id });
  279. try {
  280. await this.appContainer.apiv3Put('/users/update.imageUrlCache', { userIds: noImageCacheUserIds });
  281. }
  282. catch (err) {
  283. // Error alert doesn't apear, because user don't need to notice this error.
  284. logger.error(err);
  285. }
  286. }
  287. get navigationContainer() {
  288. return this.appContainer.getContainer('NavigationContainer');
  289. }
  290. setLatestRemotePageData(s2cMessagePageUpdated) {
  291. const newState = {
  292. remoteRevisionId: s2cMessagePageUpdated.revisionId,
  293. revisionIdHackmdSynced: s2cMessagePageUpdated.revisionIdHackmdSynced,
  294. lastUpdateUsername: s2cMessagePageUpdated.lastUpdateUsername,
  295. };
  296. if (s2cMessagePageUpdated.hasDraftOnHackmd != null) {
  297. newState.hasDraftOnHackmd = s2cMessagePageUpdated.hasDraftOnHackmd;
  298. }
  299. this.setState(newState);
  300. }
  301. setTocHtml(tocHtml) {
  302. if (this.state.tocHtml !== tocHtml) {
  303. this.setState({ tocHtml });
  304. }
  305. }
  306. /**
  307. * save success handler
  308. * @param {object} page Page instance
  309. * @param {Array[Tag]} tags Array of Tag
  310. * @param {object} revision Revision instance
  311. */
  312. updateStateAfterSave(page, tags, revision) {
  313. const { editorMode } = this.navigationContainer.state;
  314. // update state of PageContainer
  315. const newState = {
  316. pageId: page._id,
  317. revisionId: revision._id,
  318. revisionCreatedAt: new Date(revision.createdAt).getTime() / 1000,
  319. remoteRevisionId: revision._id,
  320. revisionIdHackmdSynced: page.revisionHackmdSynced,
  321. hasDraftOnHackmd: page.hasDraftOnHackmd,
  322. markdown: revision.body,
  323. createdAt: page.createdAt,
  324. updatedAt: page.updatedAt,
  325. };
  326. if (tags != null) {
  327. newState.tags = tags;
  328. }
  329. this.setState(newState);
  330. // PageEditor component
  331. const pageEditor = this.appContainer.getComponentInstance('PageEditor');
  332. if (pageEditor != null) {
  333. if (editorMode !== 'edit') {
  334. pageEditor.updateEditorValue(newState.markdown);
  335. }
  336. }
  337. // PageEditorByHackmd component
  338. const pageEditorByHackmd = this.appContainer.getComponentInstance('PageEditorByHackmd');
  339. if (pageEditorByHackmd != null) {
  340. // reset
  341. if (editorMode !== 'hackmd') {
  342. pageEditorByHackmd.reset();
  343. }
  344. }
  345. // hidden input
  346. $('input[name="revision_id"]').val(newState.revisionId);
  347. }
  348. /**
  349. * Save page
  350. * @param {string} markdown
  351. * @param {object} optionsToSave
  352. * @return {object} { page: Page, tags: Tag[] }
  353. */
  354. async save(markdown, optionsToSave = {}) {
  355. const { editorMode } = this.navigationContainer.state;
  356. const { pageId, path } = this.state;
  357. let { revisionId } = this.state;
  358. const options = Object.assign({}, optionsToSave);
  359. if (editorMode === 'hackmd') {
  360. // set option to sync
  361. options.isSyncRevisionToHackmd = true;
  362. revisionId = this.state.revisionIdHackmdSynced;
  363. }
  364. let res;
  365. if (pageId == null) {
  366. res = await this.createPage(path, markdown, options);
  367. }
  368. else {
  369. res = await this.updatePage(pageId, revisionId, markdown, options);
  370. }
  371. this.updateStateAfterSave(res.page, res.tags, res.revision);
  372. return res;
  373. }
  374. async saveAndReload(optionsToSave) {
  375. if (optionsToSave == null) {
  376. const msg = '\'saveAndReload\' requires the \'optionsToSave\' param';
  377. throw new Error(msg);
  378. }
  379. const { editorMode } = this.navigationContainer.state;
  380. if (editorMode == null) {
  381. logger.warn('\'saveAndReload\' requires the \'errorMode\' param');
  382. return;
  383. }
  384. const { pageId, path } = this.state;
  385. let { revisionId } = this.state;
  386. const options = Object.assign({}, optionsToSave);
  387. let markdown;
  388. if (editorMode === 'hackmd') {
  389. const pageEditorByHackmd = this.appContainer.getComponentInstance('PageEditorByHackmd');
  390. markdown = await pageEditorByHackmd.getMarkdown();
  391. // set option to sync
  392. options.isSyncRevisionToHackmd = true;
  393. revisionId = this.state.revisionIdHackmdSynced;
  394. }
  395. else {
  396. const pageEditor = this.appContainer.getComponentInstance('PageEditor');
  397. markdown = pageEditor.getMarkdown();
  398. }
  399. let res;
  400. if (pageId == null) {
  401. res = await this.createPage(path, markdown, options);
  402. }
  403. else {
  404. res = await this.updatePage(pageId, revisionId, markdown, options);
  405. }
  406. const editorContainer = this.appContainer.getContainer('EditorContainer');
  407. editorContainer.clearDraft(path);
  408. window.location.href = path;
  409. return res;
  410. }
  411. async createPage(pagePath, markdown, tmpParams) {
  412. const socketIoContainer = this.appContainer.getContainer('SocketIoContainer');
  413. // clone
  414. const params = Object.assign(tmpParams, {
  415. path: pagePath,
  416. body: markdown,
  417. });
  418. const res = await this.appContainer.apiv3Post('/pages/', params);
  419. const { page, tags, revision } = res.data;
  420. return { page, tags, revision };
  421. }
  422. async updatePage(pageId, revisionId, markdown, tmpParams) {
  423. const socketIoContainer = this.appContainer.getContainer('SocketIoContainer');
  424. // clone
  425. const params = Object.assign(tmpParams, {
  426. page_id: pageId,
  427. revision_id: revisionId,
  428. body: markdown,
  429. });
  430. const res = await this.appContainer.apiPost('/pages.update', params);
  431. if (!res.ok) {
  432. throw new Error(res.error);
  433. }
  434. return res;
  435. }
  436. deletePage(isRecursively, isCompletely) {
  437. const socketIoContainer = this.appContainer.getContainer('SocketIoContainer');
  438. // control flag
  439. const completely = isCompletely ? true : null;
  440. const recursively = isRecursively ? true : null;
  441. return this.appContainer.apiPost('/pages.remove', {
  442. recursively,
  443. completely,
  444. page_id: this.state.pageId,
  445. revision_id: this.state.revisionId,
  446. });
  447. }
  448. revertRemove(isRecursively) {
  449. const socketIoContainer = this.appContainer.getContainer('SocketIoContainer');
  450. // control flag
  451. const recursively = isRecursively ? true : null;
  452. return this.appContainer.apiPost('/pages.revertRemove', {
  453. recursively,
  454. page_id: this.state.pageId,
  455. });
  456. }
  457. rename(newPagePath, isRecursively, isRenameRedirect, isRemainMetadata) {
  458. const socketIoContainer = this.appContainer.getContainer('SocketIoContainer');
  459. const { pageId, revisionId, path } = this.state;
  460. return this.appContainer.apiv3Put('/pages/rename', {
  461. revisionId,
  462. pageId,
  463. isRecursively,
  464. isRenameRedirect,
  465. isRemainMetadata,
  466. newPagePath,
  467. path,
  468. });
  469. }
  470. showSuccessToastr() {
  471. toastr.success(undefined, 'Saved successfully', {
  472. closeButton: true,
  473. progressBar: true,
  474. newestOnTop: false,
  475. showDuration: '100',
  476. hideDuration: '100',
  477. timeOut: '1200',
  478. extendedTimeOut: '150',
  479. });
  480. }
  481. showErrorToastr(error) {
  482. toastr.error(error.message, 'Error occured', {
  483. closeButton: true,
  484. progressBar: true,
  485. newestOnTop: false,
  486. showDuration: '100',
  487. hideDuration: '100',
  488. timeOut: '3000',
  489. });
  490. }
  491. // request to server so the client to join a room for each page
  492. emitJoinPageRoomRequest() {
  493. const socketIoContainer = this.appContainer.getContainer('SocketIoContainer');
  494. const socket = socketIoContainer.getSocket();
  495. socket.emit('join:page', { socketId: socket.id, pageId: this.state.pageId });
  496. }
  497. addWebSocketEventHandlers() {
  498. // eslint-disable-next-line @typescript-eslint/no-this-alias
  499. const pageContainer = this;
  500. const socketIoContainer = this.appContainer.getContainer('SocketIoContainer');
  501. const socket = socketIoContainer.getSocket();
  502. socket.on('page:create', (data) => {
  503. logger.debug({ obj: data }, `websocket on 'page:create'`); // eslint-disable-line quotes
  504. // update remote page data
  505. const { s2cMessagePageUpdated } = data;
  506. if (s2cMessagePageUpdated.pageId === pageContainer.state.pageId) {
  507. pageContainer.setLatestRemotePageData(s2cMessagePageUpdated);
  508. }
  509. });
  510. socket.on('page:update', (data) => {
  511. logger.debug({ obj: data }, `websocket on 'page:update'`); // eslint-disable-line quotes
  512. // update remote page data
  513. const { s2cMessagePageUpdated } = data;
  514. if (s2cMessagePageUpdated.pageId === pageContainer.state.pageId) {
  515. pageContainer.setLatestRemotePageData(s2cMessagePageUpdated);
  516. }
  517. });
  518. socket.on('page:delete', (data) => {
  519. logger.debug({ obj: data }, `websocket on 'page:delete'`); // eslint-disable-line quotes
  520. // update remote page data
  521. const { s2cMessagePageUpdated } = data;
  522. if (s2cMessagePageUpdated.pageId === pageContainer.state.pageId) {
  523. pageContainer.setLatestRemotePageData(s2cMessagePageUpdated);
  524. }
  525. });
  526. socket.on('page:editingWithHackmd', (data) => {
  527. logger.debug({ obj: data }, `websocket on 'page:editingWithHackmd'`); // eslint-disable-line quotes
  528. // update isHackmdDraftUpdatingInRealtime
  529. const { s2cMessagePageUpdated } = data;
  530. if (s2cMessagePageUpdated.pageId === pageContainer.state.pageId) {
  531. pageContainer.setState({ isHackmdDraftUpdatingInRealtime: true });
  532. }
  533. });
  534. }
  535. /* TODO GW-325 */
  536. retrieveMyBookmarkList() {
  537. }
  538. async resolveConflict(pageId, revisionId, markdown, optionsToSave) {
  539. if (optionsToSave == null) {
  540. const msg = '\'saveAndReload\' requires the \'optionsToSave\' param';
  541. throw new Error(msg);
  542. }
  543. const { path } = this.state;
  544. const params = Object.assign(optionsToSave, {
  545. page_id: pageId,
  546. revision_id: revisionId,
  547. body: markdown,
  548. });
  549. const res = await this.appContainer.apiPost('/pages.update', params);
  550. if (!res.ok) {
  551. throw new Error(res.error);
  552. }
  553. const editorContainer = this.appContainer.getContainer('EditorContainer');
  554. editorContainer.clearDraft(path);
  555. return res;
  556. }
  557. async resolveConflictAndReload(pageId, revisionId, markdown, optionsToSave) {
  558. await this.resolveConflict(pageId, revisionId, markdown, optionsToSave);
  559. window.location.href = this.state.path;
  560. }
  561. }