Skip to content

Commit

Permalink
Merge pull request #128 from sparcs-kaist/fix@reviews-syncronize
Browse files Browse the repository at this point in the history
[FATAL] Fix #123, #126, fix synchronized reviews, add translation in timetable
  • Loading branch information
sboh1214 authored Aug 22, 2023
2 parents 022ebab + 11fec86 commit d5bd48d
Show file tree
Hide file tree
Showing 13 changed files with 197 additions and 144 deletions.
13 changes: 10 additions & 3 deletions assets/translations/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,16 @@
"remained_datetime": "D-{} days {} hours {} minutes"
},
"timetable": {
"ask_delete_lecture": "Are you delete class '{}'?",
"ask_delete_tab": "Do you really want to delete {}?",
"ask_delete_lecture": "Do you want to delete class '{}'?",
"ask_delete_tab": "Do you really want to delete '{}'?",
"my_tab": "My Table",
"tab": "Table {}",
"add_lecture": "Add Lecture",
"remove_lecture": "Remove Lecture",
"dialog": {
"add_lecture": "Add Lecture",
"ask_add_lecture": "There is a lecture with overlapping hours. If added, the previous lecture will be deleted.\nDo you want to add new lecture to the timetable?"
},
"tab_menu": {
"copy": "Copy Timetable",
"export_img": "Share as Image",
Expand Down Expand Up @@ -113,7 +119,8 @@
"load": "Load",
"speech": "Speech",
"like": "Like",
"report": "Report"
"report": "Report",
"expand": "more"
},
"user": {
"name": "Name",
Expand Down
11 changes: 9 additions & 2 deletions assets/translations/ko.json
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,15 @@
},
"timetable": {
"ask_delete_lecture": "'{}' 수업을 삭제하시겠습니까?",
"ask_delete_tab": "{}을(를) 정말 삭제하시겠습니까?",
"ask_delete_tab": "'{}'을(를) 정말 삭제하시겠습니까?",
"my_tab": "내 시간표",
"tab": "시간표 {}",
"add_lecture": "시간표에 추가",
"remove_lecture": "시간표에서 제거",
"dialog": {
"add_lecture": "수업 추가",
"ask_add_lecture": "시간이 겹치는 수업이 있습니다. 추가하시면 해당 수업은 삭제됩니다.\n시간표에 추가하시겠습니까?"
},
"tab_menu": {
"copy": "시간표 복제하기",
"export_img": "이미지로 내보내기",
Expand Down Expand Up @@ -113,7 +119,8 @@
"load": "널널",
"speech": "강의",
"like": "추천",
"report": "신고하기"
"report": "신고하기",
"expand": "더 보기"
},
"user": {
"name": "이름",
Expand Down
4 changes: 2 additions & 2 deletions lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import 'package:otlplus/providers/auth_model.dart';
import 'package:otlplus/providers/course_detail_model.dart';
import 'package:otlplus/providers/info_model.dart';
import 'package:otlplus/providers/lecture_detail_model.dart';
import 'package:otlplus/providers/review_model.dart';
import 'package:otlplus/providers/latest_reviews_model.dart';
import 'package:otlplus/providers/lecture_search_model.dart';
import 'package:otlplus/providers/timetable_model.dart';
import 'package:otlplus/utils/create_material_color.dart';
Expand Down Expand Up @@ -66,7 +66,7 @@ void main() {
),
ChangeNotifierProvider(create: (_) => LectureSearchModel()),
ChangeNotifierProvider(create: (_) => CourseSearchModel()),
ChangeNotifierProvider(create: (_) => ReviewModel()),
ChangeNotifierProvider(create: (_) => LatestReviewsModel()),
ChangeNotifierProvider(create: (_) => LikedReviewModel()),
ChangeNotifierProvider(create: (_) => HallOfFameModel()),
ChangeNotifierProvider(create: (_) => CourseDetailModel()),
Expand Down
9 changes: 5 additions & 4 deletions lib/pages/lecture_detail_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -113,9 +113,8 @@ class LectureDetailPage extends StatelessWidget {
context: context,
barrierDismissible: false,
builder: (context) => AlertDialog(
title: const Text("수업 추가"),
content: const Text(
"시간이 겹치는 수업이 있습니다. 추가하시면 해당 수업은 삭제됩니다.\n시간표에 추가하시겠습니까?"),
title: Text("timetable.dialog.add_lecture".tr()),
content: Text("timetable.dialog.ask_add_lecture".tr()),
actions: [
IconTextButton(
padding: EdgeInsets.all(12),
Expand Down Expand Up @@ -144,7 +143,9 @@ class LectureDetailPage extends StatelessWidget {
);
}
},
text: isAdded ? "시간표에서 제거" : "시간표에 추가",
text: isAdded
? "timetable.remove_lecture".tr()
: "timetable.add_lecture".tr(),
textStyle: const TextStyle(fontSize: 12.0),
icon: isAdded ? Icons.close : Icons.add,
iconSize: 14,
Expand Down
1 change: 1 addition & 0 deletions lib/pages/main_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@ class _MainPageState extends State<MainPage> {
borderRadius:
BorderRadius.vertical(top: Radius.circular(16.0)),
child: Container(
color: OTLColor.grayF,
constraints: const BoxConstraints.expand(),
child: CustomScrollView(
reverse: true,
Expand Down
36 changes: 21 additions & 15 deletions lib/pages/review_page.dart
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
import 'package:flutter/material.dart';
import 'package:otlplus/pages/course_detail_page.dart';
import 'package:otlplus/models/review.dart';
import 'package:otlplus/providers/hall_of_fame_model.dart';
import 'package:otlplus/utils/navigator.dart';
import 'package:otlplus/widgets/hall_of_fame_control.dart';
import 'package:otlplus/widgets/otl_scaffold.dart';
import 'package:otlplus/widgets/review_mode_control.dart';
import 'package:provider/provider.dart';
import 'package:otlplus/providers/course_detail_model.dart';
import 'package:otlplus/providers/review_model.dart';
import 'package:otlplus/providers/latest_reviews_model.dart';
import 'package:otlplus/widgets/review_block.dart';

class ReviewPage extends StatefulWidget {
Expand All @@ -23,9 +22,6 @@ class _ReviewPageState extends State<ReviewPage> {
Widget build(BuildContext context) {
final _selectedMode =
context.select<HallOfFameModel, int>((m) => m.selectedMode);
final latestReviews =
context.select<ReviewModel, List<Review>>((m) => m.reviews);
final hallOfFames = context.watch<HallOfFameModel>().hallOfFames();

return OTLLayout(
leading: ReviewModeControl(
Expand All @@ -40,17 +36,17 @@ class _ReviewPageState extends State<ReviewPage> {
),
body: Card(
shape: const RoundedRectangleBorder(
borderRadius: BorderRadius.vertical(top: Radius.circular(16.0)),
borderRadius: BorderRadius.only(topRight: Radius.circular(16.0)),
),
child: NotificationListener<ScrollNotification>(
onNotification: (scrollNotification) {
if (_selectedMode == 1) {
final reviewModel = context.read<ReviewModel>();
final reviewModel = context.read<LatestReviewsModel>();

if (!reviewModel.isLoading &&
scrollNotification.metrics.pixels ==
scrollNotification.metrics.maxScrollExtent) {
reviewModel.loadReviews();
reviewModel.loadLatestReviews();
}

return true;
Expand All @@ -60,7 +56,7 @@ class _ReviewPageState extends State<ReviewPage> {
if (!hallOfFameModel.isLoading &&
scrollNotification.metrics.pixels ==
scrollNotification.metrics.maxScrollExtent) {
hallOfFameModel.loadHallOfFames();
hallOfFameModel.loadHallOfFame();
}

return true;
Expand All @@ -71,24 +67,28 @@ class _ReviewPageState extends State<ReviewPage> {
child: Column(
mainAxisSize: MainAxisSize.min,
children: <Widget>[
_selectedMode == 1
? _buildLatestReviews(latestReviews)
: _buildHallOfFames(hallOfFames),
_selectedMode == 1 ? LatestReviewsPage() : HallOfFamePage()
],
),
),
),
),
);
}
}

class LatestReviewsPage extends StatelessWidget {
const LatestReviewsPage({Key? key}) : super(key: key);

Widget _buildLatestReviews(latestReviews) {
@override
Widget build(BuildContext context) {
final _scrollController = context.watch<HallOfFameModel>().scrollController;
final latestReviews = context.watch<LatestReviewsModel>().latestReviews;

return Expanded(
child: RefreshIndicator(
onRefresh: () async {
await context.read<ReviewModel>().clear();
await context.read<LatestReviewsModel>().clear();
},
child: Scrollbar(
child: CustomScrollView(
Expand Down Expand Up @@ -132,9 +132,15 @@ class _ReviewPageState extends State<ReviewPage> {
),
);
}
}

class HallOfFamePage extends StatelessWidget {
const HallOfFamePage({Key? key}) : super(key: key);

Widget _buildHallOfFames(hallOfFames) {
@override
Widget build(BuildContext context) {
final _scrollController = context.watch<HallOfFameModel>().scrollController;
final hallOfFames = context.watch<HallOfFameModel>().hallOfFame;

return Expanded(
child: RefreshIndicator(
Expand Down
14 changes: 11 additions & 3 deletions lib/pages/timetable_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,11 @@ class _TimetablePageState extends State<TimetablePage> {
GestureDetector(
behavior: HitTestBehavior.translucent,
onTap: () {
OTLNavigator.push(context, LectureSearchPage());
OTLNavigator.push(
context,
LectureSearchPage(
openKeyboard: false,
));
},
child: Padding(
padding:
Expand Down Expand Up @@ -167,10 +171,14 @@ class _TimetablePageState extends State<TimetablePage> {
}

Timetable _buildTimetable(
BuildContext context, List<Lecture> lectures, bool isExamTime) {
BuildContext context,
List<Lecture> lectures,
bool isExamTime,
) {
bool isFirst = true;
final tempLecture =
context.select<TimetableModel, Lecture?>((model) => model.tempLecture);
final isEn = EasyLocalization.of(context)?.currentLocale == Locale('en');

return Timetable(
lectures: (tempLecture == null) ? lectures : [...lectures, tempLecture],
Expand Down Expand Up @@ -205,7 +213,7 @@ class _TimetablePageState extends State<TimetablePage> {
builder: (context) => AlertDialog(
title: Text("common.delete".tr()),
content: Text("timetable.ask_delete_lecture").tr(
args: [lecture.title],
args: [isEn ? lecture.titleEn : lecture.title],
),
actions: [
IconTextButton(
Expand Down
17 changes: 9 additions & 8 deletions lib/providers/hall_of_fame_model.dart
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ class HallOfFameModel extends ChangeNotifier {
Semester? get semeseter => _semester;
void setSemester(Semester? semester) {
_semester = semester;
notifyListeners();

// 1. Animate Immediately But Error Prone
// _scrollController.animateTo(
Expand All @@ -40,16 +41,16 @@ class HallOfFameModel extends ChangeNotifier {
);
}

List<Review> _hallOfFames = <Review>[];
List<Review> hallOfFames() {
if (_hallOfFames.length == 0 && !_isLoading) loadHallOfFames();
return _hallOfFames;
List<Review> _hallOfFame = <Review>[];
List<Review> get hallOfFame {
if (_hallOfFame.length == 0 && !_isLoading) loadHallOfFame();
return _hallOfFame;
}

Future<void> clear() async {
_hallOfFames.clear();
_hallOfFame.clear();
_page = 0;
await loadHallOfFames();
await loadHallOfFame();

// 2. Animate Slowly But Safe
_scrollController.animateTo(
Expand All @@ -59,7 +60,7 @@ class HallOfFameModel extends ChangeNotifier {
);
}

Future<void> loadHallOfFames() async {
Future<void> loadHallOfFame() async {
_isLoading = true;

try {
Expand All @@ -82,7 +83,7 @@ class HallOfFameModel extends ChangeNotifier {
});
}
final rawReviews = response.data as List;
_hallOfFames.addAll(rawReviews.map((review) => Review.fromJson(review)));
_hallOfFame.addAll(rawReviews.map((review) => Review.fromJson(review)));
_page++;
_isLoading = false;
notifyListeners();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,26 +3,26 @@ import 'package:otlplus/constants/url.dart';
import 'package:otlplus/dio_provider.dart';
import 'package:otlplus/models/review.dart';

class ReviewModel extends ChangeNotifier {
class LatestReviewsModel extends ChangeNotifier {
int _page = 0;
int get page => _page;

bool _isLoading = false;
bool get isLoading => _isLoading;

List<Review> _reviews = <Review>[];
List<Review> get reviews {
if (_reviews.length == 0 && !_isLoading) loadReviews();
return _reviews;
List<Review> _latestReviews = <Review>[];
List<Review> get latestReviews {
if (_latestReviews.length == 0 && !_isLoading) loadLatestReviews();
return _latestReviews;
}

Future<void> clear() async {
_reviews.clear();
_latestReviews.clear();
_page = 0;
await loadReviews();
await loadLatestReviews();
}

Future<void> loadReviews() async {
Future<void> loadLatestReviews() async {
_isLoading = true;

try {
Expand All @@ -33,7 +33,8 @@ class ReviewModel extends ChangeNotifier {
"limit": 10,
});
final rawReviews = response.data as List;
_reviews.addAll(rawReviews.map((review) => Review.fromJson(review)));
_latestReviews
.addAll(rawReviews.map((review) => Review.fromJson(review)));
_page++;
_isLoading = false;
notifyListeners();
Expand Down
5 changes: 3 additions & 2 deletions lib/widgets/expandable_text.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import 'package:easy_localization/easy_localization.dart' as _;
import 'package:flutter/gestures.dart';
import 'package:flutter/material.dart';

Expand Down Expand Up @@ -25,11 +26,11 @@ class ExpandableTextState extends State<ExpandableText> {
TextSpan expandButton = TextSpan(
children: <TextSpan>[
TextSpan(
text: "..",
text: ".. ",
style: widget.style,
),
TextSpan(
text: " 더보기",
text: "review.expand".tr(),
style:
(widget.style ?? TextStyle()).copyWith(color: Colors.black45),
recognizer: TapGestureRecognizer()
Expand Down
Loading

0 comments on commit d5bd48d

Please sign in to comment.