From 0f5bfe6aecaf917d7c9710358ba1e41dc1242926 Mon Sep 17 00:00:00 2001 From: grtsinry43 Date: Thu, 9 Oct 2025 00:53:20 +0800 Subject: [PATCH] feat: Implement "Create Post" screen with image upload This commit introduces a new "Create Post" screen, enabling users to compose and publish posts with text and up to three images. The implementation includes a dedicated ViewModel, robust state management, and an asynchronous image upload flow. **Key Changes:** * **feat(Create Post Screen):** * Added `CreatePostScreen.kt`, a new Composable screen for creating posts. * The UI includes a text input field, selectors for "Section" and "Category," and an image picker/preview area. * Implemented `SelectionBottomSheet` as a reusable component for picking sections and categories from a modal bottom sheet. * The "Publish" button is dynamically enabled based on content validation and image upload status. * Error messages are displayed to the user via a snackbar-like component. * **feat(CreatePostViewModel):** * Created a new `CreatePostViewModel` to manage the logic and state (`CreatePostState`) of the creation process. * Fetches post categories on initialization. * Handles image selection and manages an asynchronous upload queue. Each selected image is immediately uploaded to the backend via `MediaRepository`. * The ViewModel tracks the upload progress for each image and updates the UI accordingly. * The `createPost` function validates all inputs, compiles the post data (including uploaded image UUIDs), and sends it to the repository. * **feat(Navigation):** * Added a `CreatePost` route to the navigation graph (`Screen.kt`). * Integrated the new screen into `App.kt` with custom horizontal slide transitions. * The publish button on the main screen's top bar now navigates to the `CreatePostScreen`. * Upon successful post creation, the user is navigated back to the main screen. * **refactor(PostDetailViewModel):** * Adjusted the `createComment` logic to correctly handle `parentCommentId`, sending `0L` instead of `null` when there is no parent comment. --- .idea/deploymentTargetSelector.xml | 2 +- .../main/java/com/qingshuige/tangyuan/App.kt | 56 +- .../qingshuige/tangyuan/navigation/Screen.kt | 2 + .../tangyuan/ui/screens/CreatePostScreen.kt | 645 ++++++++++++++++++ .../ui/screens/UserProfileUpdateScreen.kt | 2 + .../tangyuan/viewmodel/CreatePostViewModel.kt | 327 +++++++++ .../tangyuan/viewmodel/PostDetailViewModel.kt | 2 +- 7 files changed, 1033 insertions(+), 3 deletions(-) create mode 100644 app/src/main/java/com/qingshuige/tangyuan/ui/screens/CreatePostScreen.kt create mode 100644 app/src/main/java/com/qingshuige/tangyuan/ui/screens/UserProfileUpdateScreen.kt create mode 100644 app/src/main/java/com/qingshuige/tangyuan/viewmodel/CreatePostViewModel.kt diff --git a/.idea/deploymentTargetSelector.xml b/.idea/deploymentTargetSelector.xml index bf30898..dc6fe30 100644 --- a/.idea/deploymentTargetSelector.xml +++ b/.idea/deploymentTargetSelector.xml @@ -4,7 +4,7 @@