Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix padding and add admin control for member location sharing #157

Open
wants to merge 6 commits into
base: main
Choose a base branch
from

Conversation

cp-sneh-s
Copy link
Collaborator

@cp-sneh-s cp-sneh-s commented Jan 8, 2025

Changelog

  • Adjust padding for inviteCode text
  • Added admin control for change location setting of member
  • Remove save button functinality from topbar

New Features

  • Added functionality for admin to change group member's location sharing functionality
Screen_recording_20250108_113037.mp4

Summary by CodeRabbit

  • New Features

    • Enhanced space profile screen with more interactive UI components.
    • Added new location management features for space members.
    • Introduced more granular loading states for invite code and location settings.
  • Bug Fixes

    • Improved user interaction feedback mechanisms.
    • Refined state management for location and space profile updates.
  • UI/UX Improvements

    • Replaced text field with a more customizable input component.
    • Added progress indicators and refresh icons.
    • Simplified toolbar and navigation interactions.
    • Improved layout for better visual hierarchy and spacing.

Copy link

coderabbitai bot commented Jan 8, 2025

Walkthrough

This pull request introduces modifications to the SpaceProfileScreen.kt and SpaceProfileViewModel.kt files, focusing on enhancing the user interface and refining state management. Key changes include replacing the UserTextField with Text and BasicTextField, simplifying the toolbar by removing the save button, and adding visual feedback elements like a CircularProgressIndicator. The view model's logic for managing location settings and loading states has been updated, including the introduction of new properties in the SpaceProfileState. The associated test file has also been adjusted to reflect these changes.

Changes

File Change Summary
app/src/main/java/com/canopas/yourspace/ui/flow/settings/space/SpaceProfileScreen.kt - Replaced UserTextField with Text and BasicTextField
- Simplified toolbar by removing save text button
- Added conditional checkmark icon for saving changes
- Introduced CircularProgressIndicator for loading states
- Improved layout spacing and alignment
- Updated method signatures for several functions
app/src/main/java/com/canopas/yourspace/ui/flow/settings/space/SpaceProfileViewModel.kt - Added updateMemberLocation method
- Updated onLocationEnabledChanged to use coroutines
- Modified regenerateInviteCode to use isCodeLoading
- Expanded SpaceProfileState with new properties for location and code management
app/src/test/java/com/canopas/yourspace/ui/flow/settings/space/SpaceProfileViewModelTest.kt - Removed allowSave assertion in onLocationEnabledChanged test
- Eliminated saveSpace invocation in location enabled test
- Removed navigation verification after saving

Possibly related PRs

Suggested reviewers

  • cp-megh-l
  • cp-radhika-s

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

‼️ IMPORTANT
Auto-reply has been disabled for this repository in the CodeRabbit settings. The CodeRabbit bot will not respond to your replies unless it is explicitly tagged.

  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR. (Beta)
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary or Summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 3

🧹 Nitpick comments (2)
app/src/main/java/com/canopas/yourspace/ui/flow/settings/space/SpaceProfileViewModel.kt (1)

95-109: Add loading state for member location updates

While the error handling is good, the function should manage loading state to provide better user feedback during the async operation.

Consider this enhancement:

 fun updateMemberLocation(memberId: String, enableLocation: Boolean) {
     viewModelScope.launch(appDispatcher.IO) {
         try {
+            _state.emit(_state.value.copy(userLocationUpdatingId = memberId))
             spaceRepository.enableLocation(spaceID, memberId, enableLocation)
             val spaceInfo = spaceRepository.getSpaceInfo(spaceID)
             _state.emit(
                 _state.value.copy(
                     spaceInfo = spaceInfo,
-                    locationEnabledChanges = mapOf(memberId to enableLocation)
+                    locationEnabledChanges = mapOf(memberId to enableLocation),
+                    userLocationUpdatingId = null
                 )
             )
         } catch (e: Exception) {
             Timber.e(e, "Failed to update member location")
+            _state.emit(_state.value.copy(
+                error = e,
+                userLocationUpdatingId = null
+            ))
         }
     }
 }
app/src/main/java/com/canopas/yourspace/ui/flow/settings/space/SpaceProfileScreen.kt (1)

549-551: Consider adding haptic feedback for better user experience.

The switch implementation could benefit from haptic feedback when toggling location settings.

 onCheckedChange = { isChecked ->
+    HapticFeedback.performHapticFeedback(HapticFeedbackType.TextHandleMove)
     onCheckedChange(isChecked)
 },
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between cd11194 and e1f09e8.

📒 Files selected for processing (3)
  • app/src/main/java/com/canopas/yourspace/ui/flow/settings/space/SpaceProfileScreen.kt (7 hunks)
  • app/src/main/java/com/canopas/yourspace/ui/flow/settings/space/SpaceProfileViewModel.kt (4 hunks)
  • app/src/test/java/com/canopas/yourspace/ui/flow/settings/space/SpaceProfileViewModelTest.kt (0 hunks)
💤 Files with no reviewable changes (1)
  • app/src/test/java/com/canopas/yourspace/ui/flow/settings/space/SpaceProfileViewModelTest.kt
🔇 Additional comments (8)
app/src/main/java/com/canopas/yourspace/ui/flow/settings/space/SpaceProfileViewModel.kt (3)

183-187: LGTM! Good state management after save operation

The implementation properly refreshes space info and resets states after saving.


327-331: LGTM! Well-structured state properties

The new state properties provide good separation of concerns and proper type safety.


82-82: Verify decoupling of location changes from save state

The save state now only considers space name changes, ignoring location changes. While this aligns with separating location management, ensure this is intentional and won't prevent necessary location updates from being saved.

✅ Verification successful

Location changes are correctly decoupled from save state

The codebase shows that location updates are intentionally handled through dedicated methods (enableLocation, updateMemberLocation) and don't need to be part of the general save operation. This separation is well-tested and maintains consistency across both user and admin-initiated location changes.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for other location-related save operations
rg -A 5 "enableLocation|locationEnabled.*save" 

Length of output: 13867

app/src/main/java/com/canopas/yourspace/ui/flow/settings/space/SpaceProfileScreen.kt (5)

237-242: LGTM! Clean focus management implementation.

The focus management implementation using LocalFocusManager and MutableInteractionSource follows Compose best practices.


250-296: Well-structured text field implementation with proper visual feedback.

The BasicTextField implementation with dynamic outline color, keyboard actions, and cursor styling provides a better user experience. The check icon for saving is more intuitive than a top bar button.


Line range hint 350-363: LGTM! Clear implementation of user's location control.

The implementation properly handles the current user's location sharing preferences with appropriate admin checks.


318-326: LGTM! Clear visual feedback for admin actions.

The implementation properly shows loading state during invite code regeneration.


305-305: LGTM! Improved visual hierarchy with consistent padding.

The padding adjustments for the invite code text and dividers create a better visual hierarchy.

Also applies to: 338-338, 344-344

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

🧹 Nitpick comments (1)
app/src/main/java/com/canopas/yourspace/ui/flow/settings/space/SpaceProfileViewModel.kt (1)

82-82: Consider renaming variables for clarity

In the onChange() function, both spaceName and _state.value.spaceName are used, which can be confusing. To enhance readability, consider renaming spaceName to currentSpaceName or originalSpaceName.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between e1f09e8 and 56e76aa.

📒 Files selected for processing (1)
  • app/src/main/java/com/canopas/yourspace/ui/flow/settings/space/SpaceProfileViewModel.kt (4 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: build
🔇 Additional comments (1)
app/src/main/java/com/canopas/yourspace/ui/flow/settings/space/SpaceProfileViewModel.kt (1)

133-140: Error handling for invite code regeneration is well-implemented

The regenerateInviteCode function now includes proper error handling and updates the loading state appropriately. This addresses previous concerns regarding error management in this function.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🧹 Nitpick comments (1)
app/src/main/java/com/canopas/yourspace/ui/flow/settings/space/SpaceProfileViewModel.kt (1)

336-340: Add documentation for new state properties

Consider adding KDoc comments to explain the purpose of the new state properties:

  • isCodeLoading: For invite code regeneration progress
  • locationEnabledChanges: For tracking member location setting changes
  • isLocationSettingChange: For current user's location setting change progress
  • userLocationUpdatingId: For tracking which member's location is being updated
 data class SpaceProfileState(
     // ... existing properties ...
+    /** Tracks the loading state during invite code regeneration */
     val isCodeLoading: Boolean = false,
+    /** Maps member IDs to their updated location sharing settings */
     val locationEnabledChanges: Map<String, Boolean> = emptyMap(),
+    /** Indicates if the current user's location setting is being updated */
     val isLocationSettingChange: Boolean = false,
+    /** ID of the member whose location setting is being updated */
     val userLocationUpdatingId: String? = null
 )
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 56e76aa and 803a006.

📒 Files selected for processing (1)
  • app/src/main/java/com/canopas/yourspace/ui/flow/settings/space/SpaceProfileViewModel.kt (4 hunks)
🔇 Additional comments (3)
app/src/main/java/com/canopas/yourspace/ui/flow/settings/space/SpaceProfileViewModel.kt (3)

134-141: LGTM! Good error handling and loading state management.

The implementation properly manages loading states and handles errors for invite code regeneration.


192-196: LGTM! Good state management after save operation.

The implementation properly updates the space info and handles the allowSave state in both success and error cases.


88-98: 🛠️ Refactor suggestion

Improve state management in onLocationEnabledChanged

The current implementation has potential issues:

  1. The state is updated before the API call, leading to UI inconsistency if the API fails.
  2. No loading state is managed during the operation.

Consider this implementation:

 viewModelScope.launch {
     try {
-        _state.value = state.value.copy(locationEnabled = enable)
+        _state.value = state.value.copy(isLocationSettingChange = true)
         spaceRepository.enableLocation(spaceID, authService.currentUser?.id ?: "", enable)
+        _state.value = state.value.copy(
+            locationEnabled = enable,
+            isLocationSettingChange = false
+        )
     } catch (e: Exception) {
         Timber.e(e, "Failed to update location")
-        _state.value = state.value.copy(error = e, locationEnabled = !enable)
+        _state.value = state.value.copy(
+            error = e,
+            isLocationSettingChange = false
+        )
     }
     onChange()
 }

Likely invalid or redundant comment.

@cp-megh-l cp-megh-l changed the title Fix padding and add admin control for member location sharing. Fix padding and add admin control for member location sharing Jan 9, 2025
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🧹 Nitpick comments (2)
app/src/main/java/com/canopas/yourspace/ui/flow/settings/space/SpaceProfileViewModel.kt (2)

141-148: Add validation and timeout handling in regenerateInviteCode

The function needs additional safeguards:

  1. No validation for spaceID
  2. No timeout handling for long-running operations

Consider this implementation:

 fun regenerateInviteCode() = viewModelScope.launch(appDispatcher.IO) {
+    if (spaceID.isBlank()) {
+        _state.emit(_state.value.copy(
+            error = IllegalArgumentException("Space ID cannot be empty")
+        ))
+        return@launch
+    }
     _state.emit(_state.value.copy(isCodeLoading = true))
     try {
+        withTimeout(TimeUnit.SECONDS.toMillis(30)) {
             spaceRepository.regenerateInviteCode(spaceRepository.currentSpaceId)
             fetchInviteCode(spaceID)
+        }
         _state.emit(_state.value.copy(isCodeLoading = false))
     } catch (e: Exception) {
         Timber.e(e, "Failed to regenerate invite code")
         _state.emit(_state.value.copy(isCodeLoading = false, error = e))
     }
 }

343-347: Improve property naming and add documentation

Consider:

  1. Rename isLocationSettingChange to isLocationSettingUpdating for clarity
  2. Add KDoc comments to explain the purpose of each property

Consider this implementation:

 data class SpaceProfileState(
     // ... other properties ...
+    /** Time remaining until the invite code expires */
     val codeExpireTime: String = "",
+    /** Loading state for invite code regeneration */
     val isCodeLoading: Boolean = false,
+    /** Map of member IDs to their updated location sharing status */
     val locationEnabledChanges: Map<String, Boolean> = emptyMap(),
-    val isLocationSettingChange: Boolean = false,
+    /** Indicates if a location setting update is in progress */
+    val isLocationSettingUpdating: Boolean = false,
+    /** ID of the member whose location sharing status is being updated */
     val userLocationUpdatingId: String? = null
 )
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 803a006 and 944cb97.

📒 Files selected for processing (1)
  • app/src/main/java/com/canopas/yourspace/ui/flow/settings/space/SpaceProfileViewModel.kt (4 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: build
🔇 Additional comments (2)
app/src/main/java/com/canopas/yourspace/ui/flow/settings/space/SpaceProfileViewModel.kt (2)

199-203: LGTM! Good error handling and state management

The implementation properly updates the space info after save operation and handles errors appropriately.


88-98: 🛠️ Refactor suggestion

Improve state management in onLocationEnabledChanged

The current implementation has potential state inconsistency issues:

  1. State is updated before the API call completes
  2. Loading state is not managed
  3. isLocationSettingChange is not handled in error case

Consider this implementation:

 viewModelScope.launch {
     try {
+        _state.value = state.value.copy(isLocationSettingChange = true)
         spaceRepository.enableLocation(spaceID, authService.currentUser?.id ?: "", enable)
-        _state.value = state.value.copy(locationEnabled = enable)
+        _state.value = state.value.copy(
+            locationEnabled = enable,
+            isLocationSettingChange = false
+        )
     } catch (e: Exception) {
         Timber.e(e, "Failed to update location")
-        _state.value = state.value.copy(error = e, locationEnabled = !enable)
+        _state.value = state.value.copy(
+            error = e,
+            isLocationSettingChange = false
+        )
     }
     onChange()
 }

Likely invalid or redundant comment.

@cp-megh-l
Copy link
Collaborator

Also, the click ripple for save/check button in edit-name field needs to be updated

@cp-megh-l
Copy link
Collaborator

There should be a loader(in place of check mark), when there is api call to update group name

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🧹 Nitpick comments (2)
app/src/main/java/com/canopas/yourspace/ui/flow/settings/space/SpaceProfileScreen.kt (2)

287-291: Improve click handling for better accessibility

The click handling on the check icon should be implemented using IconButton for better accessibility and consistent ripple effect.

-                                .clickable {
-                                    ripple(true)
-                                    viewModel.saveSpace()
-                                    focusManager.clearFocus()
-                                }
+                            modifier = Modifier.padding(horizontal = 8.dp)
+                        }
+                        IconButton(
+                            onClick = {
+                                viewModel.saveSpace()
+                                focusManager.clearFocus()
+                            }
+                        ) {
+                            Icon(
+                                imageVector = Icons.Default.Check,
+                                contentDescription = stringResource(R.string.save_changes),
+                                tint = outlineColor
+                            )

389-396: Add content description for location toggle

The Switch component should have a meaningful content description for better accessibility.

     Switch(
         checked = isChecked,
         enabled = enable,
+        modifier = Modifier
+            .padding(end = 8.dp)
+            .semantics {
+                contentDescription = stringResource(
+                    if (isChecked) R.string.location_sharing_enabled
+                    else R.string.location_sharing_disabled,
+                    userInfo.user.fullName
+                )
+            },
         onCheckedChange = { isChecked ->
             onCheckedChange(isChecked)
         },
-        modifier = Modifier.padding(end = 8.dp)
     )
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 944cb97 and 597da56.

📒 Files selected for processing (2)
  • app/src/main/java/com/canopas/yourspace/ui/flow/settings/space/SpaceProfileScreen.kt (6 hunks)
  • app/src/main/java/com/canopas/yourspace/ui/flow/settings/space/SpaceProfileViewModel.kt (5 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • app/src/main/java/com/canopas/yourspace/ui/flow/settings/space/SpaceProfileViewModel.kt
🔇 Additional comments (2)
app/src/main/java/com/canopas/yourspace/ui/flow/settings/space/SpaceProfileScreen.kt (2)

364-366: Verify error handling for location updates

Based on previous review comments, ensure proper error handling is implemented in the ViewModel for failed location updates.

#!/bin/bash
# Search for error handling in location update implementations
rg "onLocationEnabledChanged|updateMemberLocation" -A 10 "app/src/main/java/com/canopas/yourspace/ui/flow/settings/space/SpaceProfileViewModel.kt"

310-310: LGTM! Padding improvements

The padding adjustments improve the visual layout and maintain consistency throughout the screen.

Also applies to: 315-315, 343-343, 349-349

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants