OverviewFilesCommitsIssuesDocsReleasesPeers

keet-deobfuscated / @holepunchto / keet-store / store / chat / file / chat-file.selector.js

28 lines · javascript ref:
import { createSelector as e } from "@reduxjs/toolkit"
import { CHAT_STATE_KEY as t } from "../chat.constant"
import { CHAT_FILE_UPLOAD_STATE_KEY as r } from "./chat-file.constant"
export const getChatFileUploadState = (e) => e[t][r]
export const getChatPendingFileTempIds = (e) => getChatFileUploadState(e).tempIds
export const getChatPendingFile = (e, t) => getChatFileUploadState(e).byTempId[t]
export const getChatPendingFileProgressByTempId = (e) => getChatFileUploadState(e).progressByTempId
export const getChatPendingFileProgress = (e, t) =>
  getChatPendingFileProgressByTempId(e)[t]?.progress || 0
export const getChatPendingFileProgressTotal = e(getChatPendingFileProgressByTempId, (e) => {
  const t = Object.values(e)
  return t.length ? t.reduce((e, { progress: t }) => e + t, 0) / t.length : 0
})
export const getChatPendingFileErrorByTempId = (e) => getChatFileUploadState(e).errorByTempId
export const getChatPendingFileErrorsCount = e(
  getChatPendingFileErrorByTempId,
  (e) => Object.keys(e).length,
)
export const getChatPendingFileRemaining = e(getChatPendingFileProgressByTempId, (e) =>
  Object.keys(e).reduce((t, r) => {
    const { completed: o } = e[r]
    return o ? t : t + 1
  }, 0),
)
export const getChatPendingFileIsParsing = (e) => getChatFileUploadState(e).isUploadingFileParsing
export const getChatPendingFileError = (e, t) => getChatFileUploadState(e).errorByTempId[t] || !1
export const getChatPendingFileResultByTempId = (e) => getChatFileUploadState(e).resultByTempId