Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: 해시태그뷰, 해시태그 상세 검색 구현 #56

Merged
merged 1 commit into from
Aug 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions lib/constants/app_constants.dart
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,5 @@ List<Color> folderColors = [
AppColors.folderColorD7E5FC,
AppColors.folderColorECD8F3,
];

String uniqueKey = 'unique_key';
20 changes: 20 additions & 0 deletions lib/providers/content_detail_provider.dart
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,24 @@ class ContentDetail extends _$ContentDetail {
Future<ContentModel?> build() async {
return null;
}

Future<void> editContent({
required String contentId,
required String contentName,
required String contentMemo,
required String hashTagStringList,
}) async {
state = const AsyncValue.loading();

state = await AsyncValue.guard(() async {
// await ContentRepository.instance.editContent(
// contentId: contentId,
// contentName: contentName,
// contentMemo: contentMemo,
// hashTagStringList: hashTagStringList,
// );
var data = await fetchItem(contentId: contentId);
return data;
});
}
}
22 changes: 18 additions & 4 deletions lib/providers/hashtag_provider.dart
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,24 @@ class Hashtag extends _$Hashtag {
state = const AsyncValue.loading();

state = await AsyncValue.guard(() async {
await HashtagRepository.instance.editHashtag(
tagId: tagId,
hashtags: hashtags,
);
// await HashtagRepository.instance.editHashtag(
// tagId: tagId,
// hashtags: hashtags,
// );
var data = await fetchItem();
return data;
});
}

Future<void> deleteHashtag({
required List<String> tagIds,
}) async {
state = const AsyncValue.loading();

state = await AsyncValue.guard(() async {
// await HashtagRepository.instance.deleteHashtag(
// tagIds: tagIds,
// );
var data = await fetchItem();
return data;
});
Expand Down
4 changes: 2 additions & 2 deletions lib/providers/hashtag_view_provider.dart
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ part 'hashtag_view_provider.g.dart';
// @Riverpod(keepAlive: true)
@riverpod
class HashtagView extends _$HashtagView {
Future<(List<ContentModel>, int)> fetchItem() async {
Future<(List<ContentModel>, int)> fetchItem({String? hashtag}) async {
// get the [KeepAliveLink]
var link = ref.keepAlive();
// a timer to be used by the callbacks below
Expand All @@ -34,7 +34,7 @@ class HashtagView extends _$HashtagView {
timer?.cancel();
});

var data = await HashtagRepository.instance.getHashtagView();
var data = await HashtagRepository.instance.getHashtagView(tag: hashtag);
return data;
}

Expand Down
10 changes: 7 additions & 3 deletions lib/repositories/content_repository.dart
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ abstract class IContentRepository {

Future<void> editContent({
required String contentId,
required ContentModel content,
required String contentName,
required String contentMemo,
required String hashTagStringList,
});

Expand Down Expand Up @@ -106,15 +107,18 @@ class ContentRepository implements IContentRepository {
@override
Future<void> editContent({
required String contentId,
required ContentModel content,
required String contentName,
required String contentMemo,
required String hashTagStringList,
}) async {
var token = await TokenRepository.instance.getToken();

await dio.post(
'/api/v1/content/edit',
data: {
//todo 수정데이터
'title': contentName,
'memo': contentMemo,
'hashTag': hashTagStringList,
},
options: Options(
headers: {
Expand Down
20 changes: 19 additions & 1 deletion lib/repositories/hashtag_repository.dart
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ abstract class IHashtagRepository {
required String tagId,
required String hashtags,
});
Future<void> deleteHashtag({
required List<String> tagIds,
});
}

class HashtagRepository implements IHashtagRepository {
Expand Down Expand Up @@ -79,7 +82,7 @@ class HashtagRepository implements IHashtagRepository {
'/api/v1/hashtag/edit',
data: {
'tagId': tagId,
'hashtag': hashtags,
'hashTag': hashtags,
},
options: Options(
headers: {
Expand All @@ -88,4 +91,19 @@ class HashtagRepository implements IHashtagRepository {
),
);
}

@override
Future<void> deleteHashtag({required List<String> tagIds}) async {
var token = await TokenRepository.instance.getToken();

await dio.post(
'/api/v1/hashtag/delete',
data: {'tagIds': tagIds},
options: Options(
headers: {
'Authorization': 'Bearer $token',
},
),
);
}
}
1 change: 1 addition & 0 deletions lib/screens/add_content/add_image_content.dart
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ class AddImageContent extends HookConsumerWidget {
await ContentRepository.instance.addContent(
contentType: AddContentType.image,
content: ContentModel(
folderName: 'folderName',
contentId: folderId,
contentName: title.value,
contentHashTags: [],
Expand Down
1 change: 1 addition & 0 deletions lib/screens/add_content/add_link_content.dart
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ class AddLinkContent extends HookConsumerWidget {
await ContentRepository.instance.addContent(
contentType: AddContentType.url,
content: ContentModel(
folderName: 'folderName',
contentId: folderId,
contentUrl: link.value,
contentName: title.value,
Expand Down
1 change: 1 addition & 0 deletions lib/screens/file_sharing/user_listing_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ class UserListingScreen extends HookWidget {
@override
Widget build(BuildContext context) {
var content = useState(ContentModel(
folderName: '',
contentId: '1',
contentName: '',
contentMemo: '',
Expand Down
4 changes: 4 additions & 0 deletions lib/screens/home/content_view.dart
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import 'package:moa_app/widgets/button.dart';
import 'package:moa_app/widgets/image.dart';
import 'package:moa_app/widgets/loading_indicator.dart';
import 'package:moa_app/widgets/moa_widgets/bottom_modal_item.dart';
import 'package:moa_app/widgets/snackbar.dart';
import 'package:url_launcher/url_launcher.dart';

class ContentView extends HookConsumerWidget {
Expand All @@ -41,6 +42,9 @@ class ContentView extends HookConsumerWidget {
void pressGoToLink(String contentUrl) async {
var url = Uri.parse(contentUrl);
if (!await launchUrl(url)) {
if (context.mounted) {
snackbar.alert(context, '잘못된 링크입니다.\n$url');
}
throw Exception('Could not launch $url');
}
}
Expand Down
32 changes: 29 additions & 3 deletions lib/screens/home/edit_content_view.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:flutter_hooks/flutter_hooks.dart';
import 'package:go_router/go_router.dart';
Expand All @@ -6,14 +7,17 @@ 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/providers/content_detail_provider.dart';
import 'package:moa_app/providers/hashtag_provider.dart';
import 'package:moa_app/repositories/content_repository.dart';
import 'package:moa_app/screens/add_content/add_image_content.dart';
import 'package:moa_app/utils/general.dart';
import 'package:moa_app/widgets/button.dart';
import 'package:moa_app/widgets/edit_text.dart';
import 'package:moa_app/widgets/image.dart';
import 'package:moa_app/widgets/loading_indicator.dart';
import 'package:moa_app/widgets/moa_widgets/hashtag_box.dart';
import 'package:moa_app/widgets/snackbar.dart';

class EditContentView extends HookConsumerWidget {
const EditContentView({
Expand All @@ -31,10 +35,31 @@ class EditContentView extends HookConsumerWidget {
var hashtagList = useState<List<String>>(
content.contentHashTags.map((e) => e.hashTag).toList());

void saveEditContent() {
var loading = useState(false);

Future<void> saveEditContent() async {
// todo 컨텐츠 수정
// ContentRepository.instance.editContent()
isEditMode.value = false;
try {
loading.value = true;
await ContentRepository.instance.editContent(
contentId: content.contentId,
contentMemo: titleController.text,
contentName: memoController.text,
hashTagStringList: hashtagList.value.join(','),
);
await ref.read(contentDetailProvider.notifier).editContent(
contentId: content.contentId,
contentMemo: titleController.text,
contentName: memoController.text,
hashTagStringList: hashtagList.value.join(','),
);
isEditMode.value = false;
} catch (e) {
snackbar.alert(
context, kDebugMode ? e.toString() : '오류가 발생했습니다. 다시 시도해주세요.');
} finally {
loading.value = false;
}
}

void showEditHashtagModal() {
Expand Down Expand Up @@ -139,6 +164,7 @@ class EditContentView extends HookConsumerWidget {
),
const SizedBox(height: 30),
Button(
loading: loading.value,
backgroundColor: AppColors.primaryColor,
text: '변경 내용 저장',
onPressed: saveEditContent,
Expand Down
2 changes: 1 addition & 1 deletion lib/screens/home/folder_detail_view.dart
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ class FolderDetailView extends HookConsumerWidget {
child: DynamicGridList(
contentList: contentList,
pullToRefresh: pullToRefresh,
folderName: folderName,
folderNameProp: folderName,
),
),
],
Expand Down
Loading
Loading