💄 Better attachments in posts

This commit is contained in:
LittleSheep 2024-07-26 14:21:00 +08:00
parent 0237409d27
commit 6e3d0f9787
9 changed files with 53 additions and 50 deletions

View File

@ -175,10 +175,10 @@ class AuthProvider extends GetConnect {
value: jsonEncode(credentials!.toJson()),
);
await refreshUserProfile();
Get.find<WebSocketProvider>().connect();
Get.find<WebSocketProvider>().notifyPrefetch();
await refreshAuthorizeStatus();
await refreshUserProfile();
return credentials!;
}

View File

@ -82,7 +82,8 @@ class _AccountScreenState extends State<AccountScreen> {
return CenteredContainer(
child: ListView(
children: [
const AccountHeading().paddingOnly(bottom: 8, top: 8),
if (auth.userProfile.value != null)
const AccountHeading().paddingOnly(bottom: 8, top: 8),
...(actionItems.map(
(x) => ListTile(
contentPadding: const EdgeInsets.symmetric(horizontal: 34),
@ -134,7 +135,7 @@ class _AccountHeadingState extends State<AccountHeading> {
final AuthProvider auth = Get.find();
final prof = auth.userProfile.value!;
return AccountHeadingWidget(
avatar: prof['avatar'],
banner: prof['banner'],

View File

@ -25,9 +25,8 @@ class _HomeScreenState extends State<HomeScreen>
@override
void initState() {
Get.lazyPut(() => PostListController());
super.initState();
_postController = Get.find();
_postController = PostListController();
_tabController = TabController(length: 2, vsync: this);
_tabController.addListener(() {
switch (_tabController.index) {
@ -97,7 +96,8 @@ class _HomeScreenState extends State<HomeScreen>
onRefresh: () => _postController.reloadAllOver(),
child: CustomScrollView(slivers: [
FeedListWidget(
controller: _postController.pagingController),
controller: _postController.pagingController,
),
]),
),
PostShuffleSwiper(controller: _postController),

View File

@ -13,6 +13,7 @@ class AttachmentList extends StatefulWidget {
final String parentId;
final List<int> attachmentsId;
final bool isGrid;
final bool isForceGrid;
final double? width;
final double? viewport;
@ -22,6 +23,7 @@ class AttachmentList extends StatefulWidget {
required this.parentId,
required this.attachmentsId,
this.isGrid = false,
this.isForceGrid = false,
this.width,
this.viewport,
});
@ -235,7 +237,9 @@ class _AttachmentListState extends State<AttachmentList> {
);
}
if (widget.isGrid) {
final isNotPureImage = _attachmentsMeta
.any((x) => x?.mimetype.split('/').firstOrNull != 'image');
if (widget.isGrid && (widget.isForceGrid || !isNotPureImage)) {
const radius = BorderRadius.all(Radius.circular(8));
return GridView.builder(
padding: EdgeInsets.zero,
@ -251,16 +255,15 @@ class _AttachmentListState extends State<AttachmentList> {
itemBuilder: (context, idx) {
final element = _attachmentsMeta[idx];
return Container(
decoration: BoxDecoration(
border:
Border.all(color: Theme.of(context).dividerColor, width: 1),
borderRadius: radius,
),
child: ClipRRect(
borderRadius: radius,
child: _buildEntry(element, idx),
)
);
decoration: BoxDecoration(
border:
Border.all(color: Theme.of(context).dividerColor, width: 1),
borderRadius: radius,
),
child: ClipRRect(
borderRadius: radius,
child: _buildEntry(element, idx),
));
},
).paddingSymmetric(horizontal: 24);
}

View File

@ -1,7 +1,6 @@
import 'package:flutter/material.dart';
import 'package:infinite_scroll_pagination/infinite_scroll_pagination.dart';
import 'package:solian/models/post.dart';
import 'package:solian/widgets/sized_container.dart';
import 'package:solian/widgets/posts/post_list.dart';
class FeedListWidget extends StatelessWidget {
@ -25,20 +24,14 @@ class FeedListWidget extends StatelessWidget {
pagingController: controller,
builderDelegate: PagedChildBuilderDelegate<Post>(
itemBuilder: (context, item, index) {
return SizedContainer(
child: Builder(
builder: (context) {
return PostListEntryWidget(
isShowEmbed: isShowEmbed,
isNestedClickable: isNestedClickable,
isClickable: isClickable,
item: item,
onUpdate: () {
controller.refresh();
},
);
},
),
return PostListEntryWidget(
isShowEmbed: isShowEmbed,
isNestedClickable: isNestedClickable,
isClickable: isClickable,
item: item,
onUpdate: () {
controller.refresh();
},
);
},
),

View File

@ -82,7 +82,7 @@ class _AppNavigationDrawerState extends State<AppNavigationDrawer> {
},
children: [
Obx(() {
if (auth.isAuthorized.isFalse) {
if (auth.isAuthorized.isFalse || auth.userProfile.value == null) {
return ListTile(
contentPadding: const EdgeInsets.symmetric(horizontal: 28),
leading: const Icon(Icons.account_circle),
@ -172,7 +172,7 @@ class _AppNavigationDrawerState extends State<AppNavigationDrawer> {
top: 12,
),
Obx(() {
if (auth.isAuthorized.isFalse) {
if (auth.isAuthorized.isFalse || auth.userProfile.value == null) {
return const SizedBox();
}

View File

@ -10,6 +10,7 @@ import 'package:solian/widgets/attachments/attachment_list.dart';
import 'package:solian/widgets/markdown_text_content.dart';
import 'package:solian/widgets/feed/feed_tags.dart';
import 'package:solian/widgets/posts/post_quick_action.dart';
import 'package:solian/widgets/sized_container.dart';
import 'package:timeago/timeago.dart' show format;
class PostItem extends StatefulWidget {
@ -253,10 +254,13 @@ class _PostItemState extends State<PostItem> {
crossAxisAlignment: CrossAxisAlignment.start,
children: [
_buildHeader(),
MarkdownTextContent(
content: item.body['content'],
isSelectable: widget.isContentSelectable,
).paddingOnly(left: 12, right: 8),
SizedContainer(
maxWidth: 640,
child: MarkdownTextContent(
content: item.body['content'],
isSelectable: widget.isContentSelectable,
).paddingOnly(left: 12, right: 8),
),
if (widget.item.replyTo != null && widget.isShowEmbed)
GestureDetector(
child: _buildReply(context).paddingOnly(top: 4),
@ -298,7 +302,6 @@ class _PostItemState extends State<PostItem> {
width: MediaQuery.of(context).size.width,
constraints: const BoxConstraints(
maxHeight: 720,
maxWidth: 640,
),
child: AttachmentList(
parentId: widget.item.id.toString(),

View File

@ -3,6 +3,7 @@ import 'package:flutter_card_swiper/flutter_card_swiper.dart';
import 'package:get/get.dart';
import 'package:solian/controllers/post_list_controller.dart';
import 'package:solian/widgets/posts/post_single_display.dart';
import 'package:solian/widgets/sized_container.dart';
class PostShuffleSwiper extends StatefulWidget {
final PostListController controller;
@ -37,12 +38,14 @@ class _PostShuffleSwiperState extends State<PostShuffleSwiper> {
);
}
final element = widget.controller.postList[index];
return PostSingleDisplay(
key: Key('p${element.id}'),
item: element,
onUpdate: () {
widget.controller.reloadAllOver();
},
return CenteredContainer(
child: PostSingleDisplay(
key: Key('p${element.id}'),
item: element,
onUpdate: () {
widget.controller.reloadAllOver();
},
),
);
},
padding: const EdgeInsets.all(24),

View File

@ -14,10 +14,10 @@ class PostSingleDisplay extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Container(
alignment: Alignment.center,
child: Card(
child: SingleChildScrollView(
return SingleChildScrollView(
child: Container(
alignment: Alignment.center,
child: Card(
child: PostListEntryWidget(
item: item,
isClickable: true,