From 1a5b8ec82359d64c65dee96b9941d5419d1d00bb Mon Sep 17 00:00:00 2001 From: nain93 Date: Tue, 1 Aug 2023 03:20:43 +0900 Subject: [PATCH] =?UTF-8?q?feat:=20=EC=BB=A8=ED=85=90=EC=B8=A0=20=EC=83=81?= =?UTF-8?q?=EC=84=B8=20api?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/repositories/content_repository.dart | 36 +++- lib/screens/home/content_view.dart | 174 ++++++++++-------- lib/screens/home/folder_detail_view.dart | 37 +--- lib/screens/home/hashtag_detail_view.dart | 1 + lib/screens/setting/edit_my_type_view.dart | 1 + lib/utils/router_provider.dart | 4 +- .../moa_widgets/dynamic_grid_list.dart | 109 ++--------- 7 files changed, 152 insertions(+), 210 deletions(-) diff --git a/lib/repositories/content_repository.dart b/lib/repositories/content_repository.dart index 9be008e..9022a1e 100644 --- a/lib/repositories/content_repository.dart +++ b/lib/repositories/content_repository.dart @@ -11,6 +11,10 @@ abstract class IContentRepository { required ContentModel content, required String hashTagStringList, }); + + Future getContentDetail({ + required String contentId, + }); } class ContentRepository implements IContentRepository { @@ -25,7 +29,7 @@ class ContentRepository implements IContentRepository { }) async { var token = await TokenRepository.instance.getToken(); - if (contentType.name == AddContentType.image.name) { + if (contentType == AddContentType.image) { /// 이미지 방식 await dio.post( '/api/v1/content/create', @@ -46,7 +50,7 @@ class ContentRepository implements IContentRepository { ); } - if (contentType.name == AddContentType.url.name) { + if (contentType == AddContentType.url) { /// 링크 방식 await dio.post( '/api/v1/content/create', @@ -57,8 +61,8 @@ class ContentRepository implements IContentRepository { 'hashTag': hashTagStringList, 'contentType': 'URL', 'url': content.contentUrl, - // 'originalFileName': '${content.contentName}.png', - // 'image': 'image/png:base64:${content.contentImageUrl}', + 'originalFileName': '${content.contentName}.png', + 'image': 'image/png:base64:${content.contentImageUrl}', }, options: Options( headers: { @@ -68,4 +72,28 @@ class ContentRepository implements IContentRepository { ); } } + + @override + Future getContentDetail({required String contentId}) async { + var token = await TokenRepository.instance.getToken(); + + var res = await dio.get( + '/api/v1/content/detail/view?contentId=$contentId', + options: Options( + headers: { + 'Authorization': 'Bearer $token', + }, + ), + ); + + /// 백엔드 ContentModel 타입이 통일되지 않았으므로 임시로 타입 변환해서 넣어줌 + return ContentModel.fromJson({ + 'contentId': '0', + 'contentImageUrl': res.data['data']['thumbnail_image_url'], + 'contentUrl': res.data['data']['contentUrl'] ?? '', + 'contentMemo': res.data['data']['memo'], + 'contentName': res.data['data']['contentName'], + 'contentHashTag': res.data['data']['hashTags'], + }); + } } diff --git a/lib/screens/home/content_view.dart b/lib/screens/home/content_view.dart index 3585bf3..934d2c8 100644 --- a/lib/screens/home/content_view.dart +++ b/lib/screens/home/content_view.dart @@ -4,14 +4,21 @@ import 'package:go_router/go_router.dart'; import 'package:moa_app/constants/color_constants.dart'; import 'package:moa_app/constants/file_constants.dart'; import 'package:moa_app/constants/font_constants.dart'; +import 'package:moa_app/models/content_model.dart'; +import 'package:moa_app/repositories/content_repository.dart'; import 'package:moa_app/utils/general.dart'; import 'package:moa_app/widgets/app_bar.dart'; import 'package:moa_app/widgets/button.dart'; import 'package:moa_app/widgets/moa_widgets/bottom_modal_item.dart'; class ContentView extends HookWidget { - const ContentView({super.key, required this.id}); + const ContentView({ + super.key, + required this.id, + required this.folderName, + }); final String id; + final String folderName; @override Widget build(BuildContext context) { @@ -69,83 +76,104 @@ class ContentView extends HookWidget { child: Padding( padding: const EdgeInsets.only( left: 15, right: 15, bottom: kBottomNavigationBarHeight), - child: Column( - crossAxisAlignment: CrossAxisAlignment.start, - children: [ - Row( - children: [ - Image( - image: Assets.smallFolder, - width: 42, - height: 42, - ), - const Text( - '요리/레시피', - style: H2TextStyle(), - ), - ], - ), - Wrap( - children: [ - Container( - margin: const EdgeInsets.only(top: 30, bottom: 40), - padding: - const EdgeInsets.symmetric(horizontal: 20, vertical: 8), - decoration: BoxDecoration( - borderRadius: BorderRadius.circular(50), - color: AppColors.primaryColor, + child: FutureBuilder( + future: ContentRepository.instance.getContentDetail(contentId: id), + builder: (context, snapshot) { + var content = snapshot.data; + + if (snapshot.hasData && content != null) { + return Column( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + Row( + children: [ + Image( + image: Assets.smallFolder, + width: 42, + height: 42, + ), + Text( + folderName, + style: const H2TextStyle(), + ), + ], + ), + Wrap( + spacing: 10, + runSpacing: 10, + children: [ + ...content.contentHashTag.map( + (e) => Container( + margin: const EdgeInsets.only(top: 30, bottom: 40), + padding: const EdgeInsets.symmetric( + horizontal: 20, vertical: 8), + decoration: BoxDecoration( + borderRadius: BorderRadius.circular(50), + color: AppColors.primaryColor, + ), + child: Text( + '#${e.hashTag}', + style: const TextStyle( + color: AppColors.whiteColor, + fontSize: 16, + fontWeight: FontWeight.w600, + fontFamily: FontConstants.pretendard, + ), + ), + ), + ), + ], ), - child: const Text( - '#자취레시피', - style: TextStyle( - color: AppColors.whiteColor, - fontSize: 16, - fontWeight: FontWeight.w600, - fontFamily: FontConstants.pretendard, + Container( + height: 225, + decoration: BoxDecoration( + borderRadius: BorderRadius.circular(10), + border: Border.all( + color: AppColors.grayBackground, + width: 1, + ), + image: DecorationImage( + image: NetworkImage(content.contentImageUrl), + fit: BoxFit.contain, + ), ), ), - ), - ], - ), - Container( - height: 225, - decoration: BoxDecoration( - borderRadius: BorderRadius.circular(10), - color: AppColors.primaryColor, - ), - ), - const SizedBox(height: 10), - const Text( - '1인가구 제철채소 레시피', - style: H2TextStyle(), - ), - const SizedBox(height: 30), - Text( - '요즘 유행인 다이어트 간식 #그릭요거트바크 만들기! 너무 초간단해보여서 저도 요가 후 후다닥 만들어보았는데~만들고 보니 아쉬웠던 점들도 있어서잇님들은 저처럼 시행착오 없이 바로 완벽 성공하길 바라며!', - style: const Hash1TextStyle().merge( - const TextStyle(height: 1.4), - ), - ), - const SizedBox(height: 80), - Row( - children: [ - Expanded( - child: Button( - backgroundColor: AppColors.linkButton, - text: '링크 바로가기', - onPress: pressGoToLink, + const SizedBox(height: 10), + Text( + content.contentName, + style: const H2TextStyle(), + ), + const SizedBox(height: 30), + Text( + content.contentMemo ?? '', + style: const Hash1TextStyle().merge( + const TextStyle(height: 1.4), + ), ), - ), - const SizedBox(width: 15), - Expanded( - child: Button( - text: '확인', - onPress: pressConfirm, + const SizedBox(height: 80), + Row( + children: [ + Expanded( + child: Button( + backgroundColor: AppColors.linkButton, + text: '링크 바로가기', + onPress: pressGoToLink, + ), + ), + const SizedBox(width: 15), + Expanded( + child: Button( + text: '확인', + onPress: pressConfirm, + ), + ), + ], ), - ), - ], - ), - ], + ], + ); + } + return const SizedBox(); + }, ), ), ), diff --git a/lib/screens/home/folder_detail_view.dart b/lib/screens/home/folder_detail_view.dart index ed9e7ae..4d2ab78 100644 --- a/lib/screens/home/folder_detail_view.dart +++ b/lib/screens/home/folder_detail_view.dart @@ -36,42 +36,6 @@ class FolderDetailView extends HookWidget { ); } - // void showFolderDetailModal() { - // General.instance.showBottomSheet( - // context: context, - // padding: - // const EdgeInsets.only(left: 15, right: 15, top: 15, bottom: 30), - // height: 225, - // child: Column( - // children: [ - // BottomModalItem( - // icon: Assets.share, - // title: '공유하기', - // onPressed: () { - // // Todo url링크복사후 snackbar 알림 - // }, - // ), - // BottomModalItem( - // icon: Assets.pencil, - // title: '폴더명 수정', - // onPressed: () { - // context.pop(); - // showEditFolderModal(); - // }, - // ), - // BottomModalItem( - // icon: Assets.trash, - // title: '폴더 삭제', - // onPressed: () { - // context.pop(); - // showDeleteFolderModal(); - // }, - // ), - // ], - // ), - // ); - // } - return Scaffold( appBar: AppBarBack( isBottomBorderDisplayed: false, @@ -108,6 +72,7 @@ class FolderDetailView extends HookWidget { child: DynamicGridList( contentList: contentList, pullToRefresh: pullToRefresh, + folderName: folderName, ), ), ], diff --git a/lib/screens/home/hashtag_detail_view.dart b/lib/screens/home/hashtag_detail_view.dart index 7e1dd88..6ceebda 100644 --- a/lib/screens/home/hashtag_detail_view.dart +++ b/lib/screens/home/hashtag_detail_view.dart @@ -155,6 +155,7 @@ class HashtagDetailView extends HookWidget { child: DynamicGridList( contentList: const [], pullToRefresh: pullToRefresh, + folderName: 'folderName', )), ], ), diff --git a/lib/screens/setting/edit_my_type_view.dart b/lib/screens/setting/edit_my_type_view.dart index eae0a02..5817015 100644 --- a/lib/screens/setting/edit_my_type_view.dart +++ b/lib/screens/setting/edit_my_type_view.dart @@ -159,6 +159,7 @@ class EditMyTypeView extends HookWidget { child: DynamicGridList( contentList: const [], pullToRefresh: hashtagPullToRefresh, + folderName: 'folderName', ), ), ], diff --git a/lib/utils/router_provider.dart b/lib/utils/router_provider.dart index e822c07..d261bf8 100644 --- a/lib/utils/router_provider.dart +++ b/lib/utils/router_provider.dart @@ -203,11 +203,13 @@ final routeProvider = Provider( name: GoRoutes.content.name, path: '${GoRoutes.content.path}/:id', pageBuilder: (context, state) { + var contentView = state.extra as ContentView; return buildIosPageTransitions( context: context, state: state, child: ContentView( - id: state.pathParameters['id']!, + id: contentView.id, + folderName: contentView.folderName, ), ); }, diff --git a/lib/widgets/moa_widgets/dynamic_grid_list.dart b/lib/widgets/moa_widgets/dynamic_grid_list.dart index 481d8db..e91cd89 100644 --- a/lib/widgets/moa_widgets/dynamic_grid_list.dart +++ b/lib/widgets/moa_widgets/dynamic_grid_list.dart @@ -4,6 +4,7 @@ import 'package:flutter_staggered_grid_view/flutter_staggered_grid_view.dart'; import 'package:go_router/go_router.dart'; import 'package:moa_app/constants/app_constants.dart'; import 'package:moa_app/models/content_model.dart'; +import 'package:moa_app/screens/home/content_view.dart'; import 'package:moa_app/screens/home/widgets/hashtag_card.dart'; import 'package:moa_app/utils/router_provider.dart'; import 'package:moa_app/utils/utils.dart'; @@ -13,9 +14,11 @@ class DynamicGridList extends HookWidget { super.key, required this.contentList, required this.pullToRefresh, + required this.folderName, }); final List contentList; final Future Function() pullToRefresh; + final String folderName; @override Widget build(BuildContext context) { @@ -23,6 +26,7 @@ class DynamicGridList extends HookWidget { void goContentView(String contentId) { context.push( '${GoRoutes.content.fullPath}/$contentId', + extra: ContentView(id: contentId, folderName: folderName), ); } @@ -39,10 +43,11 @@ class DynamicGridList extends HookWidget { ...List.generate( contentList.length, (i) => FutureBuilder( - future: - getImageSize(imageURL: contentList[i].contentImageUrl), - builder: (context, snapshot) { - var rate = snapshot.data ?? 1.4; + future: getImageSize(imageURL: contentList[i].contentImageUrl), + builder: (context, snapshot) { + var rate = snapshot.data ?? 1.4; + + if (snapshot.hasData) { return StaggeredGridTile.count( crossAxisCellCount: 1, mainAxisCellCount: rate, @@ -59,99 +64,11 @@ class DynamicGridList extends HookWidget { ), ), ); - }), + } + return const SizedBox(); + }, + ), ) - - // StaggeredGridTile.count( - // crossAxisCellCount: 1, - // mainAxisCellCount: 1.4, - // child: ContentCard( - // onPressContent: () => goContentView('0'), - // onPressHashtag: (tag) {}, - // content: ContentModel( - // contentId: '1', - // imageUrl: 'https://picsum.photos/200/300', - // name: 'title', - // memo: 'description', - // hashTags: [ - // HashtagModel(tagId: '0', hashTag: '#자취레시피', count: 1), - // HashtagModel(tagId: '1', hashTag: '#꿀팁', count: 1), - // ], - // ), - // ), - // ), - // StaggeredGridTile.count( - // crossAxisCellCount: 1, - // mainAxisCellCount: 1.9, - // child: ContentCard( - // onPressContent: () => goContentView('1'), - // onPressHashtag: (tag) {}, - // content: ContentModel( - // contentId: '1', - // imageUrl: 'https://picsum.photos/200/300', - // name: 'title', - // memo: 'description', - // hashTags: [ - // HashtagModel(tagId: '0', hashTag: '#자취레시피', count: 1), - // HashtagModel(tagId: '1', hashTag: '#꿀팁', count: 1), - // ], - // ), - // ), - // ), - // StaggeredGridTile.count( - // crossAxisCellCount: 1, - // mainAxisCellCount: 1.9, - // child: ContentCard( - // onPressContent: () => goContentView('2'), - // onPressHashtag: (tag) {}, - // content: ContentModel( - // contentId: '1', - // imageUrl: 'https://picsum.photos/200/300', - // name: 'title', - // memo: 'description', - // hashTags: [ - // HashtagModel(tagId: '0', hashTag: '#자취레시피', count: 1), - // HashtagModel(tagId: '1', hashTag: '#꿀팁', count: 1), - // ], - // ), - // ), - // ), - // StaggeredGridTile.count( - // crossAxisCellCount: 1, - // mainAxisCellCount: 1, - // child: ContentCard( - // onPressContent: () => goContentView('3'), - // onPressHashtag: (tag) {}, - // content: ContentModel( - // contentId: '1', - // imageUrl: 'https://picsum.photos/200/300', - // name: 'title', - // memo: 'description', - // hashTags: [ - // HashtagModel(tagId: '0', hashTag: '#자취레시피', count: 1), - // HashtagModel(tagId: '1', hashTag: '#꿀팁', count: 1), - // ], - // ), - // ), - // ), - // StaggeredGridTile.count( - // crossAxisCellCount: 1, - // mainAxisCellCount: 1.4, - // child: ContentCard( - // onPressContent: () => goContentView('4'), - // onPressHashtag: (tag) {}, - // content: ContentModel( - // contentId: '1', - // imageUrl: 'https://picsum.photos/200/300', - // name: 'title', - // memo: 'description', - // hashTags: [ - // HashtagModel(tagId: '0', hashTag: '#자취레시피', count: 1), - // HashtagModel(tagId: '1', hashTag: '#꿀팁', count: 1), - // ], - // ), - // ), - // ), ], ), ),