From f25a18c62d9c5cbb77adcaa27d216ba16c0e8297 Mon Sep 17 00:00:00 2001 From: ZomSik Date: Fri, 17 May 2024 06:04:49 +0900 Subject: [PATCH 1/2] =?UTF-8?q?#59=20=EB=B0=B1=EC=97=94=EB=93=9C=20?= =?UTF-8?q?=EC=97=B0=EA=B2=B0=EC=A4=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- frontend/android/app/build.gradle | 1 - .../gradle/wrapper/gradle-wrapper.properties | 3 +- frontend/lib/http.dart | 7 +- frontend/lib/main.dart | 36 +-- .../bookreport/bookreport_viewing_screen.dart | 30 ++- .../bookreport/bookreport_writing_screen.dart | 25 +- .../group/in_group/voicecall/voice_class.dart | 6 +- .../home/mypage/makelibrary_screen.dart | 4 +- .../screens/home/mypage/mypage_screen.dart | 249 ++++++++++-------- .../screens/home/search/search_screen.dart | 23 +- 10 files changed, 205 insertions(+), 179 deletions(-) diff --git a/frontend/android/app/build.gradle b/frontend/android/app/build.gradle index 52fde3ce33..86f34be6dc 100644 --- a/frontend/android/app/build.gradle +++ b/frontend/android/app/build.gradle @@ -71,5 +71,4 @@ flutter { } dependencies { - implementation 'io.agora.rtc:voice-sdk:4.3.1' } diff --git a/frontend/android/gradle/wrapper/gradle-wrapper.properties b/frontend/android/gradle/wrapper/gradle-wrapper.properties index e1ca574ef0..37aef8d3f0 100644 --- a/frontend/android/gradle/wrapper/gradle-wrapper.properties +++ b/frontend/android/gradle/wrapper/gradle-wrapper.properties @@ -1,5 +1,6 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists +distributionUrl=https\://services.gradle.org/distributions/gradle-8.1.1-bin.zip +networkTimeout=10000 zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-7.6.3-all.zip diff --git a/frontend/lib/http.dart b/frontend/lib/http.dart index 4a2659d274..04d6278cce 100644 --- a/frontend/lib/http.dart +++ b/frontend/lib/http.dart @@ -1,8 +1,9 @@ +import 'dart:convert'; + +import 'package:frontend/secret.dart'; import 'package:http/http.dart' as http; import 'package:intl/intl.dart'; import 'package:xml2json/xml2json.dart'; -import 'package:frontend/secret.dart'; -import 'dart:convert'; const String NaverBookSearchURL = "https://openapi.naver.com/v1/search/book.json"; @@ -220,7 +221,7 @@ Future contentCreate( }, body: json.encode({ "addBookRequest": { - "isbn": "i-$isbn", + "isbn": isbn, "title": title2, "author": author, "publisher": publisher, diff --git a/frontend/lib/main.dart b/frontend/lib/main.dart index 00108d32af..dc92c9b8b0 100644 --- a/frontend/lib/main.dart +++ b/frontend/lib/main.dart @@ -1,31 +1,30 @@ import 'package:flutter/material.dart'; import 'package:frontend/provider/bookinfo_provider.dart'; import 'package:frontend/provider/secure_storage_provider.dart'; +import 'package:frontend/screens/book/book_info_screen.dart'; import 'package:frontend/screens/home/bookreport/bookreport_template_screen.dart'; import 'package:frontend/screens/home/bookreport/bookreport_viewing_screen.dart'; import 'package:frontend/screens/home/bookreport/bookreport_writing_screen.dart'; -import 'package:frontend/screens/home/mypage/login_screen.dart'; -import 'package:frontend/screens/home/mypage/makelibrary_screen.dart'; -import 'package:frontend/screens/home/mypage/mypage_screen.dart'; -import 'package:frontend/screens/home/mypage/signup_screen.dart'; -import 'package:go_router/go_router.dart'; -import 'package:provider/provider.dart'; - -import 'package:frontend/screens/home/home_screen.dart'; -import 'package:frontend/screens/home/search/search_screen.dart'; -import 'package:frontend/screens/home/shorts/shorts_screen.dart'; import 'package:frontend/screens/home/group/group_screen.dart'; import 'package:frontend/screens/home/group/in_group/group_info_screen.dart'; -import 'package:frontend/screens/home/group/make_group/group_make_screen.dart'; +import 'package:frontend/screens/home/group/in_group/groupbook_select_screen.dart'; import 'package:frontend/screens/home/group/in_group/post/homework_list_screen.dart'; +import 'package:frontend/screens/home/group/in_group/post/homework_memberlist_screen.dart'; +import 'package:frontend/screens/home/group/in_group/post/make_post/homework_make_screen.dart'; +import 'package:frontend/screens/home/group/in_group/post/make_post/post_make_screen.dart'; import 'package:frontend/screens/home/group/in_group/post/notice_list_screen.dart'; import 'package:frontend/screens/home/group/in_group/post/post_list_screen.dart'; import 'package:frontend/screens/home/group/in_group/post/post_screen.dart'; -import 'package:frontend/screens/book/book_info_screen.dart'; -import 'package:frontend/screens/home/group/in_group/groupbook_select_screen.dart'; -import 'package:frontend/screens/home/group/in_group/post/make_post/post_make_screen.dart'; -import 'package:frontend/screens/home/group/in_group/post/make_post/homework_make_screen.dart'; -import 'package:frontend/screens/home/group/in_group/post/homework_memberlist_screen.dart'; +import 'package:frontend/screens/home/group/make_group/group_make_screen.dart'; +import 'package:frontend/screens/home/home_screen.dart'; +import 'package:frontend/screens/home/mypage/login_screen.dart'; +import 'package:frontend/screens/home/mypage/makelibrary_screen.dart'; +import 'package:frontend/screens/home/mypage/mypage_screen.dart'; +import 'package:frontend/screens/home/mypage/signup_screen.dart'; +import 'package:frontend/screens/home/search/search_screen.dart'; +import 'package:frontend/screens/home/shorts/shorts_screen.dart'; +import 'package:go_router/go_router.dart'; +import 'package:provider/provider.dart'; void main() async { runApp(const App()); @@ -97,7 +96,10 @@ final GoRouter router = GoRouter( GoRoute( name: 'bookreport_viewing', path: '/bookreport_viewing', - builder: (context, state) => const BookReportViewingScreen(), + builder: (context, state) { + int id = state.extra as int; + return BookReportViewingScreen(id: id); + }, ), GoRoute( name: 'mypage', diff --git a/frontend/lib/screens/home/bookreport/bookreport_viewing_screen.dart b/frontend/lib/screens/home/bookreport/bookreport_viewing_screen.dart index ff0961b533..4c1691ccda 100644 --- a/frontend/lib/screens/home/bookreport/bookreport_viewing_screen.dart +++ b/frontend/lib/screens/home/bookreport/bookreport_viewing_screen.dart @@ -4,7 +4,9 @@ import 'package:frontend/provider/secure_storage_provider.dart'; import 'package:provider/provider.dart'; class BookReportViewingScreen extends StatefulWidget { - const BookReportViewingScreen({super.key}); + final int id; + + const BookReportViewingScreen({super.key, required this.id}); @override State createState() => _BookReportViewingState(); @@ -36,10 +38,12 @@ class _BookReportViewingState extends State { var token; void initializeContentData(dynamic token) async { - // _contentData = await contentLoad(token, 2); - // _template = _contentData[0]['type'] as String; - // _title = _contentData[0]['title'] as String; - // _body = _contentData[0]['body'] as String; + _contentData = await contentLoad(token, widget.id); + print(widget.id); + print(_contentData); + // _template = _contentData['type'] as String; + // _title = _contentData['title'] as String; + // _body = _contentData['body'] as String; } @override @@ -116,8 +120,12 @@ class _BookReportViewingState extends State { const SizedBox(height: 15), Padding( padding: const EdgeInsets.symmetric(horizontal: 20), - child: Expanded( - child: _buildTemplateUI(_template), + child: Row( + children: [ + Expanded( + child: _buildTemplateUI(_template), + ), + ], ), ), const SizedBox(height: 15), @@ -204,8 +212,12 @@ class _BookReportViewingState extends State { const SizedBox(height: 15), Padding( padding: const EdgeInsets.symmetric(horizontal: 0), - child: Expanded( - child: _buildQuizUI(_category), + child: Row( + children: [ + Expanded( + child: _buildQuizUI(_category), + ), + ], ), ), ], diff --git a/frontend/lib/screens/home/bookreport/bookreport_writing_screen.dart b/frontend/lib/screens/home/bookreport/bookreport_writing_screen.dart index d462fb48b5..880889909f 100644 --- a/frontend/lib/screens/home/bookreport/bookreport_writing_screen.dart +++ b/frontend/lib/screens/home/bookreport/bookreport_writing_screen.dart @@ -1,5 +1,4 @@ import 'package:flutter/material.dart'; -import 'package:flutter_screenutil/flutter_screenutil.dart'; import 'package:frontend/http.dart'; import 'package:frontend/provider/bookinfo_provider.dart'; import 'package:frontend/provider/secure_storage_provider.dart'; @@ -345,8 +344,12 @@ class _BookReportWritingState extends State { const SizedBox(height: 15), Padding( padding: const EdgeInsets.symmetric(horizontal: 20), - child: Expanded( - child: _buildTemplateUI(_template), + child: Row( + children: [ + Expanded( + child: _buildTemplateUI(_template), + ), + ], ), ), const SizedBox(height: 15), @@ -361,7 +364,6 @@ class _BookReportWritingState extends State { alignment: Alignment.bottomRight, child: ElevatedButton( onPressed: () { - // 글 저장 기능 추가 contentCreate( token, 0, @@ -422,25 +424,24 @@ class _BookReportWritingState extends State { decoration: const InputDecoration( hintText: '인용문을 작성해주세요', hintStyle: TextStyle( - // 힌트 텍스트 정중앙 정렬 height: 15, ), border: InputBorder.none, ), onChanged: (text) { - setState(() {}); // Rebuild widget when text changes + setState(() {}); }, ), ), const Positioned( left: 0, top: 0, - child: Icon(Icons.format_quote), // 좌측 상단 따옴표 아이콘 + child: Icon(Icons.format_quote), ), const Positioned( right: 0, bottom: 0, - child: Icon(Icons.format_quote), // 우측 하단 따옴표 아이콘 + child: Icon(Icons.format_quote), ), ], ), @@ -494,8 +495,12 @@ class _BookReportWritingState extends State { const SizedBox(height: 15), Padding( padding: const EdgeInsets.symmetric(horizontal: 0), - child: Expanded( - child: _buildQuizUI(selectedCategory!), + child: Row( + children: [ + Expanded( + child: _buildQuizUI(selectedCategory!), + ), + ], ), ), ], diff --git a/frontend/lib/screens/home/group/in_group/voicecall/voice_class.dart b/frontend/lib/screens/home/group/in_group/voicecall/voice_class.dart index 0ec29e05a6..814f323635 100644 --- a/frontend/lib/screens/home/group/in_group/voicecall/voice_class.dart +++ b/frontend/lib/screens/home/group/in_group/voicecall/voice_class.dart @@ -10,8 +10,6 @@ class AgoraApi { Future initAgora() async { _engine = createAgoraRtcEngine(); - await _engine.initialize(const RtcEngineContext( - appId: Agora_AppID - )); + await _engine.initialize(const RtcEngineContext(appId: Agora_AppID)); } -} \ No newline at end of file +} diff --git a/frontend/lib/screens/home/mypage/makelibrary_screen.dart b/frontend/lib/screens/home/mypage/makelibrary_screen.dart index 4141f28b32..1dc519f826 100644 --- a/frontend/lib/screens/home/mypage/makelibrary_screen.dart +++ b/frontend/lib/screens/home/mypage/makelibrary_screen.dart @@ -2,9 +2,9 @@ import 'package:flutter/material.dart'; import 'package:flutter_screenutil/flutter_screenutil.dart'; import 'package:frontend/http.dart'; import 'package:frontend/provider/secure_storage_provider.dart'; -import 'package:go_router/go_router.dart'; import 'package:frontend/screens/home/bookreport/booksearch_screen_util.dart' as searchutil; +import 'package:go_router/go_router.dart'; import 'package:provider/provider.dart'; class MakeLibraryScreen extends StatefulWidget { @@ -259,7 +259,7 @@ class _MakeLibraryScreenState extends State { addBooksToLibrary(token, _appBarTitle, _bookList); print(_appBarTitle); print(_bookList); - //context.pop(); + context.pop(); }, backgroundColor: const Color(0xFF0E9913), child: const Icon(Icons.save), diff --git a/frontend/lib/screens/home/mypage/mypage_screen.dart b/frontend/lib/screens/home/mypage/mypage_screen.dart index 67e1e07f2e..b953e0189d 100644 --- a/frontend/lib/screens/home/mypage/mypage_screen.dart +++ b/frontend/lib/screens/home/mypage/mypage_screen.dart @@ -1,18 +1,15 @@ import 'package:flutter/material.dart'; import 'package:flutter_screenutil/flutter_screenutil.dart'; -import 'package:flutter_secure_storage/flutter_secure_storage.dart'; import 'package:frontend/http.dart'; import 'package:frontend/provider/secure_storage_provider.dart'; -import 'package:frontend/screens/home/mypage/signup_screen.dart'; import 'package:go_router/go_router.dart'; -import 'package:provider/provider.dart'; import 'package:google_sign_in/google_sign_in.dart'; +import 'package:provider/provider.dart'; class MypageScreen extends StatefulWidget { const MypageScreen({super.key}); @override - // ignore: library_private_types_in_public_api _MypageScreenState createState() => _MypageScreenState(); } @@ -29,79 +26,35 @@ class LibraryBook { String publisher; String imageUrl; - LibraryBook( - {required this.title, - required this.author, - required this.publisher, - required this.imageUrl}); + LibraryBook({ + required this.title, + required this.author, + required this.publisher, + required this.imageUrl, + }); } class _MypageScreenState extends State with SingleTickerProviderStateMixin { late TabController _tabController; - var books = []; - - List libraries = [ - Library( - name: '즐겨찾기', - books: [ - LibraryBook( - title: '원씽', - author: 'Gary Keller, Jay Papasan', - publisher: 'Business Books', - imageUrl: 'https://via.placeholder.com/70x100', - ), - LibraryBook( - title: '원씽2', - author: 'Gary Keller, Jay Papasan', - publisher: 'Business Books', - imageUrl: 'https://via.placeholder.com/70x100', - ), - LibraryBook( - title: '원씽', - author: 'Gary Keller, Jay Papasan', - publisher: 'Business Books', - imageUrl: 'https://via.placeholder.com/70x100', - ), - LibraryBook( - title: '원씽2', - author: 'Gary Keller, Jay Papasan', - publisher: 'Business Books', - imageUrl: 'https://via.placeholder.com/70x100', - ), - ], - ), - Library( - name: '읽고 싶은 책', - books: [ - LibraryBook( - title: '원씽(The One Thing)', - author: 'Gary Keller, Jay Papasan', - publisher: 'Business Books', - imageUrl: 'https://via.placeholder.com/70x100', - ), - LibraryBook( - title: '원씽(The One Thing)2', - author: 'Gary Keller, Jay Papasan', - publisher: 'Business Books', - imageUrl: 'https://via.placeholder.com/70x100', - ), - ], - ), - ]; + List books = []; + List libraries = []; - var id; - var token; - var isLogin; - var userInfo; + String? id; + String? token; + String? name; + String? age; + String? gender; + bool isLogin = false; + dynamic userInfo; + int? userId; @override void initState() { super.initState(); - _initUserState(); _tabController = TabController(length: 2, vsync: this); - books.sort((a, b) => a.endDate.compareTo(b.endDate)); + _initUserState(); } Future _initUserState() async { @@ -109,15 +62,57 @@ class _MypageScreenState extends State Provider.of(context, listen: false); token = await secureStorage.readData("token"); id = await secureStorage.readData("id"); - print(token); + if (token == null) { - isLogin = false; + setState(() { + isLogin = false; + }); } else { - isLogin = true; - userInfo = await getUserInfo(id, token); - books = userInfo['contentList']; - print(books); + setState(() { + isLogin = true; + }); + userInfo = await getUserInfo(id!, token!); + setState(() { + name = userInfo['name']; + age = userInfo['age']?.toString() ?? '0'; + gender = userInfo['gender']; + books = userInfo['contentList']; + secureStorage.saveData('name', name!); + secureStorage.saveData('age', age!); + secureStorage.saveData('gender', gender!); + }); + await _fetchLibraries(token!); + } + } + + Future _fetchLibraries(String token) async { + final fetchedLibraries = await getLibrary(token); + setState(() { + libraries = parseLibraries(fetchedLibraries); + }); + } + + List parseLibraries(List libraryData) { + // Create a map of library names to Library objects + Map libraryMap = {}; + + for (var entry in libraryData) { + final groupName = entry['groupName']; + final book = LibraryBook( + title: entry['title'], + author: entry['author'], + publisher: entry['publisher'], + imageUrl: entry['imageUrl'], + ); + + if (libraryMap.containsKey(groupName)) { + libraryMap[groupName]!.books.add(book); + } else { + libraryMap[groupName] = Library(name: groupName, books: [book]); + } } + + return libraryMap.values.toList(); } @override @@ -138,7 +133,10 @@ class _MypageScreenState extends State ), body: Column( children: [ - if (isLogin == true) const LoggedWidget() else const LoginWidget(), + if (isLogin) + const LoggedWidget() + else + LoginWidget(updateLoginStatus: _updateLoginStatus), TabBar( labelColor: Colors.black, indicatorColor: Colors.black, @@ -157,7 +155,10 @@ class _MypageScreenState extends State controller: _tabController, children: [ BookReportWidget(books: books), - MyLibraryWidget(libraries: libraries), + MyLibraryWidget( + libraries: libraries, + onLibraryUpdated: _initUserState, + ), ], ), ), @@ -166,6 +167,15 @@ class _MypageScreenState extends State ), ); } + + void _updateLoginStatus(bool isLoggedIn) { + setState(() { + isLogin = isLoggedIn; + if (isLoggedIn) { + _initUserState(); + } + }); + } } class LoggedWidget extends StatelessWidget { @@ -189,23 +199,17 @@ class LoggedWidget extends StatelessWidget { borderRadius: BorderRadius.circular(12), color: Colors.grey[200], ), - child: Column( - crossAxisAlignment: CrossAxisAlignment.start, + child: Row( children: [ - Row( - children: [ - Icon( - Icons.account_circle, - size: 70.w, - ), - SizedBox(width: 16.w), - Text( - name, - style: TextStyle( - fontSize: 20.sp, fontWeight: FontWeight.bold), - ), - SizedBox(width: 65.w), - ], + Icon( + Icons.account_circle, + size: 70.w, + ), + SizedBox(width: 16.w), + Text( + name, + style: + TextStyle(fontSize: 20.sp, fontWeight: FontWeight.bold), ), ], ), @@ -217,7 +221,9 @@ class LoggedWidget extends StatelessWidget { } class LoginWidget extends StatefulWidget { - const LoginWidget({super.key}); + final void Function(bool isLogin) updateLoginStatus; + + const LoginWidget({super.key, required this.updateLoginStatus}); @override _LoginWidgetState createState() => _LoginWidgetState(); @@ -252,7 +258,9 @@ class _LoginWidgetState extends State { SizedBox(width: 76.w), ElevatedButton( onPressed: () { - signInWithGoogle(context); + setState(() { + signInWithGoogle(context); + }); }, child: const Text('로그인'), ), @@ -270,19 +278,15 @@ class _LoginWidgetState extends State { final GoogleSignInAccount? googleUser = await GoogleSignIn().signIn(); if (googleUser != null) { - print('name = ${googleUser.displayName}'); - print('email = ${googleUser.email}'); - print('id = ${googleUser.id}'); - userInfo = await login(googleUser.email); await secureStorage.saveData('userID', googleUser.email); - print(userInfo); if (userInfo['exceptionCode'] != null) { - print('진입'); - await context.push('/signup'); + context.push('/signup'); + } else { + await secureStorage.saveData("token", userInfo['token']); + await secureStorage.saveData("id", userInfo['id']); + widget.updateLoginStatus(true); } - await secureStorage.saveData("token", userInfo['token']); - await secureStorage.saveData("id", userInfo['id']); } } } @@ -300,7 +304,7 @@ class BookReportWidget extends StatelessWidget { final book = books[index]; return GestureDetector( onTap: () async { - context.push('/bookreport_viewing'); + context.push('/bookreport_viewing', extra: book['id']); }, child: SizedBox( height: 101.h, @@ -313,7 +317,7 @@ class BookReportWidget extends StatelessWidget { width: 240.w, height: 16.h, child: Text( - '${book.startDate} ~ ${book.endDate}', + '${book['startDate']} ~ ${book['endDate']}', style: TextStyle( color: const Color(0xFF6E767F), fontSize: 9.sp, @@ -330,7 +334,7 @@ class BookReportWidget extends StatelessWidget { width: 240.w, height: 45.h, child: Text( - book.type, + book['type'], style: TextStyle( color: const Color(0xFF6E767F), fontSize: 9.sp, @@ -347,7 +351,7 @@ class BookReportWidget extends StatelessWidget { width: 240.w, height: 16.h, child: Text( - '${book.author} | ${book.publisher}', + '${book['book']['author']} | ${book['book']['publisher']}', style: TextStyle( color: Colors.black, fontSize: 10.sp, @@ -363,13 +367,14 @@ class BookReportWidget extends StatelessWidget { child: SizedBox( width: 240.w, child: Text( - book.title, + book['title'], style: TextStyle( color: Colors.black, fontSize: 20.sp, fontFamily: 'Noto Sans KR', fontWeight: FontWeight.w700, ), + overflow: TextOverflow.ellipsis, ), ), ), @@ -381,7 +386,7 @@ class BookReportWidget extends StatelessWidget { height: 85.68.h, decoration: ShapeDecoration( image: DecorationImage( - image: NetworkImage(book.imageUrl), + image: NetworkImage(book['book']['imageUrl']), fit: BoxFit.fill, ), shape: RoundedRectangleBorder( @@ -399,18 +404,28 @@ class BookReportWidget extends StatelessWidget { } } -class MyLibraryWidget extends StatelessWidget { +class MyLibraryWidget extends StatefulWidget { final List libraries; + final VoidCallback onLibraryUpdated; // Add this line - const MyLibraryWidget({super.key, required this.libraries}); + const MyLibraryWidget({ + super.key, + required this.libraries, + required this.onLibraryUpdated, // Add this line + }); + @override + _MyLibraryWidgetState createState() => _MyLibraryWidgetState(); +} + +class _MyLibraryWidgetState extends State { @override Widget build(BuildContext context) { return Scaffold( body: ListView.builder( - itemCount: libraries.length, + itemCount: widget.libraries.length, itemBuilder: (context, index) { - var library = libraries[index]; + var library = widget.libraries[index]; return Padding( padding: EdgeInsets.all(15.w), child: Column( @@ -437,20 +452,18 @@ class MyLibraryWidget extends StatelessWidget { Container( width: 90.w, height: 128.52.h, - decoration: ShapeDecoration( + decoration: BoxDecoration( image: DecorationImage( image: NetworkImage(book.imageUrl), fit: BoxFit.fill, ), - shape: RoundedRectangleBorder( - borderRadius: BorderRadius.circular(3), - ), + borderRadius: BorderRadius.circular(3), ), ), SizedBox(height: 5.h), SizedBox( - width: 90.w, - height: 20.h, + width: 90, + height: 20, child: Text( book.title, style: TextStyle( @@ -474,7 +487,9 @@ class MyLibraryWidget extends StatelessWidget { ), floatingActionButton: FloatingActionButton( onPressed: () { - context.push('/make_library'); + context.push('/make_library').then((_) { + widget.onLibraryUpdated(); + }); }, backgroundColor: Colors.green, shape: const CircleBorder(), diff --git a/frontend/lib/screens/home/search/search_screen.dart b/frontend/lib/screens/home/search/search_screen.dart index fc99757ce6..b51ff2d98f 100644 --- a/frontend/lib/screens/home/search/search_screen.dart +++ b/frontend/lib/screens/home/search/search_screen.dart @@ -1,15 +1,14 @@ +import 'dart:async'; + import 'package:flutter/material.dart'; -import 'package:flutter/widgets.dart'; import 'package:flutter_screenutil/flutter_screenutil.dart'; -import 'package:go_router/go_router.dart'; import 'package:frontend/http.dart'; -import 'package:frontend/screens/home/search/search_screen_util.dart' - as SearchUtil; +import 'package:frontend/provider/secure_storage_provider.dart'; import 'package:frontend/screens/home/group/group_screen_util.dart' as GroupUtil; -import 'package:frontend/provider/secure_storage_provider.dart'; +import 'package:frontend/screens/home/search/search_screen_util.dart' + as SearchUtil; import 'package:provider/provider.dart'; -import 'dart:async'; List BookData = []; List GroupData = []; @@ -198,15 +197,9 @@ class _SearchState extends State { if (check && GroupData.isEmpty) Text("검색 결과가 없습니다"), ElevatedButton( onPressed: () async { - dynamic userInfo = - await login("test13@gmail.com"); - // dynamic userInfo = await singup("test13@gmail.com", "한지민", 30, "여자"); - print(userInfo['token']); - print(userInfo['id']); - await secureStorage.saveData( - "token", userInfo['token']); - await secureStorage.saveData( - "id", userInfo['id']); + await secureStorage.saveData('name', '이현준'); + await secureStorage.saveData('age', '23'); + await secureStorage.saveData('gender', '남자'); }, child: Text('테스트'), ), From 206c165ea4ea29402d9fe738b2e5c5cb6536a11f Mon Sep 17 00:00:00 2001 From: ZomSik Date: Sat, 18 May 2024 14:59:03 +0900 Subject: [PATCH 2/2] =?UTF-8?q?#59=20=EB=B0=B1=EC=97=94=EB=93=9C=20?= =?UTF-8?q?=EC=97=B0=EA=B2=B0=EC=A4=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- frontend/lib/http.dart | 7 +- frontend/lib/main.dart | 4 +- .../bookreport/bookreport_viewing_screen.dart | 11 + .../bookreport/bookreport_writing_screen.dart | 199 ++++++++---------- .../home/mypage/makelibrary_screen.dart | 3 +- .../screens/home/mypage/mypage_screen.dart | 14 +- .../screens/home/mypage/signup_screen.dart | 80 ++++--- 7 files changed, 159 insertions(+), 159 deletions(-) diff --git a/frontend/lib/http.dart b/frontend/lib/http.dart index f51aab2105..0894afa4d0 100644 --- a/frontend/lib/http.dart +++ b/frontend/lib/http.dart @@ -199,6 +199,7 @@ Future contentCreate( dynamic asId, String isbn, String booktitle, + String description, String author, String publisher, String publishDate, @@ -211,7 +212,6 @@ Future contentCreate( var address; // print(clubId); if (clubId == null) { - print(clubId); address = Uri.parse("$BASE_URL/content/create?"); } else { address = Uri.parse("$BASE_URL/content/create?clubId=$clubId&asId=$asId"); @@ -226,6 +226,7 @@ Future contentCreate( "addBookRequest": { "isbn": isbn, "title": booktitle, + "description": description, "author": author, "publisher": publisher, "publishDate": publishDate, @@ -239,7 +240,7 @@ Future contentCreate( }), ); final data = res.body; - // final data = json.decode(utf8.decode(res.bodyBytes)); + //final data = json.decode(utf8.decode(res.bodyBytes)); print(data); return data; } @@ -603,6 +604,7 @@ Future addBookToLibrary( String token, String isbn, String title, + String description, String author, String publisher, String publishDate, @@ -617,6 +619,7 @@ Future addBookToLibrary( body: json.encode({ "isbn": isbn, "title": title, + "description": description, "author": author, "publisher": publisher, "publishDate": publishDate, diff --git a/frontend/lib/main.dart b/frontend/lib/main.dart index efa3e36371..b4823e773f 100644 --- a/frontend/lib/main.dart +++ b/frontend/lib/main.dart @@ -107,9 +107,7 @@ final GoRouter router = GoRouter( path: '/bookreport_viewing', builder: (context, state) { dynamic contentData = state.extra as dynamic; - return BookReportViewingScreen( - contentData: contentData, - ); + return BookReportViewingScreen(contentData: contentData); }, ), GoRoute( diff --git a/frontend/lib/screens/home/bookreport/bookreport_viewing_screen.dart b/frontend/lib/screens/home/bookreport/bookreport_viewing_screen.dart index 5daadf6261..9372d5f624 100644 --- a/frontend/lib/screens/home/bookreport/bookreport_viewing_screen.dart +++ b/frontend/lib/screens/home/bookreport/bookreport_viewing_screen.dart @@ -22,6 +22,7 @@ class _BookReportViewingState extends State { String _template = ''; String _writer = ''; String _title = ''; + String _booktitle = ''; String _body = ''; String _author = "작가"; String _publisher = "출판사"; @@ -43,6 +44,7 @@ class _BookReportViewingState extends State { if (_template == "독후감" || _template == "한줄평" || _template == "인용구") { _body = content['body']; _title = content['title']; + _booktitle = content['book']['title']; } else { _category = quizCategory(content['type']); _answer = content['answer']; @@ -131,6 +133,15 @@ class _BookReportViewingState extends State { ), ), const SizedBox(height: 10), + Padding( + padding: const EdgeInsets.symmetric(horizontal: 20), + child: Row( + children: [ + Text(_booktitle), + ], + ), + ), + const SizedBox(height: 10), Padding( padding: const EdgeInsets.symmetric(horizontal: 20), child: Row( diff --git a/frontend/lib/screens/home/bookreport/bookreport_writing_screen.dart b/frontend/lib/screens/home/bookreport/bookreport_writing_screen.dart index af0a6c7690..c86964a0be 100644 --- a/frontend/lib/screens/home/bookreport/bookreport_writing_screen.dart +++ b/frontend/lib/screens/home/bookreport/bookreport_writing_screen.dart @@ -29,6 +29,7 @@ class _BookReportWritingState extends State { bool _isKeyboardVisible = false; // Variables to store user input + final TextEditingController _titleController = TextEditingController(); final TextEditingController _bookTitleController = TextEditingController(); DateTime _startDate = DateTime.now(); DateTime _endDate = DateTime.now(); @@ -51,6 +52,7 @@ class _BookReportWritingState extends State { String _isbn = ""; String _publisherDate = ""; String _imageUrl = ""; + String _description = ""; late final _KeyboardVisibilityObserverWrapper _keyboardVisibilityObserverWrapper; @@ -142,89 +144,24 @@ class _BookReportWritingState extends State { padding: const EdgeInsets.symmetric(horizontal: 20), child: Row( children: [ - const Text('도서: '), + const Text('제목: '), const SizedBox(width: 10), Expanded( child: SizedBox( width: _screenWidth * 0.7, child: TextField( style: const TextStyle(fontSize: 14), - controller: _bookTitleController, + controller: _titleController, decoration: const InputDecoration( - hintText: '도서를 입력하세요.', + hintText: '제목을 입력하세요.', border: InputBorder.none, ), - textInputAction: TextInputAction.go, - onSubmitted: (value) async { - BookData = - await SearchBook(_bookTitleController.text); - showDialog( - // ignore: use_build_context_synchronously - context: context, - builder: (BuildContext context) { - return AlertDialog( - title: const Text('도서 검색 결과'), - content: SingleChildScrollView( - child: Column( - children: [ - for (int i = 0; i < BookData.length; i++) - searchutil.BookSearchListItem( - data: BookData[i], - type: "search", - clubId: 0, - onSelected: (selectedData) { - print( - 'Selected Data: $selectedData'); - _bookTitleController.text = - selectedData['title']; - setState(() { - _author = selectedData['author']; - _publisher = - selectedData['publisher']; - }); - _isbn = selectedData['isbn']; - _publisherDate = - selectedData['pubdate']; - _imageUrl = selectedData['image']; - Navigator.of(context).pop(); - }, - ), - ], - ), - ), - ); - }, - ); - }, ), ), ), ], ), ), - const SizedBox(height: 10), - Padding( - padding: const EdgeInsets.symmetric(horizontal: 20), - child: Row( - children: [ - Text('$_author | $_publisher', - style: const TextStyle(color: Colors.black)), - ], - ), - ), - const SizedBox(height: 15), - Padding( - padding: const EdgeInsets.symmetric(horizontal: 10), - child: Container( - decoration: BoxDecoration( - border: Border.all( - width: 1, - color: const Color(0xFFA9AFB7), - ), - ), - ), - ), - const SizedBox(height: 15), Padding( padding: const EdgeInsets.symmetric(horizontal: 20), child: Row( @@ -275,65 +212,94 @@ class _BookReportWritingState extends State { ], ), ), - const SizedBox(height: 20), + const SizedBox(height: 15), + Padding( + padding: const EdgeInsets.symmetric(horizontal: 10), + child: Container( + decoration: BoxDecoration( + border: Border.all( + width: 1, + color: const Color(0xFFA9AFB7), + ), + ), + ), + ), Padding( padding: const EdgeInsets.symmetric(horizontal: 20), child: Row( children: [ - const Text('공개 여부: ', style: TextStyle(color: Colors.black)), - const SizedBox(width: 3), - GestureDetector( - onTap: () { - setState(() { - _isPublic = true; - }); - }, - child: Container( - decoration: BoxDecoration( - border: Border.all( - color: Colors.black, - width: 0.5, - ), - borderRadius: BorderRadius.circular(5), - color: _isPublic ? Colors.green : Colors.white, - ), - padding: const EdgeInsets.symmetric(horizontal: 5), - child: const Text( - '공개', - style: TextStyle( - color: Colors.black, - ), - ), - ), - ), + const Text('도서: '), const SizedBox(width: 10), - GestureDetector( - onTap: () { - setState(() { - _isPublic = false; - }); - }, - child: Container( - decoration: BoxDecoration( - border: Border.all( - color: Colors.black, - width: 0.5, - ), - borderRadius: BorderRadius.circular(5), - color: !_isPublic ? Colors.green : Colors.white, - ), - padding: const EdgeInsets.symmetric(horizontal: 5), - child: const Text( - '비공개', - style: TextStyle( - color: Colors.black, + Expanded( + child: SizedBox( + width: _screenWidth * 0.7, + child: TextField( + style: const TextStyle(fontSize: 14), + controller: _bookTitleController, + decoration: const InputDecoration( + hintText: '도서를 입력하세요.', + border: InputBorder.none, ), + textInputAction: TextInputAction.go, + onSubmitted: (value) async { + BookData = + await SearchBook(_bookTitleController.text); + showDialog( + // ignore: use_build_context_synchronously + context: context, + builder: (BuildContext context) { + return AlertDialog( + title: const Text('도서 검색 결과'), + content: SingleChildScrollView( + child: Column( + children: [ + for (int i = 0; i < BookData.length; i++) + searchutil.BookSearchListItem( + data: BookData[i], + type: "search", + clubId: 0, + onSelected: (selectedData) { + print( + 'Selected Data: $selectedData'); + _bookTitleController.text = + selectedData['title']; + setState(() { + _author = selectedData['author']; + _publisher = + selectedData['publisher']; + }); + _isbn = selectedData['isbn']; + _publisherDate = + selectedData['pubdate']; + _imageUrl = selectedData['image']; + _description = + selectedData['description']; + Navigator.of(context).pop(); + }, + ), + ], + ), + ), + ); + }, + ); + }, ), ), ), ], ), ), + const SizedBox(height: 10), + Padding( + padding: const EdgeInsets.symmetric(horizontal: 20), + child: Row( + children: [ + Text('$_author | $_publisher', + style: const TextStyle(color: Colors.black)), + ], + ), + ), const SizedBox(height: 15), Padding( padding: const EdgeInsets.symmetric(horizontal: 10), @@ -378,12 +344,13 @@ class _BookReportWritingState extends State { widget.asId, _isbn, _bookTitleController.text, + _description, _author, _publisher, _publisherDate, _imageUrl, _template, - _bookTitleController.text, + _titleController.text, _writingController.text, _startDate.toString(), _endDate.toString()); diff --git a/frontend/lib/screens/home/mypage/makelibrary_screen.dart b/frontend/lib/screens/home/mypage/makelibrary_screen.dart index 1dc519f826..15ac2ff635 100644 --- a/frontend/lib/screens/home/mypage/makelibrary_screen.dart +++ b/frontend/lib/screens/home/mypage/makelibrary_screen.dart @@ -119,7 +119,6 @@ class _MakeLibraryScreenState extends State { const SizedBox(width: 10), Expanded( child: SizedBox( - //width: _screenWidth * 0.7, child: TextField( style: const TextStyle(fontSize: 14), controller: _bookTitleController, @@ -150,6 +149,8 @@ class _MakeLibraryScreenState extends State { _tempbookList = { 'isbn': selectedData['isbn'], 'title': selectedData['title'], + 'description': + selectedData['description'], 'author': selectedData['author'], 'publisher': selectedData['publisher'], diff --git a/frontend/lib/screens/home/mypage/mypage_screen.dart b/frontend/lib/screens/home/mypage/mypage_screen.dart index b953e0189d..0c1926095b 100644 --- a/frontend/lib/screens/home/mypage/mypage_screen.dart +++ b/frontend/lib/screens/home/mypage/mypage_screen.dart @@ -77,6 +77,7 @@ class _MypageScreenState extends State age = userInfo['age']?.toString() ?? '0'; gender = userInfo['gender']; books = userInfo['contentList']; + print(books); secureStorage.saveData('name', name!); secureStorage.saveData('age', age!); secureStorage.saveData('gender', gender!); @@ -281,10 +282,15 @@ class _LoginWidgetState extends State { userInfo = await login(googleUser.email); await secureStorage.saveData('userID', googleUser.email); if (userInfo['exceptionCode'] != null) { - context.push('/signup'); + context.push('/signup').then((_) { + widget.updateLoginStatus(true); + }); } else { await secureStorage.saveData("token", userInfo['token']); await secureStorage.saveData("id", userInfo['id']); + await secureStorage.saveData("name", userInfo['name']); + await secureStorage.saveData("age", userInfo['age'].toString()); + await secureStorage.saveData("gender", userInfo['gender']); widget.updateLoginStatus(true); } } @@ -302,9 +308,11 @@ class BookReportWidget extends StatelessWidget { itemCount: books.length, itemBuilder: (context, index) { final book = books[index]; + final startDate = book['startDate'].toString().substring(0, 10); + final endDate = book['endDate'].toString().substring(0, 10); return GestureDetector( onTap: () async { - context.push('/bookreport_viewing', extra: book['id']); + context.push('/bookreport_viewing', extra: book); }, child: SizedBox( height: 101.h, @@ -317,7 +325,7 @@ class BookReportWidget extends StatelessWidget { width: 240.w, height: 16.h, child: Text( - '${book['startDate']} ~ ${book['endDate']}', + '$startDate ~ $endDate', style: TextStyle( color: const Color(0xFF6E767F), fontSize: 9.sp, diff --git a/frontend/lib/screens/home/mypage/signup_screen.dart b/frontend/lib/screens/home/mypage/signup_screen.dart index ea5e21bc5c..255e26c18e 100644 --- a/frontend/lib/screens/home/mypage/signup_screen.dart +++ b/frontend/lib/screens/home/mypage/signup_screen.dart @@ -1,7 +1,7 @@ import 'package:flutter/material.dart'; import 'package:flutter_screenutil/flutter_screenutil.dart'; -import 'package:frontend/provider/secure_storage_provider.dart'; import 'package:frontend/http.dart'; +import 'package:frontend/provider/secure_storage_provider.dart'; import 'package:go_router/go_router.dart'; import 'package:provider/provider.dart'; @@ -114,18 +114,22 @@ class _SignupState extends State { ), Positioned( left: 20.w, - child: Expanded( - child: SizedBox( - width: 330.w, - child: TextField( - style: const TextStyle(fontSize: 14), - controller: _nameController, - decoration: const InputDecoration( - hintText: '이름', - border: InputBorder.none, + child: Row( + children: [ + Expanded( + child: SizedBox( + width: 330.w, + child: TextField( + style: const TextStyle(fontSize: 14), + controller: _nameController, + decoration: const InputDecoration( + hintText: '이름', + border: InputBorder.none, + ), + ), ), ), - ), + ], ), ), ], @@ -154,20 +158,24 @@ class _SignupState extends State { ), Positioned( left: 20.w, - child: Expanded( - child: SizedBox( - width: 330.w, - child: TextFormField( - style: const TextStyle(fontSize: 14), - controller: _ageController, - keyboardType: TextInputType.number, - decoration: const InputDecoration( - hintText: '나이', - border: InputBorder.none, + child: Row( + children: [ + Expanded( + child: SizedBox( + width: 330.w, + child: TextFormField( + style: const TextStyle(fontSize: 14), + controller: _ageController, + keyboardType: TextInputType.number, + decoration: const InputDecoration( + hintText: '나이', + border: InputBorder.none, + ), + validator: _validateAge, + ), ), - validator: _validateAge, ), - ), + ], ), ), ], @@ -196,19 +204,23 @@ class _SignupState extends State { ), Positioned( left: 20.w, - child: Expanded( - child: SizedBox( - width: 330.w, - child: TextFormField( - style: const TextStyle(fontSize: 14), - controller: _genderController, - decoration: const InputDecoration( - hintText: '성별', - border: InputBorder.none, + child: Row( + children: [ + Expanded( + child: SizedBox( + width: 330.w, + child: TextFormField( + style: const TextStyle(fontSize: 14), + controller: _genderController, + decoration: const InputDecoration( + hintText: '성별', + border: InputBorder.none, + ), + validator: _validateAge, + ), ), - validator: _validateAge, ), - ), + ], ), ), ],