1 import { cancelled, put, takeLatest } from 'redux-saga/effects';
3 import { parseItemRevision } from '@proton/pass/lib/items/item.parser';
4 import { getItemRevisions } from '@proton/pass/lib/items/item.requests';
5 import { itemHistoryFailure, itemHistoryIntent, itemHistorySuccess } from '@proton/pass/store/actions';
6 import type { ItemRevision, ItemRevisionListResponse } from '@proton/pass/types';
8 function* loadHistoryWorker({ payload, meta: { request } }: ReturnType<typeof itemHistoryIntent>): Generator {
9 const ctrl = new AbortController();
12 const result = (yield getItemRevisions(payload, ctrl.signal)) as ItemRevisionListResponse;
13 const { RevisionsData, LastToken, Total } = result;
14 const revisions = (yield Promise.all(
15 RevisionsData.map((revision) => parseItemRevision(payload.shareId, revision))
18 yield put(itemHistorySuccess(request.id, { revisions, next: LastToken, total: Total, since: payload.since }));
20 yield put(itemHistoryFailure(request.id, error));
22 if (yield cancelled()) ctrl.abort();
26 export default function* watcher() {
27 yield takeLatest(itemHistoryIntent.match, loadHistoryWorker);