Skip to content

Commit

Permalink
Updates
Browse files Browse the repository at this point in the history
  • Loading branch information
harana-bot committed Mar 3, 2024
1 parent 2b674a6 commit a022909
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 51 deletions.
16 changes: 9 additions & 7 deletions src/main/scala/com/harana/search/client/cards/CardPanel.scala
Original file line number Diff line number Diff line change
Expand Up @@ -19,25 +19,27 @@ import slinky.web.html._

val buttonClass = "relative inline-flex bg-white py-2 text-xs font-semibold text-gray-900 ring-1 ring-inset ring-gray-300 hover:bg-gray-50 focus:z-10"

when(searchState.selectedDocument.nonEmpty && searchState.selectedIntegration.nonEmpty)(
when(searchState.selectedDocument.nonEmpty && searchState.selectedIntegration.nonEmpty) {
val thumbnail = searchState.loadedThumbnails.get(searchState.selectedDocument.get.id)

span(className := "justify-center")(
div(className := "card-stack")(
div(className := "container")(
div(className := "cards")(
div(className := s"card card-middle ${if (state.middleCard.isEmpty) "card-hidden"}")(
Card(state.middleCard, searchState.selectedDocument.get, searchState.selectedIntegration.get, searchState.selectedThumbnail)
Card(state.middleCard, searchState.selectedDocument.get, searchState.selectedIntegration.get, thumbnail)
),
div(className := s"card card-horizontal-left ${if (state.horizontalLeftCard.isEmpty) "card-hidden"}", onClick := (_ => Circuit.dispatch(SelectHorizontalLeftCard)))(
Card(state.horizontalLeftCard, searchState.selectedDocument.get, searchState.selectedIntegration.get, searchState.selectedThumbnail)
Card(state.horizontalLeftCard, searchState.selectedDocument.get, searchState.selectedIntegration.get, thumbnail)
),
div(className := s"card card-horizontal-right ${if (state.horizontalRightCard.isEmpty) "card-hidden"}", onClick := (_ => Circuit.dispatch(SelectHorizontalRightCard)))(
Card(state.horizontalRightCard, searchState.selectedDocument.get, searchState.selectedIntegration.get, searchState.selectedThumbnail)
Card(state.horizontalRightCard, searchState.selectedDocument.get, searchState.selectedIntegration.get, thumbnail)
),
div(className := s"card card-vertical-top ${if (state.verticalTopCard.isEmpty) "card-hidden"}", onClick := (_ => Circuit.dispatch(SelectVerticalTopCard)))(
Card(state.verticalTopCard, searchState.selectedDocument.get, searchState.selectedIntegration.get, searchState.selectedThumbnail)
Card(state.verticalTopCard, searchState.selectedDocument.get, searchState.selectedIntegration.get, thumbnail)
),
div(className := s"card card-vertical-bottom ${if (state.verticalBottomCard.isEmpty) "card-hidden"}", onClick := (_ => Circuit.dispatch(SelectVerticalBottomCard)))(
Card(state.verticalBottomCard, searchState.selectedDocument.get, searchState.selectedIntegration.get, searchState.selectedThumbnail)
Card(state.verticalBottomCard, searchState.selectedDocument.get, searchState.selectedIntegration.get, thumbnail)
)
)
)
Expand All @@ -48,6 +50,6 @@ import slinky.web.html._
button(onClick := (_ => Circuit.dispatch(OpenParentFolder)), `type` := "button", className := s"-ml-px px-3 rounded-r-md $buttonClass")("Show Folder")
)
)
)
}
}
}
76 changes: 36 additions & 40 deletions src/main/scala/com/harana/search/client/search/SearchHandler.scala
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,11 @@ class SearchHandler extends ActionHandler(zoomTo(_.searchState)) {
effectOnly(
action(
ActionBatch(
UpdateSelectedIntegration(None),
UpdateSelectedDocument(None),
UpdateSearchApplication(None),
UpdateSearchResults(List.empty),
UpdateSearchTerm(None),
UpdateSearchResults(List.empty)
UpdateSelectedDocument(None),
UpdateSelectedIntegration(None)
)
)
)
Expand All @@ -62,21 +62,21 @@ class SearchHandler extends ActionHandler(zoomTo(_.searchState)) {
.toList
.sortBy(pair => Integrations.get(pair._1).title.toLowerCase)
UpdateSearchResults(results)
}}
}
}
) +
Effect(
Tauri.invoke("search_application", Map("query" -> term.get)).map { (result: js.UndefOr[RawApplication]) => {
UpdateSearchApplication(result.toOption.map(Application.apply))
}}
) +
action(
ActionBatch(
UpdateSelectedIntegration(None),
UpdateSelectedDocument(None),
//UpdateSearchApplication(None),
UpdateSearchTerm(term)
Effect(
Tauri.invoke("search_application", Map("query" -> term.get)).map { (result: js.UndefOr[RawApplication]) => {
UpdateSearchApplication(result.toOption.map(Application.apply))
}}
) +
action(
ActionBatch(
UpdateSearchTerm(term),
UpdateSelectedDocument(None),
UpdateSelectedIntegration(None)
)
)
)
)
}

Expand Down Expand Up @@ -165,34 +165,31 @@ class SearchHandler extends ActionHandler(zoomTo(_.searchState)) {
Effect(
Tauri.invoke[Unit]("emit_preview_message", Map("name" -> "preview_document_changed", "payload" -> doc.asJson.noSpaces)).map(_ => NoChange)
) +
Effect(
Tauri.invoke[String]("get_viewer", Map("path" -> doc.path.get)).map(viewer => UpdateAllowPreview(viewer != "Noop"))
) +
action(
ActionBatch(
LoadThumbnail(documentId),
UpdateCards(List(List("thumbnail"), List("file"))),
UpdateFocusedPanel(Panel.Document),
UpdateSelectedDocument(Some(documentId)),
if (scroll) ScrollToDocument(documentId) else NoChange
Effect(
Tauri.invoke[String]("get_viewer", Map("path" -> doc.path.get)).map(viewer => UpdateAllowPreview(viewer != "Noop"))
) +
action(
ActionBatch(
LoadThumbnail(documentId),
UpdateCards(List(List("thumbnail"), List("file"))),
UpdateFocusedPanel(Panel.Document),
UpdateSelectedDocument(Some(documentId)),
if (scroll) ScrollToDocument(documentId) else NoChange
)
)
)
} else
action(UpdateFocusedPanel(Panel.Document))
)

case LoadThumbnail(documentId) =>
effectOnly(
Effect(
(for {
exists <- Tauri.invoke[String]("has_thumbnail", Map("documentId" -> documentId))
url = s"${zoomTo(_.systemState).value.thumbnailsUrl}/$documentId.png"
action = UpdateSelectedThumbnail(if (exists.toBoolean) Some(url) else None)
} yield action).recover {
case e: Exception =>
e.printStackTrace()
NoChange
}
for {
exists <- Tauri.invoke[String]("has_thumbnail", Map("documentId" -> documentId))
url = s"${zoomTo(_.systemState).value.thumbnailsUrl}/$documentId.png"
thumbnails = value.loadedThumbnails + (documentId -> url)
action = if (exists.toBoolean) UpdateLoadedThumbnails(thumbnails) else NoChange
} yield action
)
)

Expand Down Expand Up @@ -237,8 +234,10 @@ class SearchHandler extends ActionHandler(zoomTo(_.searchState)) {
updated(value.copy(errorMessage = None, focusedPanel = panel))
}

case UpdateLoadedThumbnails(thumbnails) =>
updated(value.copy(loadedThumbnails = thumbnails))

case UpdateSearchApplication(application) =>
println("Updating search application to: " + application)
updated(value.copy(searchApplication = application))

case UpdateSearchResults(results) =>
Expand Down Expand Up @@ -271,8 +270,5 @@ class SearchHandler extends ActionHandler(zoomTo(_.searchState)) {
selectedDocument = Some(document(documentId.get))
)
)

case UpdateSelectedThumbnail(thumbnail) =>
updated(value.copy(selectedThumbnail = thumbnail))
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -55,5 +55,6 @@ class SearchScrollHandler extends ActionHandler(zoomTo(_.searchState)) {

case ScrollToLastIntegration =>
scrollToRef(SearchPanel.integrationsRef, value.searchResults.length - 1)

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,17 @@ object SearchStore {
integrations: List[Integration],
focusedPanel: Panel,
errorMessage: Option[String],
loadedThumbnails: Map[DocumentId, String],
searchApplication: Option[Application],
searchResults: List[(IntegrationId, List[Document])],
searchTerm: Option[String],
selectedCardHorizontal: Int,
selectedCardVertical: Int,
selectedIntegration: Option[IntegrationId],
selectedDocumentId: Option[DocumentId],
selectedDocument: Option[Document],
selectedThumbnail: Option[String])
selectedDocument: Option[Document])

val initialState = State(false, Integrations.list, Panel.Search, None, None, List(), None, 1, 1, None, None, None, None)
val initialState = State(false, Integrations.list, Panel.Search, None, Map(), None, List(), None, 1, 1, None, None, None)

case class KeyDown(key: Int, event: KeyboardEvent) extends DiodeAction
case class KeyUp(key: Int, event: KeyboardEvent) extends DiodeAction
Expand Down Expand Up @@ -69,12 +69,12 @@ object SearchStore {
case class UpdateErrorMessage(message: Option[String]) extends DiodeAction
case class UpdateIntegrations(integrations: List[Integration]) extends DiodeAction
case class UpdateFocusedPanel(panel: Panel) extends DiodeAction
case class UpdateLoadedThumbnails(thumbnails: Map[DocumentId, String]) extends DiodeAction
case class UpdateSelectedCardHorizontal(index: Int) extends DiodeAction
case class UpdateSelectedCardVertical(index: Int) extends DiodeAction
case class UpdateSearchApplication(application: Option[Application]) extends DiodeAction
case class UpdateSearchResults(results: List[(IntegrationId, List[Document])]) extends DiodeAction
case class UpdateSearchTerm(term: Option[SearchTerm]) extends DiodeAction
case class UpdateSelectedDocument(documentId: Option[DocumentId]) extends DiodeAction
case class UpdateSelectedIntegration(connector: Option[IntegrationId]) extends DiodeAction
case class UpdateSelectedThumbnail(thumbnail: Option[String]) extends DiodeAction
}

0 comments on commit a022909

Please sign in to comment.