Skip to content

Commit ff39039

Browse files
committed
1.3.1+30: Add optionals github & twitter on Profile Page
1 parent 82441cd commit ff39039

File tree

6 files changed

+113
-22
lines changed

6 files changed

+113
-22
lines changed

lib/data/models/user.dart

Lines changed: 44 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,7 @@ import './post.dart';
77
class User {
88
final String? id;
99
final String? name;
10-
final int? streak;
11-
final int? maxStreak;
1210
final int? sats;
13-
final int? stacked;
1411
final int? freePosts;
1512
final int? freeComments;
1613
final int? tipDefault;
@@ -34,22 +31,19 @@ class User {
3431
final bool? greeterMode;
3532
final String? lastCheckedJobs;
3633
final String? typename;
37-
final bool isContributor;
3834

3935
final Post? bio;
4036
final int? nItems;
4137
final int? nComments;
4238
final int? nBookmarks;
4339
final int? photoId;
4440
final int? since;
41+
final UserOptional? optional;
4542

4643
User({
4744
this.id,
4845
this.name,
49-
this.streak,
50-
this.maxStreak,
5146
this.sats,
52-
this.stacked,
5347
this.freePosts,
5448
this.freeComments,
5549
this.tipDefault,
@@ -79,17 +73,14 @@ class User {
7973
this.nBookmarks,
8074
this.photoId,
8175
this.since,
82-
this.isContributor = false,
76+
this.optional,
8377
});
8478

8579
factory User.fromJson(Map<String, dynamic> json) {
8680
return User(
8781
id: json['id'] as String?,
8882
name: json['name'] as String?,
89-
streak: json['optional']?['streak'] as int?,
90-
maxStreak: json['optional']?['maxStreak'] as int?,
9183
sats: json['privates']?['sats'] as int?,
92-
stacked: json['optional']?['stacked'] as int?,
9384
freePosts: json['freePosts'] as int?,
9485
freeComments: json['freeComments'] as int?,
9586
tipDefault: json['privates']?['tipDefault'] as int?,
@@ -119,11 +110,48 @@ class User {
119110
nBookmarks: json['nbookmarks'] as int?,
120111
photoId: json['photoId'] as int?,
121112
since: json['since'] as int?,
122-
isContributor: (json['optional']?['isContributor']) == true,
113+
optional: json['optional'] != null
114+
? UserOptional.fromJson(json['optional'])
115+
: null,
123116
);
124117
}
125118

126119
String get atName => '@$name';
120+
}
121+
122+
class UserOptional {
123+
final int? streak;
124+
final int? maxStreak;
125+
final int? stacked;
126+
final bool isContributor;
127+
final String? typename;
128+
final String? githubId;
129+
final String? nostrAuthPubkey;
130+
final String? twitterId;
131+
132+
UserOptional({
133+
this.streak,
134+
this.maxStreak,
135+
this.stacked,
136+
this.isContributor = false,
137+
this.typename,
138+
this.githubId,
139+
this.nostrAuthPubkey,
140+
this.twitterId,
141+
});
142+
143+
factory UserOptional.fromJson(Map<String, dynamic> json) {
144+
return UserOptional(
145+
streak: json['streak'] as int?,
146+
maxStreak: json['maxStreak'] as int?,
147+
isContributor: (json['isContributor']) == true,
148+
stacked: json['stacked'] as int?,
149+
typename: json['__typename'] as String?,
150+
githubId: json['githubId'] as String?,
151+
nostrAuthPubkey: json['nostrAuthPubkey'] as String?,
152+
twitterId: json['twitterId'] as String?,
153+
);
154+
}
127155

128156
String get satsStacked {
129157
// TODO: Proper exception handling
@@ -135,4 +163,8 @@ class User {
135163
return stacked?.toString() ?? '';
136164
}
137165
}
166+
167+
String get nostr => nostrAuthPubkey == null
168+
? ''
169+
: '${nostrAuthPubkey!.substring(0, 8)}...${nostrAuthPubkey!.split('').reversed.join().substring(0, 8)}';
138170
}

lib/views/pages/profile/bio_header.dart

Lines changed: 56 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import 'package:cached_network_image/cached_network_image.dart';
22
import 'package:flutter/material.dart';
3+
import 'package:font_awesome_flutter/font_awesome_flutter.dart';
34
import 'package:stacker_news/colors.dart';
45
import 'package:stacker_news/data/models/post.dart';
56
import 'package:stacker_news/data/models/user.dart';
@@ -55,12 +56,13 @@ class BioHeader extends StatelessWidget {
5556
user.atName,
5657
style: textTheme.titleLarge,
5758
),
58-
if (user.hideCowboyHat != true && user.streak != null)
59-
CowboyStreak(streak: user.streak!),
59+
if (user.hideCowboyHat != true &&
60+
user.optional?.streak != null)
61+
CowboyStreak(streak: user.optional?.streak!),
6062
],
6163
),
6264
Text(
63-
'${user.satsStacked} sats stacked',
65+
'${user.optional?.satsStacked} sats stacked',
6466
style: textTheme.titleLarge?.copyWith(
6567
color: SNColors.primary.withRed(160),
6668
),
@@ -96,12 +98,13 @@ class BioHeader extends StatelessWidget {
9698
style: label,
9799
),
98100
Text(
99-
'${user.maxStreak ?? ''}',
101+
'${user.optional?.maxStreak ?? ''}',
100102
),
101103
],
102104
),
103-
if (user.isContributor) const SizedBox(height: 8),
104-
if (user.isContributor)
105+
if (user.optional?.isContributor == true)
106+
const SizedBox(height: 8),
107+
if (user.optional?.isContributor == true)
105108
Row(
106109
children: [
107110
const SizedBox(width: 12),
@@ -112,6 +115,53 @@ class BioHeader extends StatelessWidget {
112115
),
113116
],
114117
),
118+
// TODO: Add nostr
119+
// if (user.optional?.nostr != null) const SizedBox(height: 8),
120+
// if (user.optional?.nostr != null)
121+
// Row(
122+
// children: [
123+
// const SizedBox(width: 12),
124+
// const Icon(FontAwesomeIcons.circleCheck, size: 16),
125+
// Text(
126+
// ' ${user.optional?.nostr}',
127+
// style: link,
128+
// ),
129+
// ],
130+
// ),
131+
if (user.optional?.githubId != null)
132+
TextButton.icon(
133+
onPressed: () {
134+
Utils.launchURL(
135+
'https://github.com/${user.optional?.githubId}',
136+
);
137+
},
138+
icon: const Icon(
139+
FontAwesomeIcons.github,
140+
size: 16,
141+
color: SNColors.light,
142+
),
143+
label: Text(
144+
'${user.optional?.githubId}',
145+
style: link,
146+
),
147+
),
148+
if (user.optional?.twitterId != null)
149+
TextButton.icon(
150+
onPressed: () {
151+
Utils.launchURL(
152+
'https://twitter.com/${user.optional?.twitterId}',
153+
);
154+
},
155+
icon: const Icon(
156+
FontAwesomeIcons.twitter,
157+
size: 16,
158+
color: SNColors.light,
159+
),
160+
label: Text(
161+
'${user.optional?.twitterId}',
162+
style: link,
163+
),
164+
),
115165
],
116166
),
117167
],

lib/views/pages/profile/profile_page.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,10 @@ class ProfilePage extends StatefulWidget {
1919
class _ProfilePageState extends State<ProfilePage> {
2020
@override
2121
Widget build(BuildContext context) {
22-
final user = ModalRoute.of(context)?.settings.arguments as String;
22+
final userName = ModalRoute.of(context)?.settings.arguments as String;
2323

2424
return FutureBuilder(
25-
future: locator<Api>().fetchProfile(user),
25+
future: locator<Api>().fetchProfile(userName),
2626
builder: (context, snapshot) {
2727
if (!snapshot.hasData) {
2828
return const GenericPageScaffold(

lib/views/widgets/user_button.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ class UserButton extends StatelessWidget {
2626
style: textTheme.titleSmall?.copyWith(color: Colors.blue),
2727
),
2828
const SizedBox(width: 4),
29-
if (user?.hideCowboyHat != true && user?.streak != null)
29+
if (user?.hideCowboyHat != true && user?.optional?.streak != null)
3030
CowboyHat(color: textTheme.titleSmall?.color),
3131
],
3232
),

pubspec.lock

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -248,6 +248,14 @@ packages:
248248
description: flutter
249249
source: sdk
250250
version: "0.0.0"
251+
font_awesome_flutter:
252+
dependency: "direct main"
253+
description:
254+
name: font_awesome_flutter
255+
sha256: "275ff26905134bcb59417cf60ad979136f1f8257f2f449914b2c3e05bbb4cd6f"
256+
url: "https://pub.dev"
257+
source: hosted
258+
version: "10.7.0"
251259
get_it:
252260
dependency: "direct main"
253261
description:

pubspec.yaml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ description: A new Flutter project.
1111
# In iOS, build-name is used as CFBundleShortVersionString while build-number used as CFBundleVersion.
1212
# Read more about iOS versioning at
1313
# https://developer.apple.com/library/archive/documentation/General/Reference/InfoPlistKeyReference/Articles/CoreFoundationKeys.html
14-
version: 1.3.0+29
14+
version: 1.3.1+30
1515

1616
environment:
1717
sdk: ">=3.4.0 <4.0.0"
@@ -39,6 +39,7 @@ dependencies:
3939
provider: ^6.0.5
4040
intl: ^0.19.0
4141
app_links: ^6.1.1
42+
font_awesome_flutter: ^10.7.0
4243

4344
# dependency_overrides:
4445
# Downgrade markdown to 7.0.2 to fix issue with flutter_markdown footnotes

0 commit comments

Comments
 (0)