Skip to content

Commit 8a4e2ea

Browse files
committed
🔀 Merge branch 'develop'
2 parents fce4419 + 63962b0 commit 8a4e2ea

26 files changed

+765
-289
lines changed

.vscode/settings.json

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
"cSpell.words": [
44
"Combinator",
55
"Cupertino",
6+
"Fuser",
67
"Intelli",
78
"LTRB",
89
"RGBO",
@@ -11,17 +12,33 @@
1112
"Scrollbar",
1213
"Stateful",
1314
"appbar",
15+
"askstories",
1416
"autocorrect",
1517
"autofocus",
18+
"beststories",
1619
"blockquote",
20+
"debouncer",
1721
"dedent",
22+
"dismissible",
1823
"downvoted",
24+
"faved",
25+
"fnid",
26+
"fnop",
27+
"hmac",
1928
"horiz",
29+
"jobstories",
30+
"newstories",
31+
"nosee",
32+
"r'auth",
33+
"r'vote",
2034
"sama",
35+
"showstories",
2136
"sqflite",
2237
"sublist",
2338
"subpages",
2439
"timeago",
40+
"topstories",
41+
"uemail",
2542
"upvote",
2643
"upvoted",
2744
"vsync"

lib/components/comment.dart

Lines changed: 3 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ import 'package:hn_flutter/sdk/actions/hn_item_actions.dart';
1717
import 'package:hn_flutter/sdk/actions/ui_actions.dart';
1818
import 'package:hn_flutter/sdk/models/hn_item.dart';
1919
import 'package:hn_flutter/sdk/models/hn_account.dart';
20-
import 'package:hn_flutter/sdk/services/hn_item_service.dart';
2120

2221
import 'package:hn_flutter/components/simple_markdown.dart';
2322

@@ -135,63 +134,10 @@ class _CommentState extends State<Comment>
135134
}
136135

137136
Future<Null> _reply (BuildContext ctx, HNItemStatus status, HNAccount account) async {
138-
String comment;
139-
comment = await showDialog(
140-
context: ctx,
141-
child: new SimpleDialog(
142-
title: const Text('Reply'),
143-
contentPadding: const EdgeInsets.fromLTRB(16.0, 8.0, 16.0, 8.0),
144-
children: <Widget>[
145-
new TextField(
146-
maxLines: null,
147-
autofocus: true,
148-
autocorrect: true,
149-
keyboardType: TextInputType.text,
150-
decoration: new InputDecoration(
151-
labelText: 'Comment',
152-
),
153-
onChanged: (val) => comment = val,
154-
),
155-
const Padding(
156-
padding: const EdgeInsets.only(top: 8.0),
157-
),
158-
new ButtonTheme.bar(
159-
child: new ButtonBar(
160-
children: <Widget>[
161-
new FlatButton(
162-
child: new Text('Cancel'.toUpperCase()),
163-
onPressed: () => Navigator.pop(ctx),
164-
),
165-
new FlatButton(
166-
child: new Text('Reply'.toUpperCase()),
167-
onPressed: () => Navigator.pop(ctx, comment),
168-
),
169-
],
170-
),
171-
),
172-
],
173-
)
137+
Navigator.pushNamed(
138+
ctx,
139+
'/${Routes.SUBMIT_COMMENT}?parentId=${widget.itemId}&authToken=${status.authTokens.reply}'
174140
);
175-
176-
print(comment);
177-
178-
if (comment != null) {
179-
await this._hnItemService.replyToItemById(
180-
status.id,
181-
comment,
182-
status.authTokens,
183-
account.accessCookie,
184-
).catchError((err) {
185-
Scaffold.of(ctx).showSnackBar(new SnackBar(
186-
content: new Text(err.toString()),
187-
));
188-
throw err;
189-
});
190-
191-
Scaffold.of(ctx).showSnackBar(new SnackBar(
192-
content: new Text('Comment added.'),
193-
));
194-
}
195141
}
196142

197143
void _viewProfile (BuildContext ctx, String author) {

lib/components/hn_editor.dart

Lines changed: 176 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,176 @@
1+
import 'package:flutter/material.dart';
2+
3+
import 'package:flutter_markdown/flutter_markdown.dart' show MarkdownBody;
4+
5+
class HackerNewsEditor extends StatefulWidget {
6+
final String labelText;
7+
final String initialValue;
8+
final ValueChanged<String> onChanged;
9+
10+
HackerNewsEditor ({
11+
this.labelText = 'Text',
12+
this.initialValue,
13+
this.onChanged,
14+
Key key,
15+
}): super(key: key);
16+
17+
@override
18+
createState () => new HackerNewsEditorState();
19+
}
20+
21+
class HackerNewsEditorState extends State<HackerNewsEditor> {
22+
final TextEditingController _controller = new TextEditingController();
23+
24+
@override
25+
void initState () {
26+
super.initState();
27+
28+
this._controller.text = widget.initialValue;
29+
this._controller.addListener(() {
30+
setState(() {});
31+
if (widget.onChanged != null) widget.onChanged(this._controller.text);
32+
});
33+
}
34+
35+
@override
36+
void dispose () {
37+
super.dispose();
38+
this._controller.dispose();
39+
}
40+
41+
String get value => this._controller.text ?? '';
42+
43+
void _padSelection (String padding) {
44+
final selection = this._controller.selection.textInside(this._controller.text);
45+
final modified = '$padding$selection$padding';
46+
final modifiedOffset = this._controller.selection.extentOffset + padding.length * 2;
47+
this._controller.text =
48+
this._controller.selection.textBefore(this._controller.text) +
49+
modified +
50+
this._controller.selection.textAfter(this._controller.text);
51+
this._controller.selection = new TextSelection.fromPosition(new TextPosition(
52+
offset: modifiedOffset,
53+
));
54+
}
55+
56+
void _createBlock (String blockString) {
57+
final selection = this._controller.selection.textInside(this._controller.text);
58+
final modified = selection.replaceAll('\n', '\n$blockString');
59+
this._controller.text =
60+
this._controller.selection.textBefore(this._controller.text) +
61+
'\n$blockString$modified\n' +
62+
this._controller.selection.textAfter(this._controller.text);
63+
}
64+
65+
void _insertQuote () => this._createBlock('> ');
66+
67+
void _insertListBullet () => this._createBlock('- ');
68+
69+
void _insertListNumber () => this._createBlock('1. ');
70+
71+
void _makeSelectionBold () => this._padSelection('**');
72+
73+
void _makeSelectionItalic () => this._padSelection('*');
74+
75+
void _makeSelectionUnderlined () => this._padSelection('__');
76+
77+
void _makeSelectionStruckThrough () => this._padSelection('~~');
78+
79+
@override
80+
Widget build (BuildContext context) {
81+
return new DefaultTabController(
82+
length: 2,
83+
child: new Column(
84+
children: <Widget>[
85+
new Expanded(
86+
child: new TabBarView(
87+
children: <Widget>[
88+
this._buildEditor(context),
89+
this._buildPreview(context),
90+
],
91+
),
92+
),
93+
new Container(
94+
color: Theme.of(context).primaryColor,
95+
child: new TabBar(
96+
tabs: <Tab>[
97+
new Tab(
98+
icon: const Icon(Icons.edit),
99+
),
100+
new Tab(
101+
icon: const Icon(Icons.remove_red_eye),
102+
),
103+
],
104+
),
105+
),
106+
],
107+
),
108+
);
109+
}
110+
111+
Widget _buildEditor (BuildContext context) {
112+
return new Column(
113+
children: <Widget>[
114+
new Expanded(
115+
child: new Padding(
116+
padding: const EdgeInsets.symmetric(vertical: 8.0, horizontal: 16.0),
117+
child: new TextField(
118+
controller: this._controller,
119+
autofocus: true,
120+
autocorrect: true,
121+
keyboardType: TextInputType.multiline,
122+
maxLines: null,
123+
decoration: new InputDecoration(
124+
labelText: widget.labelText,
125+
border: const OutlineInputBorder(),
126+
),
127+
),
128+
),
129+
),
130+
new SizedBox(
131+
height: 48.0,
132+
child: new ListView(
133+
scrollDirection: Axis.horizontal,
134+
children: <Widget>[
135+
new IconButton(
136+
icon: const Icon(Icons.format_bold),
137+
onPressed: _makeSelectionBold,
138+
),
139+
new IconButton(
140+
icon: const Icon(Icons.format_italic),
141+
onPressed: _makeSelectionItalic,
142+
),
143+
new IconButton(
144+
icon: const Icon(Icons.format_quote),
145+
onPressed: this._insertQuote,
146+
),
147+
new IconButton(
148+
icon: const Icon(Icons.format_strikethrough),
149+
onPressed: this._makeSelectionStruckThrough,
150+
),
151+
new IconButton(
152+
icon: const Icon(Icons.format_underlined),
153+
onPressed: this._makeSelectionUnderlined,
154+
),
155+
new IconButton(
156+
icon: const Icon(Icons.format_list_bulleted),
157+
onPressed: this._insertListBullet,
158+
),
159+
new IconButton(
160+
icon: const Icon(Icons.format_list_numbered),
161+
onPressed: this._insertListNumber,
162+
),
163+
],
164+
),
165+
),
166+
],
167+
);
168+
}
169+
170+
Widget _buildPreview (BuildContext context) {
171+
return new Padding(
172+
padding: const EdgeInsets.symmetric(vertical: 8.0, horizontal: 16.0),
173+
child: new MarkdownBody(data: this._controller.text),
174+
);
175+
}
176+
}

lib/components/main_drawer.dart

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -90,9 +90,15 @@ class _MainDrawerState extends State<MainDrawer>
9090
..addAll([
9191
new ListTile(
9292
title: new Text('Add account'),
93-
trailing: new IconButton(
94-
disabledColor: Colors.black45,
95-
icon: const Icon(Icons.add),
93+
trailing: new Padding(
94+
padding: const EdgeInsets.symmetric(
95+
vertical: 8.0,
96+
horizontal: 12.0
97+
),
98+
child: const Icon(
99+
Icons.add,
100+
color: Colors.black45
101+
),
96102
),
97103
onTap: () async {
98104
if (await this._showAddAccountDialog(context) ?? false) {

lib/main.dart

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,22 +2,10 @@ import 'dart:async';
22

33
import 'package:flutter/material.dart';
44
import 'package:flutter/cupertino.dart';
5-
import 'package:flutter/rendering.dart' show
6-
debugPaintSizeEnabled,
7-
debugPaintBaselinesEnabled,
8-
debugPaintLayerBordersEnabled,
9-
debugPaintPointersEnabled,
10-
debugRepaintRainbowEnabled;
11-
12-
import 'package:hn_flutter/pages/settings.dart';
13-
import 'package:hn_flutter/pages/stories.dart';
14-
import 'package:hn_flutter/pages/story.dart';
15-
import 'package:hn_flutter/pages/user.dart';
165

176
import 'package:hn_flutter/router.dart';
187

198
import 'package:hn_flutter/injection/di.dart';
20-
import 'package:hn_flutter/sdk/services/local_storage_service.dart';
219

2210
Future<Null> main () async {
2311
Injector.configure(Flavor.PROD);

lib/pages/settings.dart

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,6 @@
1-
import 'dart:async';
2-
31
import 'package:flutter/material.dart';
42
import 'package:flutter_flux/flutter_flux.dart';
53

6-
import 'package:hn_flutter/components/fab_bottom_padding.dart';
7-
8-
import 'package:hn_flutter/sdk/services/hn_story_service.dart';
9-
import 'package:hn_flutter/sdk/actions/ui_actions.dart';
104
import 'package:hn_flutter/sdk/stores/ui_store.dart';
115

126
class SettingsPage extends StoreWatcher {
@@ -19,10 +13,6 @@ class SettingsPage extends StoreWatcher {
1913
listenToStore(uiStoreToken);
2014
}
2115

22-
Future<Null> _changeSortMode (SortModes sortMode) async {
23-
setStorySortMode(sortMode);
24-
}
25-
2616
@override
2717
Widget build(BuildContext context, Map<StoreToken, Store> stores) {
2818
// This method is rerun every time setState is called, for instance as done
@@ -31,9 +21,6 @@ class SettingsPage extends StoreWatcher {
3121
// The Flutter framework has been optimized to make rerunning build methods
3222
// fast, so that you can just rebuild anything that needs updating rather
3323
// than having to individually change instances of widgets.
34-
final UIStore uiStore = stores[uiStoreToken];
35-
36-
final sortMode = uiStore.sortMode;
3724

3825
return new Scaffold(
3926
appBar: new AppBar(

0 commit comments

Comments
 (0)