/* Copyright 2020 The Matrix.org Foundation C.I.C. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. */ import React from 'react'; import PropTypes from 'prop-types'; import classNames from 'classnames'; import * as sdk from '../../../index'; import { _t } from '../../../languageHandler'; import Modal from '../../../Modal'; import AccessibleButton from "../elements/AccessibleButton"; import SettingsStore, {SettingLevel} from "../../../settings/SettingsStore"; import LabelledToggleSwitch from "../elements/LabelledToggleSwitch"; import Field from "../elements/Field"; import {formatBytes} from "../../../utils/FormattingUtils"; import EventIndexPeg from "../../../indexing/EventIndexPeg"; export default class EventIndexPanel extends React.Component { constructor() { super(); this.state = { eventIndexSize: 0, roomCount: 0, }; } async updateCurrentRoom(room) { const eventIndex = EventIndexPeg.get(); const stats = await eventIndex.getStats(); this.setState({ eventIndexSize: stats.size, roomCount: stats.roomCount, }); } componentWillUnmount(): void { const eventIndex = EventIndexPeg.get(); if (eventIndex !== null) { eventIndex.removeListener("changedCheckpoint", this.updateCurrentRoom.bind(this)); } } async componentWillMount(): void { let eventIndexSize = 0; let roomCount = 0; const eventIndex = EventIndexPeg.get(); if (eventIndex !== null) { eventIndex.on("changedCheckpoint", this.updateCurrentRoom.bind(this)); const stats = await eventIndex.getStats(); eventIndexSize = stats.size; roomCount = stats.roomCount; } this.setState({ eventIndexSize, roomCount, }); } _onManage = async () => { Modal.createTrackedDialogAsync('Message search', 'Message search', import('../../../async-components/views/dialogs/eventindex/ManageEventIndex'), { onFinished: () => {}, }, null, /* priority = */ false, /* static = */ true, ); } render() { let eventIndexingSettings = null; if (EventIndexPeg.get() !== null) { eventIndexingSettings = (