R/update_state.R

Defines functions update_state

Documented in update_state

#' update_state
#' @export update_state
update_state <- function(input, user) {
  # browser()
  if (is.reactivevalues(input)) {
    input <- reactiveValuesToList(input)
  }
  # cli_alert_info('Storing state for {user}')

  # names_input <- names(input)
  # browser()
  # names_input <- names_input[rowSums(map_dfc(exclude_names, ~ str_detect(names_input, .))) == 0]
  # input <- map(input, function(inpt) {
  #   purrr::discard(inpt, ~ length(.) > 5)
  # })
  # browser()
  # input <- purrr::keep(input, ~ length(.) <= len)
  if (length(input)) {
    con <- connect_table()
    if (inherits(con, "try-error")) {
      cli_alert_danger("Failed to store state")
      return()
    }
    # browser()
    # state <- redisGet(user)
    # state <- update.list(state, input)
    # state$user_name <- user
    con <- mongo("user_history", "redpul", Sys.getenv("MONGO_URI"))
    con$insert(state)
    # print(toJSON(input, pretty = TRUE))
    redisSet(user, state)
    redisClose()
  }
}
fdrennan/test documentation built on April 23, 2022, 12:37 a.m.