Skip to content

Commit

Permalink
Merge pull request #74 from spine-examples/mark-all-as-read
Browse files Browse the repository at this point in the history
 Add the option to "Mark all mentions as read"
  • Loading branch information
MykytaPimonovTD authored Dec 13, 2024
2 parents e8c6d8a + 901f4d2 commit 9d908ea
Show file tree
Hide file tree
Showing 17 changed files with 434 additions and 50 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ import io.spine.examples.pingh.client.settings.isIgnored
import io.spine.examples.pingh.client.settings.value
import io.spine.examples.pingh.mentions.GitHubClientId
import io.spine.examples.pingh.mentions.MentionId
import io.spine.examples.pingh.mentions.MentionStatus
import io.spine.examples.pingh.mentions.MentionView
import io.spine.examples.pingh.mentions.UserMentions
import io.spine.examples.pingh.mentions.UserMentionsId
Expand Down Expand Up @@ -160,6 +161,16 @@ public class MentionsFlow internal constructor(
client.send(command)
}

/**
* Marks all unread and snoozed mentions as read.
*/
public fun markAllAsRead() {
ensureLoggedIn()
mentions.value
.filter { it.status != MentionStatus.READ }
.forEach { markAsRead(it.id) }
}

/**
* Marks the mention as pinned.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ package io.spine.internal.dependency

// https://github.com/spine-examples/Pingh
public object Pingh {
private const val version = "1.0.0-SNAPSHOT.33"
private const val version = "1.0.0-SNAPSHOT.34"
private const val group = "io.spine.examples.pingh"

public const val client: String = "$group:client:$version"
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -65,12 +65,42 @@ internal class AppState(serverEndpoint: ServerEndpoint) {
.build()
}

/**
* Actions that are performed when the application is [closed][close].
*/
internal val closureActions = mutableListOf<() -> Unit>()

init {
addClosureAction(app::close)
}

/**
* Switches the window visibility.
*/
internal fun toggleWindowVisibility() {
window.isShown = !window.isShown
}

/**
* Adds an action to be executed upon application closure,
* following the order in which actions were added.
*/
internal fun addClosureAction(onClose: () -> Unit) {
closureActions.add(onClose)
}

/**
* Closes the application.
*
* When the application is closed, all actions added
* using [addClosureAction()][addClosureAction] method are executed sequentially.
*
* By default, the client connection to
* the Pingh server is [closed][PinghApplication.close] first.
*/
internal fun close() {
closureActions.forEach { it() }
}
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@ public fun main() {
application {
Theme {
val state = remember { AppState(serverEndpoint) }
Window(state.window, state.app)
state.addClosureAction { exitApplication() }
Window(state)
Tray(state)
}
}
Expand Down
87 changes: 71 additions & 16 deletions desktop/src/main/kotlin/io/spine/examples/pingh/desktop/Mentions.kt
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,10 @@ import androidx.compose.foundation.layout.wrapContentSize
import androidx.compose.foundation.lazy.LazyColumn
import androidx.compose.foundation.lazy.LazyItemScope
import androidx.compose.foundation.shape.CircleShape
import androidx.compose.material.Divider
import androidx.compose.material3.Card
import androidx.compose.material3.CardDefaults.cardColors
import androidx.compose.material3.Icon
import androidx.compose.material3.IconButtonDefaults.iconButtonColors
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Text
Expand All @@ -77,10 +79,14 @@ import androidx.compose.ui.unit.IntOffset
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
import io.spine.example.pingh.desktop.generated.resources.Res
import io.spine.example.pingh.desktop.generated.resources.mark_all_as_read
import io.spine.example.pingh.desktop.generated.resources.more
import io.spine.example.pingh.desktop.generated.resources.pin
import io.spine.example.pingh.desktop.generated.resources.pingh
import io.spine.example.pingh.desktop.generated.resources.pinned
import io.spine.example.pingh.desktop.generated.resources.quit
import io.spine.example.pingh.desktop.generated.resources.refresh
import io.spine.example.pingh.desktop.generated.resources.settings
import io.spine.example.pingh.desktop.generated.resources.snooze
import io.spine.examples.pingh.client.MentionsFlow
import io.spine.examples.pingh.client.howMuchTimeHasPassed
Expand All @@ -98,17 +104,19 @@ import org.jetbrains.compose.resources.painterResource
*
* @param flow The flow for managing the lifecycle of mentions.
* @param toSettingsPage The navigation to the 'Settings' page.
* @param exitApp Closes applications and aborts any tasks it is performing.
*/
@Composable
internal fun MentionsPage(
flow: MentionsFlow,
toSettingsPage: () -> Unit
toSettingsPage: () -> Unit,
exitApp: () -> Unit
) {
Column(
Modifier.fillMaxSize()
.background(MaterialTheme.colorScheme.background)
) {
ToolBar(flow, toSettingsPage)
ToolBar(flow, toSettingsPage, exitApp)
Spacer(Modifier.height(0.5.dp))
MentionCards(flow)
}
Expand All @@ -120,13 +128,16 @@ internal fun MentionsPage(
*
* @param flow The flow for managing the lifecycle of mentions.
* @param toSettingsPage The navigation to the 'Settings' page.
* @param appIconFraction The proportion of the button's size that the app icon occupies.
* @param exitApp Closes applications and aborts any tasks it is performing.
* @param iconSizeFraction The proportion of the button's size
* occupied by the icon on the toolbar.
*/
@Composable
private fun ToolBar(
flow: MentionsFlow,
toSettingsPage: () -> Unit,
appIconFraction: Float = 0.8f
exitApp: () -> Unit,
iconSizeFraction: Float = 0.85f
) {
val contentColor = MaterialTheme.colorScheme.onSecondary
val borderColor = MaterialTheme.colorScheme.onBackground
Expand All @@ -143,19 +154,16 @@ private fun ToolBar(
strokeWidth = 1.dp.toPx()
)
}
.padding(start = 20.dp, end = 13.dp),
.padding(start = 25.dp, end = 15.dp),
verticalAlignment = CenterVertically
) {
IconButton(
icon = painterResource(Res.drawable.pingh),
onClick = toSettingsPage,
modifier = Modifier.size(50.dp).testTag("settings-button"),
colors = iconButtonColors(
contentColor = contentColor
),
sizeFraction = appIconFraction
Icon(
painter = painterResource(Res.drawable.pingh),
contentDescription = null,
modifier = Modifier.size(40.dp),
tint = contentColor
)
Spacer(Modifier.width(5.dp))
Spacer(Modifier.width(10.dp))
Text(
text = "Recent mentions",
modifier = Modifier.weight(1f),
Expand All @@ -168,10 +176,57 @@ private fun ToolBar(
onClick = {
flow.updateMentions()
},
modifier = Modifier.size(44.dp),
modifier = Modifier.size(30.dp),
colors = iconButtonColors(
contentColor = contentColor
)
),
tooltip = "Refresh",
sizeFraction = iconSizeFraction
)
Menu(
flow = flow,
toSettingsPage = toSettingsPage,
exitApp = exitApp
)
}
}

/**
* Displays the menu of the Mentions page.
*
* @param flow The flow for managing the lifecycle of mentions.
* @param toSettingsPage The navigation to the 'Settings' page.
* @param exitApp Closes applications and aborts any tasks it is performing.
*/
@Composable
private fun Menu(
flow: MentionsFlow,
toSettingsPage: () -> Unit,
exitApp: () -> Unit
) {
Menu(
icon = painterResource(Res.drawable.more),
modifier = Modifier.size(30.dp).testTag("menu-button"),
tooltip = "More"
) {
MenuItem(
text = "Mark all as read",
leadingIcon = painterResource(Res.drawable.mark_all_as_read),
modifier = Modifier.testTag("mark-all-as-read-button"),
onClick = flow::markAllAsRead
)
MenuItem(
text = "Settings",
leadingIcon = painterResource(Res.drawable.settings),
modifier = Modifier.testTag("settings-button"),
onClick = toSettingsPage
)
Divider(color = MaterialTheme.colorScheme.background)
MenuItem(
text = "Quit",
leadingIcon = painterResource(Res.drawable.quit),
modifier = Modifier.testTag("quit-button"),
onClick = exitApp
)
}
}
Expand Down
Loading

0 comments on commit 9d908ea

Please sign in to comment.