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: bug when the name of subcategory is empty #263

Merged

Conversation

dixidroid
Copy link
Contributor

fixed a bug when the name of subcategory was empty in Discussions

@dixidroid dixidroid linked an issue Mar 18, 2024 that may be closed by this pull request
@dixidroid dixidroid force-pushed the fix/empty_name_of_subcategory branch from 2e3a962 to f03e289 Compare March 18, 2024 16:26
Copy link
Contributor

@HamzaIsrar12 HamzaIsrar12 left a comment

Choose a reason for hiding this comment

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

I've asked Moiz to confirm the default string for us. Meanwhile, I believe it would be wise to minimize the usage of topic.name to zero, as it could potentially cause issues in other areas as well.

Regarding an alternative approach, using something like this codesnippet to fetch the topic title from one common place seems like a good idea. Thoughts?

@dixidroid dixidroid force-pushed the fix/empty_name_of_subcategory branch from f03e289 to bfd0507 Compare March 19, 2024 13:34
@dixidroid
Copy link
Contributor Author

@HamzaIsrar12 I changed where the topic name located. Check it please. Waiting for Moiz's confirmation...

Comment on lines 20 to 23
fun getTopicName(): String {
return name.ifEmpty { stringResource(id = R.string.discussion_unnamed_subcategory) }
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Not sure if the UI layer code can be stored in the domain model.
Is there any possibility to move it to the UI layer?

Copy link
Contributor

Choose a reason for hiding this comment

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

Continuing your thought process, @volodymyr-chekyrta, perhaps we can update it at the repository level.

    suspend fun getCourseTopics(courseId: String): List<Topic> {
        val topicsData = api.getCourseTopics(courseId).mapToDomain()

        // Fetch default name
        val defaultTopicName = resourceManager.getString(R.string.discussion_unnamed_subcategory)

        currentCourseId = courseId
        topics.clear()
        topics.addAll(topicsData.nonCoursewareTopics)
        topicsData.coursewareTopics.forEach {
            topics.add(it)
            if (it.children.isNotEmpty()) {
                topics.addAll(it.children)
            }
        }
        
        // New Code
        topics.forEachIndexed { index, topic ->
            if (topic.name.isBlank()) {
                topics[index] = topic.copy(name = defaultTopicName)
            }
        }
        // End
        
        return topics.toList()
    }

Thoughts?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

@HamzaIsrar12
Copy link
Contributor

@dixidroid Moiz has approved the usage of "Unnamed subcategory". 👍🏻

@dixidroid dixidroid force-pushed the fix/empty_name_of_subcategory branch from bfd0507 to b72f65b Compare March 22, 2024 11:06
@volodymyr-chekyrta volodymyr-chekyrta merged commit f49283d into openedx:develop Mar 25, 2024
3 checks passed
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.

[Android] Empty name of subcategory displays in Discussions
3 participants