Skip to content

Commit 79a8ec1

Browse files
committed
2 parents 3a5e7e2 + 503bfa8 commit 79a8ec1

4 files changed

Lines changed: 56 additions & 43 deletions

File tree

lam7a/lib/features/add_tweet/ui/view/add_tweet_screen.dart

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ import 'package:lam7a/features/add_tweet/ui/widgets/add_tweet_header_widget.dart
1212
import 'package:lam7a/features/add_tweet/ui/widgets/add_tweet_toolbar_widget.dart';
1313
import 'package:lam7a/features/tweet/ui/viewmodel/tweet_viewmodel.dart';
1414
import 'package:lam7a/features/tweet/ui/widgets/tweet_body_summary_widget.dart';
15+
import 'package:lam7a/features/profile/ui/viewmodel/profile_posts_viewmodel.dart';
16+
import 'package:lam7a/features/profile/ui/viewmodel/profile_viewmodel.dart';
1517
import 'dart:io';
1618
import 'package:permission_handler/permission_handler.dart';
1719

@@ -579,6 +581,20 @@ class _AddTweetScreenState extends ConsumerState<AddTweetScreen> {
579581
final state = ref.read(addTweetViewmodelProvider);
580582

581583
if (state.isTweetPosted) {
584+
585+
try {
586+
final authState = ref.read(authenticationProvider);
587+
final myUser = authState.user;
588+
589+
if (myUser != null && myUser.id != null) {
590+
final userId = myUser.id.toString();
591+
592+
// Refresh profile lists
593+
ref.invalidate(profilePostsProvider(userId));
594+
ref.invalidate(profileRepliesProvider(userId));
595+
ref.invalidate(profileLikesProvider(userId));
596+
}
597+
} catch (_) {}
582598
// Show success message
583599
ScaffoldMessenger.of(context).showSnackBar(
584600
const SnackBar(

lam7a/lib/features/profile/ui/view/followers_following_page.dart

Lines changed: 4 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -67,45 +67,6 @@ class _FollowersFollowingPageState extends ConsumerState<FollowersFollowingPage>
6767
}
6868
}
6969

70-
// Widget _buildTile(UserModel u) {
71-
// final hasImage = u.profileImageUrl != null && u.profileImageUrl!.isNotEmpty;
72-
// return ListTile(
73-
// contentPadding: const EdgeInsets.symmetric(horizontal: 8),
74-
// leading: CircleAvatar(
75-
// radius: 24,
76-
// backgroundColor: Colors.grey.shade200,
77-
// backgroundImage: hasImage ? NetworkImage(u.profileImageUrl!) : null,
78-
// child: !hasImage ? const Icon(Icons.person, color: Colors.white) : null,
79-
// ),
80-
81-
// title: Row(
82-
// children: [
83-
// Expanded(
84-
// child: Text(u.name ?? "Unknown",
85-
// style: const TextStyle(fontWeight: FontWeight.bold)),
86-
// ),
87-
// // Follow button
88-
// FollowButton(user: u),
89-
// ],
90-
// ),
91-
// subtitle: Text(
92-
// "@${u.username ?? ''}${(u.bio != null && u.bio!.isNotEmpty) ? '\n${u.bio}' : ''}",
93-
// maxLines: 2,
94-
// overflow: TextOverflow.ellipsis,
95-
// ),
96-
// isThreeLine: true,
97-
// onTap: () {
98-
// // navigate to profile and pass username as argument
99-
// Navigator.push(
100-
// context,
101-
// MaterialPageRoute(
102-
// builder: (_) => const ProfileScreen(),
103-
// settings: RouteSettings(arguments: {"username": u.username}),
104-
// ),
105-
// );
106-
// },
107-
// );
108-
// }
10970

11071
Widget _buildTile(UserModel u) {
11172
final hasImage = u.profileImageUrl != null && u.profileImageUrl!.isNotEmpty;
@@ -151,7 +112,10 @@ Widget _buildTile(UserModel u) {
151112
),
152113
),
153114
),
154-
FollowButton(user: u),
115+
FollowButton(
116+
user: u,
117+
onFollowStateChanged: () => _loadData(),
118+
),
155119
],
156120
),
157121
const SizedBox(height: 1),

lam7a/lib/features/profile/ui/widgets/follow_button.dart

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,12 @@ import 'package:lam7a/core/providers/authentication.dart';
77
import 'package:lam7a/features/profile/repository/profile_repository.dart';
88
import 'package:lam7a/features/tweet/ui/viewmodel/tweet_home_viewmodel.dart';
99

10+
1011
class FollowButton extends ConsumerStatefulWidget {
1112
final UserModel user;
13+
final VoidCallback? onFollowStateChanged;
1214

13-
const FollowButton({super.key, required this.user});
15+
const FollowButton({super.key, required this.user, this.onFollowStateChanged});
1416

1517
@override
1618
ConsumerState<FollowButton> createState() => _FollowButtonState();
@@ -20,6 +22,8 @@ class _FollowButtonState extends ConsumerState<FollowButton> {
2022
late UserModel _user;
2123
bool _loading = false;
2224

25+
26+
2327
@override
2428
void initState() {
2529
super.initState();
@@ -65,6 +69,7 @@ class _FollowButtonState extends ConsumerState<FollowButton> {
6569
myUser.copyWith(followingCount: myUser.followingCount + 1),
6670
);
6771
}
72+
widget.onFollowStateChanged?.call();
6873

6974
if (mounted) setState(() {});
7075
} finally {
@@ -81,10 +86,17 @@ class _FollowButtonState extends ConsumerState<FollowButton> {
8186

8287
return OutlinedButton(
8388
onPressed: _loading ? null : _toggle,
84-
style: OutlinedButton.styleFrom(
89+
style: OutlinedButton.styleFrom
90+
(
91+
side: BorderSide(
92+
color: Theme.of(context).brightness == Brightness.light
93+
? Colors.black
94+
: Colors.white,
95+
),
96+
97+
8598
backgroundColor: isFollowing ? Colors.white : Colors.black,
8699
foregroundColor: isFollowing ? Colors.black : Colors.white,
87-
side: const BorderSide(color: Colors.black),
88100
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(20)),
89101
padding: const EdgeInsets.symmetric(
90102
horizontal: 14,

lam7a/lib/features/tweet/ui/widgets/tweet_feed.dart

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@ import 'package:lam7a/features/tweet/ui/viewmodel/tweet_viewmodel.dart';
88
import 'package:lam7a/features/add_tweet/ui/view/add_tweet_screen.dart';
99
import 'package:lam7a/core/providers/authentication.dart';
1010
import 'package:top_snackbar_flutter/top_snack_bar.dart';
11+
import 'package:lam7a/features/profile/ui/viewmodel/profile_posts_viewmodel.dart';
12+
import 'package:lam7a/features/profile/ui/viewmodel/profile_viewmodel.dart';
13+
1114

1215
class TweetFeed extends ConsumerStatefulWidget {
1316
const TweetFeed({super.key, required this.tweetState});
@@ -337,6 +340,15 @@ class _TweetFeedState extends ConsumerState<TweetFeed>
337340
),
338341
onPressed: () {
339342
_showRepostQuoteOptions(context);
343+
344+
final tweet = widget.tweetState.tweet.value;
345+
if (tweet != null && tweet.userId != null){
346+
final userId = tweet.userId.toString();
347+
348+
ref.invalidate(profilePostsProvider(userId));
349+
ref.invalidate(profileRepliesProvider(userId));
350+
ref.invalidate(profileLikesProvider(userId));
351+
}
340352
},
341353
),
342354
),
@@ -406,6 +418,15 @@ class _TweetFeedState extends ConsumerState<TweetFeed>
406418
ref
407419
.read(tweetViewModelProvider(tweetId).notifier)
408420
.handleLike(controller: _controller);
421+
422+
final tweet = widget.tweetState.tweet.value;
423+
if (tweet != null && tweet.userId != null){
424+
final userId = tweet.userId.toString();
425+
426+
ref.invalidate(profilePostsProvider(userId));
427+
ref.invalidate(profileRepliesProvider(userId));
428+
ref.invalidate(profileLikesProvider(userId));
429+
}
409430
},
410431
),
411432
),

0 commit comments

Comments
 (0)