<commit_before>package com.karasiq.shadowcloud.webapp.components.folder

import scala.language.postfixOps
import scala.scalajs.concurrent.JSExecutionContext.Implicits.queue

import rx._
import rx.async._

import com.karasiq.bootstrap.Bootstrap.default._
import scalaTags.all._

import com.karasiq.common.memory.MemorySize
import com.karasiq.shadowcloud.model.File
import com.karasiq.shadowcloud.webapp.components.common.AppIcons
import com.karasiq.shadowcloud.webapp.components.file.FilePreview
import com.karasiq.shadowcloud.webapp.components.file.FilePreview.PreviewVariants
import com.karasiq.shadowcloud.webapp.context.{AppContext, FolderContext}
import com.karasiq.shadowcloud.webapp.utils.Blobs

object FileListItem {
  def apply(file: File, selectedFile: Var[Option[File]])(implicit context: AppContext, fc: FolderContext): FileListItem = {
    new FileListItem(file, selectedFile)
  }
}

class FileListItem(file: File, selectedFile: Var[Option[File]])(implicit context: AppContext, fc: FolderContext) extends BootstrapHtmlComponent {
  lazy val previews = {
    FilePreview.getPreviews(fc.regionId, file.id)
      .toRx(PreviewVariants.empty)
  }

  def renderTag(md: ModifierT*): TagT = {
    GridSystem.row(
      GridSystem.col(3).asDiv(
        Rx[Frag](previews().image match {
          case Some(thumbnail) ⇒
            val blob = Blobs.fromBytes(thumbnail.data.toArray)
            val imageUrl = Blobs.getUrl(blob)
            img(Bootstrap.image.responsive, Bootstrap.image.rounded, src := imageUrl)

          case None ⇒
            AppIcons.file
        }),
        textAlign.center,
        verticalAlign.middle,
        lineHeight := 50.px
      ),
      GridSystem.col(9).asDiv(
        GridSystem.row(
          GridSystem.col(9).asDiv(Rx[Frag](if (selectedFile().contains(file)) b(file.path.name) else file.path.name)),
          GridSystem.col(3).asDiv(
            GridSystem.mkRow(MemorySize.toString(file.checksum.size)),
            GridSystem.mkRow(context.timeFormat.timestamp(file.timestamp.lastModified)),
            color.gray,
            fontStyle.italic,
            fontSizeAdjust := 0.4,
            lineHeight := 80.pct
          )
        ),
        Rx[Frag](previews().text match {
          case Some(text) ⇒
            GridSystem.mkRow(
              if (text.format == "text/html") raw(text.data) else text.data,
              maxHeight := 5.em,
              color.gray,
              fontSizeAdjust := 0.4,
              lineHeight := 80.pct,<commit_msg>Fixes<commit_after>package com.karasiq.shadowcloud.webapp.components.folder

import scala.language.postfixOps
import scala.scalajs.concurrent.JSExecutionContext.Implicits.queue

import rx._
import rx.async._

import com.karasiq.bootstrap.Bootstrap.default._
import scalaTags.all._

import com.karasiq.common.memory.MemorySize
import com.karasiq.shadowcloud.model.File
import com.karasiq.shadowcloud.webapp.components.common.AppIcons
import com.karasiq.shadowcloud.webapp.components.file.FilePreview
import com.karasiq.shadowcloud.webapp.components.file.FilePreview.PreviewVariants
import com.karasiq.shadowcloud.webapp.context.{AppContext, FolderContext}
import com.karasiq.shadowcloud.webapp.utils.Blobs

object FileListItem {
  def apply(file: File, selectedFile: Var[Option[File]])(implicit context: AppContext, fc: FolderContext): FileListItem = {
    new FileListItem(file, selectedFile)
  }
}

class FileListItem(file: File, selectedFile: Var[Option[File]])(implicit context: AppContext, fc: FolderContext) extends BootstrapHtmlComponent {
  lazy val previews = {
    FilePreview.getPreviews(fc.regionId, file.id)
      .toRx(PreviewVariants.empty)
  }

  def renderTag(md: ModifierT*): TagT = {
    GridSystem.row(
      GridSystem.col(3).asDiv(
        Rx[Frag](previews().image match {
          case Some(thumbnail) ⇒
            val blob = Blobs.fromBytes(thumbnail.data.toArray)
            val imageUrl = Blobs.getUrl(blob)
            img(Bootstrap.image.responsive, Bootstrap.image.rounded, src := imageUrl)

          case None ⇒
            AppIcons.file
        }),
        textAlign.center,
        verticalAlign.middle,
        lineHeight := 50.px
      ),
      GridSystem.col(9).asDiv(
        GridSystem.row(
          GridSystem.col(9).asDiv(Rx[Frag](if (selectedFile().contains(file)) b(file.path.name) else span(file.path.name, cursor.pointer))),
          GridSystem.col(3).asDiv(
            GridSystem.mkRow(MemorySize.toString(file.checksum.size)),
            GridSystem.mkRow(context.timeFormat.timestamp(file.timestamp.lastModified)),
            color.gray,
            fontStyle.italic,
            fontSizeAdjust := 0.4,
            lineHeight := 80.pct
          )
        ),
        Rx[Frag](previews().text match {
          case Some(text) ⇒
            GridSystem.mkRow(
              if (text.format == "text/html") raw(text.data) else text.data,
              maxHeight := 5.em,
              color.gray,
              fontSizeAdjust := 0.4,
              lineHeight := 80.pct,
{'fraction_non_alphanumeric': 0.11301233585356148, 'fraction_numerical': 0.005968961400716275, 'mean_word_length': 2.881853281853282, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '835745', 'n_tokens_mistral': 1573, 'n_tokens_neox': 1548, 'n_words': 250}