1
0
mirror of https://github.com/matrix-org/matrix-react-sdk.git synced 2025-11-07 10:46:24 +03:00

Convert SendHistoryManager to TS

Signed-off-by: Michael Telatynski <7t3chguy@gmail.com>
This commit is contained in:
Michael Telatynski
2020-10-06 13:55:39 +01:00
parent 5f615bd4c9
commit 45fa647655

View File

@@ -16,12 +16,14 @@ limitations under the License.
*/ */
import {clamp} from "lodash"; import {clamp} from "lodash";
import {SerializedPart} from "./editor/parts";
import EditorModel from "./editor/model";
export default class SendHistoryManager { export default class SendHistoryManager {
history: Array<HistoryItem> = []; history: Array<SerializedPart[]> = [];
prefix: string; prefix: string;
lastIndex: number = 0; // used for indexing the storage lastIndex = 0; // used for indexing the storage
currentIndex: number = 0; // used for indexing the loaded validated history Array currentIndex = 0; // used for indexing the loaded validated history Array
constructor(roomId: string, prefix: string) { constructor(roomId: string, prefix: string) {
this.prefix = prefix + roomId; this.prefix = prefix + roomId;
@@ -45,7 +47,7 @@ export default class SendHistoryManager {
this.currentIndex = this.lastIndex + 1; this.currentIndex = this.lastIndex + 1;
} }
save(editorModel: Object) { save(editorModel: EditorModel) {
const serializedParts = editorModel.serializeParts(); const serializedParts = editorModel.serializeParts();
this.history.push(serializedParts); this.history.push(serializedParts);
this.currentIndex = this.history.length; this.currentIndex = this.history.length;
@@ -53,7 +55,7 @@ export default class SendHistoryManager {
sessionStorage.setItem(`${this.prefix}[${this.lastIndex}]`, JSON.stringify(serializedParts)); sessionStorage.setItem(`${this.prefix}[${this.lastIndex}]`, JSON.stringify(serializedParts));
} }
getItem(offset: number): ?HistoryItem { getItem(offset: number): SerializedPart[] {
this.currentIndex = clamp(this.currentIndex + offset, 0, this.history.length - 1); this.currentIndex = clamp(this.currentIndex + offset, 0, this.history.length - 1);
return this.history[this.currentIndex]; return this.history[this.currentIndex];
} }