Skip to content

Commit

Permalink
rename message to thread list
Browse files Browse the repository at this point in the history
  • Loading branch information
cp-ishita-g committed Jun 11, 2024
1 parent 96411a6 commit 3c666eb
Show file tree
Hide file tree
Showing 7 changed files with 70 additions and 68 deletions.
4 changes: 2 additions & 2 deletions app/lib/ui/app_route.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import 'package:flutter/cupertino.dart';
import 'package:go_router/go_router.dart';
import 'package:yourspace_flutter/ui/flow/auth/sign_in/phone/verification/phone_verification_screen.dart';
import 'package:yourspace_flutter/ui/flow/message/chat/chat_screen.dart';
import 'package:yourspace_flutter/ui/flow/message/message_screen.dart';
import 'package:yourspace_flutter/ui/flow/message/thread_list_screen.dart';
import 'package:yourspace_flutter/ui/flow/onboard/pick_name_screen.dart';
import 'package:yourspace_flutter/ui/flow/setting/contact_support/contact_support_screen.dart';
import 'package:yourspace_flutter/ui/flow/setting/profile/profile_screen.dart';
Expand Down Expand Up @@ -163,7 +163,7 @@ class AppRoute {
static AppRoute message(SpaceInfo space) {
return AppRoute(
pathMessage,
builder: (_) => MessageScreen(spaceInfo: space),
builder: (_) => ThreadListScreen(spaceInfo: space),
);
}
static AppRoute chat({required List<ApiUserInfo> users, required String spaceName}) {
Expand Down
11 changes: 5 additions & 6 deletions app/lib/ui/flow/message/chat/chat_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ class ChatScreen extends ConsumerStatefulWidget {

class _ChatScreenState extends ConsumerState<ChatScreen> {
late ChatViewNotifier notifier;
final Set<String> _selectedUsers = {};

@override
void initState() {
Expand Down Expand Up @@ -79,14 +78,14 @@ class _ChatScreenState extends ConsumerState<ChatScreen> {
scrollDirection: Axis.horizontal,
itemBuilder: (context, index) {
final isSelected =
_selectedUsers.contains(state.users[index].user.id);
notifier.selectedUsers.contains(state.users[index].user.id);
return GestureDetector(
onTap: () {
setState(() {
if (isSelected) {
_selectedUsers.remove(state.users[index].user.id);
notifier.selectedUsers.remove(state.users[index].user.id);
} else {
_selectedUsers.add(state.users[index].user.id);
notifier.selectedUsers.add(state.users[index].user.id);
}
});
},
Expand Down Expand Up @@ -124,12 +123,12 @@ class _ChatScreenState extends ConsumerState<ChatScreen> {
child: GestureDetector(
onTap: () {
setState(() {
_selectedUsers.clear();
notifier.selectedUsers.clear();
});
},
child: Column(
children: [
if (_selectedUsers.isEmpty) ...[
if (notifier.selectedUsers.isEmpty) ...[
_selectedView(context),
] else ...[
Container(
Expand Down
1 change: 1 addition & 0 deletions app/lib/ui/flow/message/chat/chat_view_model.dart
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ final chatViewStateProvider =
class ChatViewNotifier extends StateNotifier<ChatViewState> {
final MessageService messageService;
final ApiUser? currentUser;
final Set<String> selectedUsers = {};

ChatViewNotifier(this.messageService, this.currentUser)
: super(ChatViewState(message: TextEditingController()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,40 +16,39 @@ import 'package:yourspace_flutter/domain/extenstions/widget_extensions.dart';
import 'package:yourspace_flutter/ui/app_route.dart';
import 'package:yourspace_flutter/ui/components/app_page.dart';
import 'package:yourspace_flutter/ui/components/error_snakebar.dart';
import 'package:yourspace_flutter/ui/flow/message/message_view_model.dart';
import 'package:yourspace_flutter/ui/flow/message/thread_list_view_model.dart';
import 'package:flutter_slidable/flutter_slidable.dart';

import '../../../gen/assets.gen.dart';
import '../../components/alert.dart';

class MessageScreen extends ConsumerStatefulWidget {
class ThreadListScreen extends ConsumerStatefulWidget {
final SpaceInfo spaceInfo;

const MessageScreen({
const ThreadListScreen({
super.key,
required this.spaceInfo,
});

@override
ConsumerState createState() => _MessageScreenState();
ConsumerState createState() => _ThreadListScreenState();
}

class _MessageScreenState extends ConsumerState<MessageScreen> {
late MessageViewNotifier notifier;
class _ThreadListScreenState extends ConsumerState<ThreadListScreen> {
late ThreadListViewNotifier notifier;

@override
void initState() {
super.initState();
runPostFrame(() {
notifier = ref.watch(messageViewStateProvider.notifier);
notifier = ref.watch(threadListViewStateProvider.notifier);
notifier.setSpace(widget.spaceInfo);
notifier.listenThreads(widget.spaceInfo.space.id);
});
}

@override
Widget build(BuildContext context) {
final state = ref.watch(messageViewStateProvider);
final state = ref.watch(threadListViewStateProvider);
_observeInviteScreenNavigation();
_observeError();

Expand All @@ -73,7 +72,7 @@ class _MessageScreenState extends ConsumerState<MessageScreen> {
);
}

Widget _body(BuildContext context, MessageViewState state) {
Widget _body(BuildContext context, ThreadListViewState state) {
if (state.loading) {
return const Center(child: AppProgressIndicator());
}
Expand All @@ -82,11 +81,11 @@ class _MessageScreenState extends ConsumerState<MessageScreen> {
padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 16),
child: state.threadInfo.isEmpty
? _emptyView(context, state)
: _list(context, state.threadInfo),
: _threadList(context, state.threadInfo),
);
}

Widget _list(BuildContext context, List<ThreadInfo> threads) {
Widget _threadList(BuildContext context, List<ThreadInfo> threads) {
return ListView.builder(
itemCount: threads.length,
itemBuilder: (context, index) {
Expand Down Expand Up @@ -281,23 +280,25 @@ class _MessageScreenState extends ConsumerState<MessageScreen> {
: profileImageUrl.isNotEmpty
? CachedNetworkImage(
imageUrl: profileImageUrl,
placeholder: (context, url) => const AppProgressIndicator(
size: AppProgressIndicatorSize.small),
placeholder: (context, url) => ClipRRect(
borderRadius: BorderRadius.circular(size / 2),
child: Icon(Icons.perm_identity_rounded, color: context.colorScheme.textPrimaryDark),
),
fit: BoxFit.cover,
)
: Container(
color: context.colorScheme.primary,
child: Center(
child: Text(firstLetter,
style: AppTextStyle.subtitle2.copyWith(
color: context.colorScheme.textPrimary)),
color: context.colorScheme.textPrimaryDark)),
),
),
),
);
}

Widget _emptyView(BuildContext context, MessageViewState state) {
Widget _emptyView(BuildContext context, ThreadListViewState state) {
if (widget.spaceInfo.members.length >= 2) {
return _emptyMessageView(context);
} else {
Expand All @@ -317,7 +318,7 @@ class _MessageScreenState extends ConsumerState<MessageScreen> {
);
}

Widget _emptyMessageViewWith0Member(BuildContext context, MessageViewState state) {
Widget _emptyMessageViewWith0Member(BuildContext context, ThreadListViewState state) {
return Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
Expand Down Expand Up @@ -356,15 +357,15 @@ class _MessageScreenState extends ConsumerState<MessageScreen> {
}

void _observeInviteScreenNavigation() {
ref.listen(messageViewStateProvider.select((state) => state.spaceInvitationCode), (previous, next) {
ref.listen(threadListViewStateProvider.select((state) => state.spaceInvitationCode), (previous, next) {
if (next.isNotEmpty) {
AppRoute.inviteCode(code: next, spaceName: widget.spaceInfo.space.name).push(context);
}
});
}

void _observeError() {
ref.listen(messageViewStateProvider.select((state) => state.error), (previous, next) {
ref.listen(threadListViewStateProvider.select((state) => state.error), (previous, next) {
if (next != null) {
showErrorSnackBar(context, next.toString());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,26 +8,27 @@ import 'package:freezed_annotation/freezed_annotation.dart';
import 'package:data/service/space_service.dart';
import 'package:data/service/message_service.dart';

part 'message_view_model.freezed.dart';
part 'thread_list_view_model.freezed.dart';

final messageViewStateProvider = StateNotifierProvider.autoDispose<
MessageViewNotifier, MessageViewState>(
(ref) => MessageViewNotifier(
final threadListViewStateProvider = StateNotifierProvider.autoDispose<
ThreadListViewNotifier, ThreadListViewState>(
(ref) => ThreadListViewNotifier(
ref.read(spaceServiceProvider),
ref.read(messageServiceProvider),
ref.read(currentUserPod),
),
);

class MessageViewNotifier extends StateNotifier<MessageViewState> {
class ThreadListViewNotifier extends StateNotifier<ThreadListViewState> {
final SpaceService spaceService;
final MessageService messageService;
final ApiUser? currentUser;

MessageViewNotifier(this.spaceService, this.messageService, this.currentUser) : super(const MessageViewState());
ThreadListViewNotifier(this.spaceService, this.messageService, this.currentUser) : super(const ThreadListViewState());

void setSpace(SpaceInfo space) {
state = state.copyWith(space: space);
listenThreads(space.space.id);
}

void listenThreads(String spaceId) async {
Expand Down Expand Up @@ -77,8 +78,8 @@ class MessageViewNotifier extends StateNotifier<MessageViewState> {
}

@freezed
class MessageViewState with _$MessageViewState {
const factory MessageViewState({
class ThreadListViewState with _$ThreadListViewState {
const factory ThreadListViewState({
@Default(false) bool allowSave,
@Default(false) bool isCreating,
@Default(false) bool loading,
Expand All @@ -89,5 +90,5 @@ class MessageViewState with _$MessageViewState {
@Default([]) List<SpaceInfo> spaceList,
@Default([]) List<ThreadInfo> threadInfo,
Object? error,
}) = _MessageViewState;
}) = _ThreadListViewState;
}
Loading

0 comments on commit 3c666eb

Please sign in to comment.