Skip to content

Commit

Permalink
feat: #5/공고 상세 바텀 시트 factory 방식으로 변경
Browse files Browse the repository at this point in the history
1. OCP 원칙 준수를 위해 switch-case 문 방식에서 Factory를 이용한 방식으로 변경
  • Loading branch information
Younggun-Kim committed Oct 22, 2024
1 parent 2d97a08 commit 36f0e4f
Show file tree
Hide file tree
Showing 14 changed files with 123 additions and 50 deletions.
4 changes: 3 additions & 1 deletion assets/translations/ko.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,5 +50,7 @@
"delete": "삭제",
"close": "마감",
"cancel": "취소",
"isNotDeadlineYetConfirmClose": "아직 마감날이 아닙니다. 마감할까요?"
"isNotDeadlineYetConfirmClose": "아직 마감날이 아닙니다. 마감할까요?",
"isUpdateContentCorrect": "수정하신 내용이 맞으신가요?",
"canRevertFromPostingManagement": "공고 관리에서 다시 되돌릴 수 있습니다."
}
2 changes: 2 additions & 0 deletions lib/core/utils/resource/string_res.dart
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ enum StringRes {
close,
cancel,
isNotDeadlineYetConfirmClose,
isUpdateContentCorrect,
canRevertFromPostingManagement,
}

extension StringResEx on StringRes {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,9 @@ class JobPostingDetailBloc
);

result.when(success: (JobPostingDetailEntity data) {
emit(state.copyWith(status: JobPostingDetailStatus.closed));
emit(state.copyWith(
status: JobPostingDetailStatus.closed,
));
}, fail: (String message) {
emit(state.copyWith(
status: JobPostingDetailStatus.fail,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:withu_app/core/core.dart';
import 'package:withu_app/feature/feature.dart';
import 'package:withu_app/feature/job_posting/domain/entities/job_posting_detail_entity.dart';
import 'package:withu_app/feature/job_posting/presentation/blocs/detail/job_posting_detail_bloc.dart';
import 'package:withu_app/gen/colors.gen.dart';
import 'package:withu_app/shared/shared.dart';

Expand Down Expand Up @@ -175,36 +174,20 @@ class _AppBar extends StatelessWidget {
class _MoreOptionButton extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MoreOptions<DetailMoreOptionsType>(
items: DetailMoreOptionsType.values,
onSelected: (DetailMoreOptionsType item) {
switch (item) {
case DetailMoreOptionsType.update:
DescriptionBottomSheet.show(
context: context,
description: StringRes.isNotDeadlineYetConfirmClose.tr,
actionText: StringRes.update.tr,
onTap: () {},
);
case DetailMoreOptionsType.delete:
DescriptionBottomSheet.show(
context: context,
description: StringRes.isNotDeadlineYetConfirmClose.tr,
actionText: StringRes.delete.tr,
onTap: () {},
);
case DetailMoreOptionsType.close:
DescriptionBottomSheet.show(
context: context,
description: StringRes.isNotDeadlineYetConfirmClose.tr,
actionText: StringRes.close.tr,
onTap: () {
context.read<JobPostingDetailBloc>().add(OnClosedJobPosting());
},
);
default:
break;
return MoreOptions<DetailBottomSheetType>(
items: DetailBottomSheetType.values,
onSelected: (DetailBottomSheetType item) {
final option = DetailBottomSheetFactory.getOption(item);

if (option == null) {
return;
}

DescriptionBottomSheet.show(
context: context,
option: option,
bloc: context.read<JobPostingDetailBloc>(),
);
},
);
}
Expand Down
1 change: 0 additions & 1 deletion lib/feature/job_posting/presentation/pages/pages.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
export 'job_postings_page.dart';
export 'job_posting_form_page.dart';
export 'types/types.dart';

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export 'detail_bottom_sheet_type.dart';
export 'detail_bottom_sheet_factory.dart';
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:withu_app/core/core.dart';
import 'package:withu_app/feature/feature.dart';
import 'package:withu_app/feature/job_posting/presentation/widgets/detail_bottom_sheet/detail_bottom_sheet_type.dart';
import 'package:withu_app/shared/bottom_sheet/bottom_sheet.dart';

/// 공고 상세보기 바텀 시트 Factory
class DetailBottomSheetFactory {
static final Map<DetailBottomSheetType, DescriptionBottomSheetOption>
_options = {
DetailBottomSheetType.update: _UpdateBottomSheet(),
DetailBottomSheetType.delete: _DeleteBottomSheet(),
DetailBottomSheetType.close: _CloseBottomSheet(),
};

static DescriptionBottomSheetOption? getOption(
DetailBottomSheetType type,
) {
return _options[type];
}
}

/// 공고 수정
class _UpdateBottomSheet implements DescriptionBottomSheetOption {
@override
String get actionText => StringRes.update.tr;

@override
String get description => StringRes.isNotDeadlineYetConfirmClose.tr;

@override
Function(Bloc? bloc) get exec => (Bloc? bloc) {};
}

/// 공고 삭제
class _DeleteBottomSheet implements DescriptionBottomSheetOption {
@override
String get actionText => StringRes.delete.tr;

@override
String get description => StringRes.canRevertFromPostingManagement.tr;

@override
Function(Bloc? bloc) get exec => (Bloc? bloc) {};
}

/// 공고 마감
class _CloseBottomSheet implements DescriptionBottomSheetOption {
@override
String get actionText => StringRes.close.tr;

@override
String get description => StringRes.isNotDeadlineYetConfirmClose.tr;

@override
Function(Bloc? bloc) get exec => (Bloc? bloc) {
if (bloc is JobPostingDetailBloc) {
bloc.add(OnClosedJobPosting());
}
};
}
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import 'package:withu_app/core/core.dart';

/// 공고 상세의 더보기 옵션 타입
enum DetailMoreOptionsType with L10nKeyProvider {
/// 공고 상세 화면 바텀 시트 타입
enum DetailBottomSheetType with L10nKeyProvider {
update(l10nKey: 'update'),
delete(l10nKey: 'delete'),
close(l10nKey: 'close');

@override
final String l10nKey;

const DetailMoreOptionsType({required this.l10nKey});
const DetailBottomSheetType({required this.l10nKey});
}
1 change: 1 addition & 0 deletions lib/feature/job_posting/presentation/widgets/widgets.dart
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
export 'job_postings_item.dart';
export 'detail_bottom_sheet/detail_bottom_sheet.dart';
2 changes: 1 addition & 1 deletion lib/shared/bottom_sheet/bottom_sheet.dart
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
export 'base/base_bottom_sheet.dart';
export 'description/description_bottom_sheet.dart';
export 'description/description.dart';
2 changes: 2 additions & 0 deletions lib/shared/bottom_sheet/description/description.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export 'description_bottom_sheet.dart';
export 'description_bottom_sheet_option.dart';
25 changes: 13 additions & 12 deletions lib/shared/bottom_sheet/description/description_bottom_sheet.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:withu_app/core/utils/utils.dart';
import 'package:withu_app/gen/colors.gen.dart';
import 'package:withu_app/shared/shared.dart';
Expand Down Expand Up @@ -53,21 +53,22 @@ class DescriptionBottomSheet extends StatelessWidget {
/// 바텀 시트 보기.
static Future show({
required BuildContext context,
required description,
required String actionText,
required VoidCallback onTap,
required DescriptionBottomSheetOption option,
Bloc? bloc,
}) {
return showModalBottomSheet(
context: context,
backgroundColor: Colors.transparent,
builder: (context) => DescriptionBottomSheet(
description: description,
actionText: actionText,
onTap: () {
onTap();
Navigator.pop(context);
},
),
builder: (context) {
return DescriptionBottomSheet(
description: option.description,
actionText: option.actionText,
onTap: () {
option.exec(bloc);
Navigator.pop(context);
},
);
},
);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import 'package:flutter_bloc/flutter_bloc.dart';

/// BottomSheet에서 필요한 값
abstract class DescriptionBottomSheetOption {
/// 설명
final String description;

/// 버튼 문구
final String actionText;

/// 버튼 클릭 시 실행될 동작
final Function(Bloc? bloc) exec;

DescriptionBottomSheetOption({
required this.description,
required this.actionText,
required this.exec,
});
}

0 comments on commit 36f0e4f

Please sign in to comment.