Skip to content

Commit

Permalink
feat: implement normal mode space search card
Browse files Browse the repository at this point in the history
  • Loading branch information
d1snin committed Aug 8, 2023
1 parent 19b0344 commit dbd99dc
Show file tree
Hide file tree
Showing 8 changed files with 76 additions and 16 deletions.
5 changes: 5 additions & 0 deletions beam-ui/src/jsMain/kotlin/dev/d1s/beam/ui/Module.kt
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ object Qualifier {
val VoidContentEntityRenderer = named("void-content-entity-renderer")
val TextContentEntityRenderer = named("text-content-entity-renderer")

val NormalSpaceSearchCardContent = named("normal-space-search-card-content")
val NotFoundSpaceSearchCardContent = named("not-found-space-search-card-content")
val EmptySpaceSearchCardContent = named("empty-space-search-card-content")
}
Expand Down Expand Up @@ -159,6 +160,10 @@ private fun Module.contentEntityRenderers() {
}

private fun Module.spaceSearchCardContents() {
singleOf<SpaceSearchCardContent>(::NormalSpaceSearchCardContent) {
qualifier = Qualifier.NormalSpaceSearchCardContent
}

singleOf<SpaceSearchCardContent>(::NotFoundSpaceSearchCardContent) {
qualifier = Qualifier.NotFoundSpaceSearchCardContent
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ class BlockComponent : Component<BlockComponent.Config>(::Config), KoinComponent
block ?: error("Block isn't set")

card("p-4 d-flex flex-column justify-content-start mb-4") {
width = sizeOf(block.size).px
maxWidth = sizeOf(block.size).px
renderEntities(block.entities)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
package dev.d1s.beam.ui.component

import dev.d1s.beam.commons.Block
import dev.d1s.beam.commons.Blocks
import dev.d1s.beam.ui.Qualifier
import dev.d1s.beam.ui.state.CurrentSpaceContentChange
import dev.d1s.beam.ui.state.Observable
Expand All @@ -35,12 +36,21 @@ class BlockContainerComponent : Component<Unit>(), KoinComponent {

private val currentSpaceContentChangeObservable by inject<Observable<CurrentSpaceContentChange>>(Qualifier.CurrentSpaceContentChangeObservable)

private val spaceSearchCardComponent by inject<Component<SpaceSearchCardComponent.Config>>(Qualifier.SpaceSearchCardComponent)

override fun SimplePanel.render() {
div(className = "container-fluid d-flex justify-content-center") {
vPanel(justify = JustifyContent.START).bind(
currentSpaceContentChangeObservable.state
) { change ->
change.blocks?.forEach { block ->
div().bind(currentSpaceContentChangeObservable.state) { change ->
change.blocks?.let { blocks ->
renderBlocks(blocks)
renderSpaceSearchCard()
}
}
}

private fun SimplePanel.renderBlocks(blocks: Blocks) {
div(className = "container-fluid d-flex justify-content-center mb-5") {
vPanel(justify = JustifyContent.START) {
blocks.forEach { block ->
renderBlock(block)
}
}
Expand All @@ -54,4 +64,10 @@ class BlockContainerComponent : Component<Unit>(), KoinComponent {
this.block.setState(block)
}
}

private fun SimplePanel.renderSpaceSearchCard() {
render(spaceSearchCardComponent) {
mode.value = SpaceSearchCardComponent.Mode.NORMAL
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,7 @@ package dev.d1s.beam.ui.component
import dev.d1s.beam.ui.theme.currentTheme
import dev.d1s.beam.ui.util.Texts
import io.kvision.html.image
import io.kvision.html.p
import io.kvision.panel.SimplePanel
import io.kvision.utils.rem
import org.koin.core.component.KoinComponent

class EmptySpaceSearchCardContent : SpaceSearchCardContent, KoinComponent {
Expand All @@ -37,8 +35,6 @@ class EmptySpaceSearchCardContent : SpaceSearchCardContent, KoinComponent {
}

override fun SimplePanel.text() {
p(Texts.Body.SpaceSearchCard.EmptySpaceMode.TEXT, className = "mb-3") {
fontSize = 1.6.rem
}
spaceSearchCardText(Texts.Body.SpaceSearchCard.EmptySpaceMode.TEXT)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/*
* Copyright 2023 Mikhail Titov
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package dev.d1s.beam.ui.component

import dev.d1s.beam.ui.util.Texts
import io.kvision.panel.SimplePanel
import org.koin.core.component.KoinComponent

class NormalSpaceSearchCardContent : SpaceSearchCardContent, KoinComponent {

override val mode = SpaceSearchCardComponent.Mode.NORMAL

override fun SimplePanel.image() {
// nop
}

override fun SimplePanel.text() {
spaceSearchCardText(Texts.Body.SpaceSearchCard.NormalMode.TEXT)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,7 @@ package dev.d1s.beam.ui.component
import dev.d1s.beam.ui.theme.currentTheme
import dev.d1s.beam.ui.util.Texts
import io.kvision.html.image
import io.kvision.html.p
import io.kvision.panel.SimplePanel
import io.kvision.utils.rem
import org.koin.core.component.KoinComponent

class NotFoundSpaceSearchCardContent : SpaceSearchCardContent, KoinComponent {
Expand All @@ -37,8 +35,6 @@ class NotFoundSpaceSearchCardContent : SpaceSearchCardContent, KoinComponent {
}

override fun SimplePanel.text() {
p(Texts.Body.SpaceSearchCard.NotFoundMode.TEXT, className = "mb-3") {
fontSize = 1.6.rem
}
spaceSearchCardText(Texts.Body.SpaceSearchCard.NotFoundMode.TEXT)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@

package dev.d1s.beam.ui.component

import io.kvision.html.p
import io.kvision.panel.SimplePanel
import io.kvision.utils.rem

interface SpaceSearchCardContent {

Expand All @@ -25,4 +27,10 @@ interface SpaceSearchCardContent {
fun SimplePanel.image()

fun SimplePanel.text()
}

fun SimplePanel.spaceSearchCardText(text: String) {
p(text, className = "mb-3") {
fontSize = 1.6.rem
}
}
5 changes: 5 additions & 0 deletions beam-ui/src/jsMain/kotlin/dev/d1s/beam/ui/util/Texts.kt
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,11 @@ object Texts {

const val GO_BUTTON_VALUE = "Go!"

object NormalMode {

const val TEXT = "Explore the other spaces on this instance."
}

object NotFoundMode {

const val ICON_ALT = "404 image"
Expand Down

0 comments on commit dbd99dc

Please sign in to comment.