Skip to content

Commit

Permalink
1.3.1+30: Add optionals github & twitter on Profile Page
Browse files Browse the repository at this point in the history
  • Loading branch information
felipebueno committed Jun 7, 2024
1 parent 82441cd commit ff39039
Show file tree
Hide file tree
Showing 6 changed files with 113 additions and 22 deletions.
56 changes: 44 additions & 12 deletions lib/data/models/user.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,7 @@ import './post.dart';
class User {
final String? id;
final String? name;
final int? streak;
final int? maxStreak;
final int? sats;
final int? stacked;
final int? freePosts;
final int? freeComments;
final int? tipDefault;
Expand All @@ -34,22 +31,19 @@ class User {
final bool? greeterMode;
final String? lastCheckedJobs;
final String? typename;
final bool isContributor;

final Post? bio;
final int? nItems;
final int? nComments;
final int? nBookmarks;
final int? photoId;
final int? since;
final UserOptional? optional;

User({
this.id,
this.name,
this.streak,
this.maxStreak,
this.sats,
this.stacked,
this.freePosts,
this.freeComments,
this.tipDefault,
Expand Down Expand Up @@ -79,17 +73,14 @@ class User {
this.nBookmarks,
this.photoId,
this.since,
this.isContributor = false,
this.optional,
});

factory User.fromJson(Map<String, dynamic> json) {
return User(
id: json['id'] as String?,
name: json['name'] as String?,
streak: json['optional']?['streak'] as int?,
maxStreak: json['optional']?['maxStreak'] as int?,
sats: json['privates']?['sats'] as int?,
stacked: json['optional']?['stacked'] as int?,
freePosts: json['freePosts'] as int?,
freeComments: json['freeComments'] as int?,
tipDefault: json['privates']?['tipDefault'] as int?,
Expand Down Expand Up @@ -119,11 +110,48 @@ class User {
nBookmarks: json['nbookmarks'] as int?,
photoId: json['photoId'] as int?,
since: json['since'] as int?,
isContributor: (json['optional']?['isContributor']) == true,
optional: json['optional'] != null
? UserOptional.fromJson(json['optional'])
: null,
);
}

String get atName => '@$name';
}

class UserOptional {
final int? streak;
final int? maxStreak;
final int? stacked;
final bool isContributor;
final String? typename;
final String? githubId;
final String? nostrAuthPubkey;
final String? twitterId;

UserOptional({
this.streak,
this.maxStreak,
this.stacked,
this.isContributor = false,
this.typename,
this.githubId,
this.nostrAuthPubkey,
this.twitterId,
});

factory UserOptional.fromJson(Map<String, dynamic> json) {
return UserOptional(
streak: json['streak'] as int?,
maxStreak: json['maxStreak'] as int?,
isContributor: (json['isContributor']) == true,
stacked: json['stacked'] as int?,
typename: json['__typename'] as String?,
githubId: json['githubId'] as String?,
nostrAuthPubkey: json['nostrAuthPubkey'] as String?,
twitterId: json['twitterId'] as String?,
);
}

String get satsStacked {
// TODO: Proper exception handling
Expand All @@ -135,4 +163,8 @@ class User {
return stacked?.toString() ?? '';
}
}

String get nostr => nostrAuthPubkey == null
? ''
: '${nostrAuthPubkey!.substring(0, 8)}...${nostrAuthPubkey!.split('').reversed.join().substring(0, 8)}';
}
62 changes: 56 additions & 6 deletions lib/views/pages/profile/bio_header.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import 'package:cached_network_image/cached_network_image.dart';
import 'package:flutter/material.dart';
import 'package:font_awesome_flutter/font_awesome_flutter.dart';
import 'package:stacker_news/colors.dart';
import 'package:stacker_news/data/models/post.dart';
import 'package:stacker_news/data/models/user.dart';
Expand Down Expand Up @@ -55,12 +56,13 @@ class BioHeader extends StatelessWidget {
user.atName,
style: textTheme.titleLarge,
),
if (user.hideCowboyHat != true && user.streak != null)
CowboyStreak(streak: user.streak!),
if (user.hideCowboyHat != true &&
user.optional?.streak != null)
CowboyStreak(streak: user.optional?.streak!),
],
),
Text(
'${user.satsStacked} sats stacked',
'${user.optional?.satsStacked} sats stacked',
style: textTheme.titleLarge?.copyWith(
color: SNColors.primary.withRed(160),
),
Expand Down Expand Up @@ -96,12 +98,13 @@ class BioHeader extends StatelessWidget {
style: label,
),
Text(
'${user.maxStreak ?? ''}',
'${user.optional?.maxStreak ?? ''}',
),
],
),
if (user.isContributor) const SizedBox(height: 8),
if (user.isContributor)
if (user.optional?.isContributor == true)
const SizedBox(height: 8),
if (user.optional?.isContributor == true)
Row(
children: [
const SizedBox(width: 12),
Expand All @@ -112,6 +115,53 @@ class BioHeader extends StatelessWidget {
),
],
),
// TODO: Add nostr
// if (user.optional?.nostr != null) const SizedBox(height: 8),
// if (user.optional?.nostr != null)
// Row(
// children: [
// const SizedBox(width: 12),
// const Icon(FontAwesomeIcons.circleCheck, size: 16),
// Text(
// ' ${user.optional?.nostr}',
// style: link,
// ),
// ],
// ),
if (user.optional?.githubId != null)
TextButton.icon(
onPressed: () {
Utils.launchURL(
'https://github.com/${user.optional?.githubId}',
);
},
icon: const Icon(
FontAwesomeIcons.github,
size: 16,
color: SNColors.light,
),
label: Text(
'${user.optional?.githubId}',
style: link,
),
),
if (user.optional?.twitterId != null)
TextButton.icon(
onPressed: () {
Utils.launchURL(
'https://twitter.com/${user.optional?.twitterId}',
);
},
icon: const Icon(
FontAwesomeIcons.twitter,
size: 16,
color: SNColors.light,
),
label: Text(
'${user.optional?.twitterId}',
style: link,
),
),
],
),
],
Expand Down
4 changes: 2 additions & 2 deletions lib/views/pages/profile/profile_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@ class ProfilePage extends StatefulWidget {
class _ProfilePageState extends State<ProfilePage> {
@override
Widget build(BuildContext context) {
final user = ModalRoute.of(context)?.settings.arguments as String;
final userName = ModalRoute.of(context)?.settings.arguments as String;

return FutureBuilder(
future: locator<Api>().fetchProfile(user),
future: locator<Api>().fetchProfile(userName),
builder: (context, snapshot) {
if (!snapshot.hasData) {
return const GenericPageScaffold(
Expand Down
2 changes: 1 addition & 1 deletion lib/views/widgets/user_button.dart
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class UserButton extends StatelessWidget {
style: textTheme.titleSmall?.copyWith(color: Colors.blue),
),
const SizedBox(width: 4),
if (user?.hideCowboyHat != true && user?.streak != null)
if (user?.hideCowboyHat != true && user?.optional?.streak != null)
CowboyHat(color: textTheme.titleSmall?.color),
],
),
Expand Down
8 changes: 8 additions & 0 deletions pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,14 @@ packages:
description: flutter
source: sdk
version: "0.0.0"
font_awesome_flutter:
dependency: "direct main"
description:
name: font_awesome_flutter
sha256: "275ff26905134bcb59417cf60ad979136f1f8257f2f449914b2c3e05bbb4cd6f"
url: "https://pub.dev"
source: hosted
version: "10.7.0"
get_it:
dependency: "direct main"
description:
Expand Down
3 changes: 2 additions & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ description: A new Flutter project.
# In iOS, build-name is used as CFBundleShortVersionString while build-number used as CFBundleVersion.
# Read more about iOS versioning at
# https://developer.apple.com/library/archive/documentation/General/Reference/InfoPlistKeyReference/Articles/CoreFoundationKeys.html
version: 1.3.0+29
version: 1.3.1+30

environment:
sdk: ">=3.4.0 <4.0.0"
Expand Down Expand Up @@ -39,6 +39,7 @@ dependencies:
provider: ^6.0.5
intl: ^0.19.0
app_links: ^6.1.1
font_awesome_flutter: ^10.7.0

# dependency_overrides:
# Downgrade markdown to 7.0.2 to fix issue with flutter_markdown footnotes
Expand Down

0 comments on commit ff39039

Please sign in to comment.