Skip to content

Commit

Permalink
feat: added support quoting articles
Browse files Browse the repository at this point in the history
  • Loading branch information
ice-kreios committed Jan 3, 2025
1 parent 79d0e30 commit cb80228
Show file tree
Hide file tree
Showing 7 changed files with 97 additions and 32 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class ArticleListItem extends ConsumerWidget {
final eventReference = EventReference.fromNostrEntity(article);

return Padding(
padding: EdgeInsets.symmetric(vertical: 12.0.s),
padding: EdgeInsets.only(top: 12.0.s, bottom: 12.0.s, right: 16.0.s),
child: GestureDetector(
behavior: HitTestBehavior.opaque,
onTap: () =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,10 @@ class GenericRepostListItem extends StatelessWidget {
children: [
RepostAuthorHeader(pubkey: repost.masterPubkey),
SizedBox(height: 6.0.s),
Article(eventReference: eventReference),
Padding(
padding: EdgeInsets.only(right: 16.0.s),
child: Article(eventReference: eventReference),
),
],
),
),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ enum CreatePostOption {
String getTitle(BuildContext context) {
return switch (this) {
CreatePostOption.reply => context.i18n.button_reply,
CreatePostOption.quote => context.i18n.feed_write_comment,
CreatePostOption.quote => context.i18n.feed_quote_post,
CreatePostOption.plain => context.i18n.create_post_modal_title,
CreatePostOption.video => context.i18n.create_video_new_video,
_ => throw ArgumentError()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,19 @@ class QuotedEntity extends HookConsumerWidget {
() {
switch (nostrEntity) {
case PostEntity():
return Post(
eventReference: eventReference,
header: UserInfo(pubkey: eventReference.pubkey),
footer: const SizedBox.shrink(),
return QuotedEntityFrame.post(
child: Post(
eventReference: eventReference,
header: UserInfo(pubkey: eventReference.pubkey),
footer: const SizedBox.shrink(),
),
);
case ArticleEntity():
return Article(eventReference: eventReference);
return QuotedEntityFrame.article(
child: Article.quoted(
eventReference: eventReference,
),
);
default:
return const SizedBox.shrink();
}
Expand All @@ -51,9 +57,7 @@ class QuotedEntity extends HookConsumerWidget {

return Padding(
padding: EdgeInsets.only(left: 40.0.s, top: 16.0.s),
child: QuotedEntityFrame.post(
child: quoteChild,
),
child: quoteChild,
);
}
}
24 changes: 17 additions & 7 deletions lib/app/features/feed/views/components/article/article.dart
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,18 @@ import 'package:ion/app/utils/algorithm.dart';
class Article extends ConsumerWidget {
const Article({
required this.eventReference,
this.showActionButtons = true,
super.key,
});

factory Article.quoted({
required EventReference eventReference,
}) {
return Article(eventReference: eventReference, showActionButtons: false);
}

final bool showActionButtons;

final EventReference eventReference;

@override
Expand Down Expand Up @@ -55,12 +64,14 @@ class Article extends ConsumerWidget {
children: [
UserInfo(
pubkey: eventReference.pubkey,
trailing: Row(
children: [
BookmarkButton.article(eventReference: eventReference),
UserInfoMenu(pubkey: eventReference.pubkey),
],
),
trailing: showActionButtons
? Row(
children: [
BookmarkButton.article(eventReference: eventReference),
UserInfoMenu(pubkey: eventReference.pubkey),
],
)
: null,
),
SizedBox(height: 10.0.s),
ArticleImage(
Expand All @@ -72,7 +83,6 @@ class Article extends ConsumerWidget {
],
),
),
SizedBox(width: 16.0.s),
],
),
),
Expand Down
74 changes: 61 additions & 13 deletions lib/app/features/feed/views/components/post/post.dart
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
// SPDX-License-Identifier: ice License 1.0

import 'package:flutter/material.dart';
import 'package:flutter_hooks/flutter_hooks.dart';
import 'package:hooks_riverpod/hooks_riverpod.dart';
import 'package:ion/app/components/counter_items_footer/counter_items_footer.dart';
import 'package:ion/app/components/skeleton/skeleton.dart';
import 'package:ion/app/extensions/extensions.dart';
import 'package:ion/app/features/feed/data/models/entities/article_data.c.dart';
import 'package:ion/app/features/feed/data/models/entities/post_data.c.dart';
import 'package:ion/app/features/feed/views/components/article/article.dart';
import 'package:ion/app/features/feed/views/components/post/components/post_body/post_body.dart';
import 'package:ion/app/features/feed/views/components/post/post_skeleton.dart';
import 'package:ion/app/features/feed/views/components/quoted_entity_frame/quoted_entity_frame.dart';
Expand Down Expand Up @@ -73,29 +76,74 @@ class Post extends ConsumerWidget {
}
}

class _FramedEvent extends StatelessWidget {
class _FramedEvent extends HookConsumerWidget {
const _FramedEvent({required this.eventReference});

final EventReference eventReference;

@override
Widget build(BuildContext context) {
Widget build(BuildContext context, WidgetRef ref) {
final nostrEntity = ref.watch(nostrEntityProvider(eventReference: eventReference)).valueOrNull;

final quotedEntity = useMemoized(
() {
switch (nostrEntity) {
case PostEntity():
return _QuotedPost(eventReference: eventReference);
case ArticleEntity():
return _QuotedArticle(eventReference: eventReference);
default:
return const SizedBox.shrink();
}
},
[nostrEntity],
);

return Padding(
padding: EdgeInsets.only(top: 6.0.s),
child: QuotedEntityFrame.post(
child: GestureDetector(
// Open a post by clicking on any part of the widget, including the author's avatar or name.
onTap: () =>
PostDetailsRoute(eventReference: eventReference.toString()).push<void>(context),
child: AbsorbPointer(
child: Post(
eventReference: eventReference,
header: UserInfo(pubkey: eventReference.pubkey),
footer: const SizedBox.shrink(),
),
child: quotedEntity,
);
}
}

final class _QuotedPost extends ConsumerWidget {
const _QuotedPost({required this.eventReference});

final EventReference eventReference;

@override
Widget build(BuildContext context, WidgetRef ref) {
return QuotedEntityFrame.post(
child: GestureDetector(
onTap: () {
PostDetailsRoute(eventReference: eventReference.toString()).push<void>(context);
},
child: AbsorbPointer(
child: Post(
eventReference: eventReference,
header: UserInfo(pubkey: eventReference.pubkey),
footer: const SizedBox.shrink(),
),
),
),
);
}
}

final class _QuotedArticle extends ConsumerWidget {
const _QuotedArticle({required this.eventReference});

final EventReference eventReference;

@override
Widget build(BuildContext context, WidgetRef ref) {
return QuotedEntityFrame.article(
child: GestureDetector(
onTap: () {
ArticleDetailsRoute(eventReference: eventReference.toString()).push<void>(context);
},
child: AbsorbPointer(child: Article.quoted(eventReference: eventReference)),
),
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class QuotedEntityFrame extends StatelessWidget {
Key? key,
}) {
return QuotedEntityFrame._(
padding: EdgeInsets.only(left: 0.0.s, right: 16.0.s, bottom: 10.0.s),
padding: EdgeInsets.only(top: 12.0.s, right: 16.0.s, bottom: 12.0.s),
key: key,
child: child,
);
Expand Down

0 comments on commit cb80228

Please sign in to comment.