Skip to content

Commit

Permalink
WIP: Like button
Browse files Browse the repository at this point in the history
  • Loading branch information
MattsAttack committed Nov 25, 2024
1 parent 75671e4 commit df7062b
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 0 deletions.
1 change: 1 addition & 0 deletions packages/app/lib/src/app/wrapper_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,7 @@ class _Dialog extends HookConsumerWidget {
description.value,
lat,
lng,
0,
null,
);

Expand Down
3 changes: 3 additions & 0 deletions packages/app/lib/src/features/home/data/post_repository.dart
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ abstract interface class PostRepository {
String? description,
double lat,
double lng,
int numberOfLikes,
String? image,
);
}
Expand Down Expand Up @@ -94,6 +95,7 @@ final class _AppwritePostRepository implements PostRepository {
String? description,
double lat,
double lng,
int numberOfLikes,
String? image,
) async {
await database.createDocument(
Expand All @@ -108,6 +110,7 @@ final class _AppwritePostRepository implements PostRepository {
'authorName': authorName,

Check warning on line 110 in packages/app/lib/src/features/home/data/post_repository.dart

View check run for this annotation

Codecov / codecov/patch

packages/app/lib/src/features/home/data/post_repository.dart#L110

Added line #L110 was not covered by tests
'lat': lat,
'lng': lng,
'numberOfLikes': numberOfLikes,
'timestamp':
DateFormat('yyyy-MM-ddTHH:mm:ss').format(DateTime.timestamp()),

Check warning on line 115 in packages/app/lib/src/features/home/data/post_repository.dart

View check run for this annotation

Codecov / codecov/patch

packages/app/lib/src/features/home/data/post_repository.dart#L115

Added line #L115 was not covered by tests
// TODO(MattAttack): add images
Expand Down
3 changes: 3 additions & 0 deletions packages/app/lib/src/features/home/domain/post_entity.dart
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@ sealed class PostEntity with _$PostEntity {
///
required DateTime timestamp,

///
required int numberOfLikes,

/// An optional media to display alongside the post.
String? image,

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ class Feed extends ConsumerWidget {
authorName: '',
lat: 0,
lng: 0,
numberOfLikes: 0,
timestamp: DateTime.timestamp(),
),
),
Expand Down
39 changes: 39 additions & 0 deletions packages/app/lib/src/features/home/presentation/home/post.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:flutter_hooks/flutter_hooks.dart';
import 'package:hooks_riverpod/hooks_riverpod.dart';

import '../../application/avatar_service.dart';
Expand Down Expand Up @@ -32,6 +33,7 @@ class Post extends StatelessWidget {
_PosterInfo(post: post),
const Divider(color: Colors.white), //TODObase on theme
_PostBody(post: post),
_PostInteractables(post: post),
],
),
),
Expand Down Expand Up @@ -198,3 +200,40 @@ class _PostBody extends StatelessWidget {
}
// coverage:ignore-end
}

class _PostInteractables extends HookWidget {
const _PostInteractables({
required this.post,
// Temporary ignore, see <dart-lang/sdk#49025>.
// ignore: unused_element
super.key,
});

final PostEntity post;

@override
Widget build(BuildContext context) {
final thumbsIcon = useState(const Icon(Icons.thumb_up_outlined));
return Row(
children: [
Text(post.numberOfLikes.toString()),
IconButton(
onPressed: () {
if (thumbsIcon.value.icon == Icons.thumb_up_outlined) {
thumbsIcon.value = const Icon(Icons.thumb_up_sharp);

Check warning on line 223 in packages/app/lib/src/features/home/presentation/home/post.dart

View check run for this annotation

Codecov / codecov/patch

packages/app/lib/src/features/home/presentation/home/post.dart#L221-L223

Added lines #L221 - L223 were not covered by tests
} else {
thumbsIcon.value = const Icon(Icons.thumb_up_outlined);

Check warning on line 225 in packages/app/lib/src/features/home/presentation/home/post.dart

View check run for this annotation

Codecov / codecov/patch

packages/app/lib/src/features/home/presentation/home/post.dart#L225

Added line #L225 was not covered by tests
}
},
icon: thumbsIcon.value,
),
],
);
}

@override
void debugFillProperties(DiagnosticPropertiesBuilder properties) {
super.debugFillProperties(properties);
properties.add(DiagnosticsProperty<PostEntity>('post', post));
}
}

0 comments on commit df7062b

Please sign in to comment.