Skip to content

Commit df7a7b5

Browse files
committed
fix(details): improve share functionality and localization
This commit enhances the repository sharing logic by adding error handling, localizing UI strings, and improving accessibility. - **fix(details)**: Added error handling to the share action in `DetailsViewModel` with logging and user feedback on failure. - **refactor(details)**: Localized "Link copied to clipboard" and share failure messages using string resources. - **ui(details)**: Added a content description to the share icon in `DetailsRoot` for better accessibility.
1 parent 8ffe343 commit df7a7b5

2 files changed

Lines changed: 11 additions & 3 deletions

File tree

feature/details/presentation/src/commonMain/kotlin/zed/rainxch/details/presentation/DetailsRoot.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -370,7 +370,7 @@ private fun DetailsTopbar(
370370
) {
371371
Icon(
372372
imageVector = Icons.Default.Share,
373-
contentDescription = null,
373+
contentDescription = stringResource(Res.string.share_repository),
374374
)
375375
}
376376
}

feature/details/presentation/src/commonMain/kotlin/zed/rainxch/details/presentation/DetailsViewModel.kt

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -452,10 +452,18 @@ class DetailsViewModel(
452452
DetailsAction.OnShareClick -> {
453453
viewModelScope.launch {
454454
_state.value.repository?.let { repo ->
455-
shareManager.shareText("https://github-store.org/app?repo=${repo.fullName}")
455+
runCatching {
456+
shareManager.shareText("https://github-store.org/app?repo=${repo.fullName}")
457+
}.onFailure { t ->
458+
logger.error("Failed to share link: ${t.message}")
459+
_events.send(
460+
DetailsEvent.OnMessage(getString(Res.string.failed_to_share_link))
461+
)
462+
return@launch
463+
}
456464

457465
if (platform != Platform.ANDROID) {
458-
_events.send(DetailsEvent.OnMessage("Link copied to clipboard"))
466+
_events.send(DetailsEvent.OnMessage(getString(Res.string.link_copied_to_clipboard)))
459467
}
460468
}
461469
}

0 commit comments

Comments
 (0)