Compare commits
2 Commits
d3148ab89d
...
04b9427cdf
Author | SHA1 | Date | |
---|---|---|---|
04b9427cdf | |||
eab939928f |
@ -274,6 +274,12 @@
|
|||||||
"attachmentUnsetAsPostThumbnail": "Unset as post thumbnail",
|
"attachmentUnsetAsPostThumbnail": "Unset as post thumbnail",
|
||||||
"attachmentSetThumbnail": "Set thumbnail",
|
"attachmentSetThumbnail": "Set thumbnail",
|
||||||
"attachmentUpload": "Upload",
|
"attachmentUpload": "Upload",
|
||||||
|
"notification": "Notification",
|
||||||
|
"notificationUnreadCount": {
|
||||||
|
"zero": "All notifications read",
|
||||||
|
"one": "{} unread notification",
|
||||||
|
"other": "{} unread notifications"
|
||||||
|
},
|
||||||
"notificationUnread": "Unread",
|
"notificationUnread": "Unread",
|
||||||
"notificationRead": "Read",
|
"notificationRead": "Read",
|
||||||
"notificationMarkAllRead": "Mark all notifications as read",
|
"notificationMarkAllRead": "Mark all notifications as read",
|
||||||
@ -424,5 +430,6 @@
|
|||||||
"unauthorizedDescription": "Login to explore the entire Solar Network.",
|
"unauthorizedDescription": "Login to explore the entire Solar Network.",
|
||||||
"serviceStatus": "Service Status",
|
"serviceStatus": "Service Status",
|
||||||
"termRelated": "Related Terms",
|
"termRelated": "Related Terms",
|
||||||
"appDetails": "App Details"
|
"appDetails": "App Details",
|
||||||
|
"postRecommendation": "Highlight Posts"
|
||||||
}
|
}
|
||||||
|
@ -35,7 +35,7 @@
|
|||||||
"errorRequestForbidden": "被禁止的请求,您没有足够的权限去做那件事。",
|
"errorRequestForbidden": "被禁止的请求,您没有足够的权限去做那件事。",
|
||||||
"errorRequestNotFound": "您正查找的资源无法被找到。",
|
"errorRequestNotFound": "您正查找的资源无法被找到。",
|
||||||
"errorRequestConnection": "网络连接错误,请检查您的网络状态或者检查我们的服务状态。",
|
"errorRequestConnection": "网络连接错误,请检查您的网络状态或者检查我们的服务状态。",
|
||||||
"errorRequestUnknown": "位置请求错误,您可能想将此对话框截图并发送给我们。",
|
"errorRequestUnknown": "未知请求错误,您可能想将此对话框截图并发送给我们。",
|
||||||
"unknown": "未知",
|
"unknown": "未知",
|
||||||
"loading": "加载中…",
|
"loading": "加载中…",
|
||||||
"prev": "上一步",
|
"prev": "上一步",
|
||||||
@ -272,6 +272,12 @@
|
|||||||
"attachmentUnsetAsPostThumbnail": "取消设置为帖子缩略图",
|
"attachmentUnsetAsPostThumbnail": "取消设置为帖子缩略图",
|
||||||
"attachmentSetThumbnail": "设置缩略图",
|
"attachmentSetThumbnail": "设置缩略图",
|
||||||
"attachmentUpload": "上传",
|
"attachmentUpload": "上传",
|
||||||
|
"notification": "通知",
|
||||||
|
"notificationUnreadCount": {
|
||||||
|
"zero": "无未读通知",
|
||||||
|
"one": "有 {} 个未读通知",
|
||||||
|
"other": "有 {} 个未读通知"
|
||||||
|
},
|
||||||
"notificationUnread": "未读",
|
"notificationUnread": "未读",
|
||||||
"notificationRead": "已读",
|
"notificationRead": "已读",
|
||||||
"notificationMarkAllRead": "已读所有通知",
|
"notificationMarkAllRead": "已读所有通知",
|
||||||
@ -422,5 +428,6 @@
|
|||||||
"unauthorizedDescription": "登陆以探索整个 Solar Network。",
|
"unauthorizedDescription": "登陆以探索整个 Solar Network。",
|
||||||
"serviceStatus": "服务状态",
|
"serviceStatus": "服务状态",
|
||||||
"termRelated": "相关条款",
|
"termRelated": "相关条款",
|
||||||
"appDetails": "应用程序详情"
|
"appDetails": "应用程序详情",
|
||||||
|
"postRecommendation": "推荐帖子"
|
||||||
}
|
}
|
||||||
|
@ -60,6 +60,14 @@ class SnPostContentProvider {
|
|||||||
return out;
|
return out;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Future<List<SnPost>> listRecommendations() async {
|
||||||
|
final resp = await _sn.client.get('/cgi/co/recommendations');
|
||||||
|
final out = _preloadRelatedDataInBatch(
|
||||||
|
List.from(resp.data.map((ele) => SnPost.fromJson(ele))),
|
||||||
|
);
|
||||||
|
return out;
|
||||||
|
}
|
||||||
|
|
||||||
Future<(List<SnPost>, int)> listPosts({
|
Future<(List<SnPost>, int)> listPosts({
|
||||||
int take = 10,
|
int take = 10,
|
||||||
int offset = 0,
|
int offset = 0,
|
||||||
|
@ -3,16 +3,20 @@ import 'dart:math' as math;
|
|||||||
import 'package:easy_localization/easy_localization.dart';
|
import 'package:easy_localization/easy_localization.dart';
|
||||||
import 'package:flutter_staggered_grid_view/flutter_staggered_grid_view.dart';
|
import 'package:flutter_staggered_grid_view/flutter_staggered_grid_view.dart';
|
||||||
import 'package:gap/gap.dart';
|
import 'package:gap/gap.dart';
|
||||||
|
import 'package:go_router/go_router.dart';
|
||||||
import 'package:google_fonts/google_fonts.dart';
|
import 'package:google_fonts/google_fonts.dart';
|
||||||
import 'package:material_symbols_icons/symbols.dart';
|
import 'package:material_symbols_icons/symbols.dart';
|
||||||
import 'package:provider/provider.dart';
|
import 'package:provider/provider.dart';
|
||||||
import 'package:styled_widget/styled_widget.dart';
|
import 'package:styled_widget/styled_widget.dart';
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:surface/providers/post.dart';
|
||||||
import 'package:surface/providers/sn_network.dart';
|
import 'package:surface/providers/sn_network.dart';
|
||||||
import 'package:surface/providers/userinfo.dart';
|
import 'package:surface/providers/userinfo.dart';
|
||||||
import 'package:surface/types/check_in.dart';
|
import 'package:surface/types/check_in.dart';
|
||||||
|
import 'package:surface/types/post.dart';
|
||||||
import 'package:surface/widgets/app_bar_leading.dart';
|
import 'package:surface/widgets/app_bar_leading.dart';
|
||||||
import 'package:surface/widgets/dialog.dart';
|
import 'package:surface/widgets/dialog.dart';
|
||||||
|
import 'package:surface/widgets/post/post_item.dart';
|
||||||
|
|
||||||
class HomeScreenDashEntry {
|
class HomeScreenDashEntry {
|
||||||
final String name;
|
final String name;
|
||||||
@ -36,10 +40,20 @@ class HomeScreen extends StatefulWidget {
|
|||||||
|
|
||||||
class _HomeScreenState extends State<HomeScreen> {
|
class _HomeScreenState extends State<HomeScreen> {
|
||||||
static const List<HomeScreenDashEntry> kCards = [
|
static const List<HomeScreenDashEntry> kCards = [
|
||||||
|
HomeScreenDashEntry(
|
||||||
|
name: 'dashEntryRecommendation',
|
||||||
|
cols: 2,
|
||||||
|
rows: 2,
|
||||||
|
child: _HomeDashRecommendationPostWidget(),
|
||||||
|
),
|
||||||
HomeScreenDashEntry(
|
HomeScreenDashEntry(
|
||||||
name: 'dashEntryCheckIn',
|
name: 'dashEntryCheckIn',
|
||||||
child: _HomeDashCheckInWidget(),
|
child: _HomeDashCheckInWidget(),
|
||||||
),
|
),
|
||||||
|
HomeScreenDashEntry(
|
||||||
|
name: 'dashEntryNotification',
|
||||||
|
child: _HomeDashNotificationWidget(),
|
||||||
|
),
|
||||||
];
|
];
|
||||||
|
|
||||||
@override
|
@override
|
||||||
@ -52,16 +66,12 @@ class _HomeScreenState extends State<HomeScreen> {
|
|||||||
body: LayoutBuilder(
|
body: LayoutBuilder(
|
||||||
builder: (context, constraints) {
|
builder: (context, constraints) {
|
||||||
return Align(
|
return Align(
|
||||||
alignment: constraints.maxWidth > 640
|
alignment: constraints.maxWidth > 640 ? Alignment.center : Alignment.topCenter,
|
||||||
? Alignment.center
|
|
||||||
: Alignment.topCenter,
|
|
||||||
child: Container(
|
child: Container(
|
||||||
constraints: const BoxConstraints(maxWidth: 640),
|
constraints: const BoxConstraints(maxWidth: 640),
|
||||||
child: SingleChildScrollView(
|
child: SingleChildScrollView(
|
||||||
child: Column(
|
child: Column(
|
||||||
mainAxisAlignment: constraints.maxWidth > 640
|
mainAxisAlignment: constraints.maxWidth > 640 ? MainAxisAlignment.center : MainAxisAlignment.start,
|
||||||
? MainAxisAlignment.center
|
|
||||||
: MainAxisAlignment.start,
|
|
||||||
children: [
|
children: [
|
||||||
if (constraints.maxWidth <= 640) const Gap(8),
|
if (constraints.maxWidth <= 640) const Gap(8),
|
||||||
_HomeDashSpecialDayWidget().padding(top: 8, horizontal: 8),
|
_HomeDashSpecialDayWidget().padding(top: 8, horizontal: 8),
|
||||||
@ -96,9 +106,7 @@ class _HomeDashSpecialDayWidget extends StatelessWidget {
|
|||||||
final ua = context.watch<UserProvider>();
|
final ua = context.watch<UserProvider>();
|
||||||
final today = DateTime.now();
|
final today = DateTime.now();
|
||||||
final birthday = ua.user?.profile?.birthday?.toLocal();
|
final birthday = ua.user?.profile?.birthday?.toLocal();
|
||||||
final isBirthday = birthday != null &&
|
final isBirthday = birthday != null && birthday.day == today.day && birthday.month == today.month;
|
||||||
birthday.day == today.day &&
|
|
||||||
birthday.month == today.month;
|
|
||||||
return Column(
|
return Column(
|
||||||
children: [
|
children: [
|
||||||
if (isBirthday)
|
if (isBirthday)
|
||||||
@ -154,20 +162,15 @@ class _HomeDashCheckInWidgetState extends State<_HomeDashCheckInWidget> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Widget _buildDetailChunk(int index, bool positive) {
|
Widget _buildDetailChunk(int index, bool positive) {
|
||||||
final prefix =
|
final prefix = positive ? 'dailyCheckPositiveHint' : 'dailyCheckNegativeHint';
|
||||||
positive ? 'dailyCheckPositiveHint' : 'dailyCheckNegativeHint';
|
final mod = positive ? kSuggestionPositiveHintCount : kSuggestionNegativeHintCount;
|
||||||
final mod =
|
|
||||||
positive ? kSuggestionPositiveHintCount : kSuggestionNegativeHintCount;
|
|
||||||
final pos = math.max(1, _todayRecord!.resultModifiers[index] % mod);
|
final pos = math.max(1, _todayRecord!.resultModifiers[index] % mod);
|
||||||
return Column(
|
return Column(
|
||||||
crossAxisAlignment: CrossAxisAlignment.start,
|
crossAxisAlignment: CrossAxisAlignment.start,
|
||||||
children: [
|
children: [
|
||||||
Text(
|
Text(
|
||||||
prefix.tr(args: ['$prefix$pos'.tr()]),
|
prefix.tr(args: ['$prefix$pos'.tr()]),
|
||||||
style: Theme.of(context)
|
style: Theme.of(context).textTheme.titleMedium!.copyWith(fontWeight: FontWeight.bold),
|
||||||
.textTheme
|
|
||||||
.titleMedium!
|
|
||||||
.copyWith(fontWeight: FontWeight.bold),
|
|
||||||
).tr(),
|
).tr(),
|
||||||
Text(
|
Text(
|
||||||
'$prefix${pos}Description',
|
'$prefix${pos}Description',
|
||||||
@ -202,10 +205,7 @@ class _HomeDashCheckInWidgetState extends State<_HomeDashCheckInWidget> {
|
|||||||
else
|
else
|
||||||
Text(
|
Text(
|
||||||
'dailyCheckEverythingIsNegative',
|
'dailyCheckEverythingIsNegative',
|
||||||
style: Theme.of(context)
|
style: Theme.of(context).textTheme.titleMedium!.copyWith(fontWeight: FontWeight.bold),
|
||||||
.textTheme
|
|
||||||
.titleMedium!
|
|
||||||
.copyWith(fontWeight: FontWeight.bold),
|
|
||||||
).tr(),
|
).tr(),
|
||||||
const Gap(8),
|
const Gap(8),
|
||||||
if (_todayRecord?.resultTier != 4)
|
if (_todayRecord?.resultTier != 4)
|
||||||
@ -221,10 +221,7 @@ class _HomeDashCheckInWidgetState extends State<_HomeDashCheckInWidget> {
|
|||||||
else
|
else
|
||||||
Text(
|
Text(
|
||||||
'dailyCheckEverythingIsPositive',
|
'dailyCheckEverythingIsPositive',
|
||||||
style: Theme.of(context)
|
style: Theme.of(context).textTheme.titleMedium!.copyWith(fontWeight: FontWeight.bold),
|
||||||
.textTheme
|
|
||||||
.titleMedium!
|
|
||||||
.copyWith(fontWeight: FontWeight.bold),
|
|
||||||
).tr(),
|
).tr(),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
@ -338,14 +335,28 @@ class _HomeDashCheckInWidgetState extends State<_HomeDashCheckInWidget> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class _HomeDashLinkWidget extends StatelessWidget {
|
class _HomeDashNotificationWidget extends StatefulWidget {
|
||||||
final String title;
|
const _HomeDashNotificationWidget({super.key});
|
||||||
final String subtitle;
|
|
||||||
const _HomeDashLinkWidget({
|
@override
|
||||||
super.key,
|
State<_HomeDashNotificationWidget> createState() => _HomeDashNotificationWidgetState();
|
||||||
required this.title,
|
}
|
||||||
required this.subtitle,
|
|
||||||
});
|
class _HomeDashNotificationWidgetState extends State<_HomeDashNotificationWidget> {
|
||||||
|
int? _count;
|
||||||
|
|
||||||
|
Future<void> _fetchNotificationCount() async {
|
||||||
|
final sn = context.read<SnNetworkProvider>();
|
||||||
|
final resp = await sn.client.get('/cgi/id/notifications/count');
|
||||||
|
_count = resp.data['count'];
|
||||||
|
setState(() {});
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
void initState() {
|
||||||
|
super.initState();
|
||||||
|
_fetchNotificationCount();
|
||||||
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
@ -358,11 +369,11 @@ class _HomeDashLinkWidget extends StatelessWidget {
|
|||||||
crossAxisAlignment: CrossAxisAlignment.start,
|
crossAxisAlignment: CrossAxisAlignment.start,
|
||||||
children: [
|
children: [
|
||||||
Text(
|
Text(
|
||||||
title,
|
'notification',
|
||||||
style: Theme.of(context).textTheme.titleLarge,
|
style: Theme.of(context).textTheme.titleLarge,
|
||||||
),
|
).tr(),
|
||||||
Text(
|
Text(
|
||||||
subtitle,
|
_count == null ? 'loading'.tr() : 'notificationUnreadCount'.plural(_count ?? 0),
|
||||||
style: Theme.of(context).textTheme.bodyLarge,
|
style: Theme.of(context).textTheme.bodyLarge,
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
@ -377,7 +388,9 @@ class _HomeDashLinkWidget extends StatelessWidget {
|
|||||||
),
|
),
|
||||||
child: IconButton(
|
child: IconButton(
|
||||||
icon: const Icon(Symbols.arrow_right_alt),
|
icon: const Icon(Symbols.arrow_right_alt),
|
||||||
onPressed: () {},
|
onPressed: () {
|
||||||
|
GoRouter.of(context).goNamed('notification');
|
||||||
|
},
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
@ -386,3 +399,75 @@ class _HomeDashLinkWidget extends StatelessWidget {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
class _HomeDashRecommendationPostWidget extends StatefulWidget {
|
||||||
|
const _HomeDashRecommendationPostWidget({super.key});
|
||||||
|
|
||||||
|
@override
|
||||||
|
State<_HomeDashRecommendationPostWidget> createState() => _HomeDashRecommendationPostWidgetState();
|
||||||
|
}
|
||||||
|
|
||||||
|
class _HomeDashRecommendationPostWidgetState extends State<_HomeDashRecommendationPostWidget> {
|
||||||
|
bool _isBusy = false;
|
||||||
|
List<SnPost>? _posts;
|
||||||
|
|
||||||
|
Future<void> _fetchRecommendationPosts() async {
|
||||||
|
setState(() => _isBusy = true);
|
||||||
|
try {
|
||||||
|
final pt = context.read<SnPostContentProvider>();
|
||||||
|
_posts = await pt.listRecommendations();
|
||||||
|
} catch (err) {
|
||||||
|
if (!mounted) return;
|
||||||
|
context.showErrorDialog(err);
|
||||||
|
} finally {
|
||||||
|
setState(() => _isBusy = false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
void initState() {
|
||||||
|
super.initState();
|
||||||
|
_fetchRecommendationPosts();
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) {
|
||||||
|
if (_isBusy) {
|
||||||
|
return Card(
|
||||||
|
child: CircularProgressIndicator().center(),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
return Card(
|
||||||
|
child: Column(
|
||||||
|
crossAxisAlignment: CrossAxisAlignment.start,
|
||||||
|
children: [
|
||||||
|
Text(
|
||||||
|
'postRecommendation',
|
||||||
|
style: Theme.of(context).textTheme.titleLarge,
|
||||||
|
).tr().padding(horizontal: 20, top: 16, bottom: 8),
|
||||||
|
Expanded(
|
||||||
|
child: PageView.builder(
|
||||||
|
itemCount: _posts?.length ?? 0,
|
||||||
|
itemBuilder: (context, index) {
|
||||||
|
return SingleChildScrollView(
|
||||||
|
child: GestureDetector(
|
||||||
|
child: PostItem(
|
||||||
|
data: _posts![index],
|
||||||
|
showMenu: false,
|
||||||
|
).padding(left: 8, right: 8, bottom: 8),
|
||||||
|
onTap: () {
|
||||||
|
GoRouter.of(context).pushNamed('postDetail', pathParameters: {
|
||||||
|
'slug': _posts![index].id.toString(),
|
||||||
|
});
|
||||||
|
},
|
||||||
|
),
|
||||||
|
);
|
||||||
|
},
|
||||||
|
),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -1,8 +1,4 @@
|
|||||||
import 'dart:io';
|
|
||||||
|
|
||||||
import 'package:flutter/foundation.dart';
|
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:path_provider/path_provider.dart';
|
|
||||||
import 'package:shared_preferences/shared_preferences.dart';
|
import 'package:shared_preferences/shared_preferences.dart';
|
||||||
|
|
||||||
const kMaterialYouToggleStoreKey = 'app_theme_material_you';
|
const kMaterialYouToggleStoreKey = 'app_theme_material_you';
|
||||||
|
@ -60,8 +60,7 @@ class _AppNavigationDrawerState extends State<AppNavigationDrawer> {
|
|||||||
],
|
],
|
||||||
).padding(
|
).padding(
|
||||||
horizontal: 32,
|
horizontal: 32,
|
||||||
top: MediaQuery.of(context).padding.top + 12,
|
vertical: 12,
|
||||||
bottom: 12,
|
|
||||||
),
|
),
|
||||||
...destinations.where((ele) => ele.isPinned).map((ele) {
|
...destinations.where((ele) => ele.isPinned).map((ele) {
|
||||||
return NavigationDrawerDestination(
|
return NavigationDrawerDestination(
|
||||||
|
@ -720,32 +720,35 @@ class _PostTruncatedHint extends StatelessWidget {
|
|||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return Row(
|
return SingleChildScrollView(
|
||||||
children: [
|
scrollDirection: Axis.horizontal,
|
||||||
if (data.body['content_length'] != null)
|
child: Row(
|
||||||
Row(
|
children: [
|
||||||
children: [
|
if (data.body['content_length'] != null)
|
||||||
const Icon(Symbols.timer, size: 20),
|
Row(
|
||||||
const Gap(4),
|
children: [
|
||||||
Text('postReadEstimate').tr(args: [
|
const Icon(Symbols.timer, size: 20),
|
||||||
'${Duration(
|
const Gap(4),
|
||||||
seconds: (data.body['content_length'] as num).toDouble() * 60 ~/ kHumanReadSpeed,
|
Text('postReadEstimate').tr(args: [
|
||||||
).inSeconds}s',
|
'${Duration(
|
||||||
]),
|
seconds: (data.body['content_length'] as num).toDouble() * 60 ~/ kHumanReadSpeed,
|
||||||
],
|
).inSeconds}s',
|
||||||
).padding(right: 8),
|
]),
|
||||||
if (data.body['content_length'] != null)
|
],
|
||||||
Row(
|
).padding(right: 8),
|
||||||
children: [
|
if (data.body['content_length'] != null)
|
||||||
const Icon(Symbols.height, size: 20),
|
Row(
|
||||||
const Gap(4),
|
children: [
|
||||||
Text(
|
const Icon(Symbols.height, size: 20),
|
||||||
'postTotalLength'.plural(data.body['content_length']),
|
const Gap(4),
|
||||||
)
|
Text(
|
||||||
],
|
'postTotalLength'.plural(data.body['content_length']),
|
||||||
),
|
)
|
||||||
],
|
],
|
||||||
).opacity(0.75);
|
),
|
||||||
|
],
|
||||||
|
).opacity(0.75),
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user