refactor(desktop): reorganize workspace panels and navigation
This commit is contained in:
1 parent
826745b407
commit
1f73765745
92 files changed
+5811
-2650
No files matched your search
@@ -1,3 +1,4 @@
|
||||
import 'package:cutdex/shared/widgets/error_notification_host.dart';
|
||||
import 'package:cutdex/errors/app_failure.dart';
|
||||
|
||||
import 'dart:math' as math;
|
||||
@@ -34,6 +35,7 @@ extension MediaFilterLabel on MediaFilter {
|
||||
}
|
||||
|
||||
const maximumMediaGridTileWidth = 160.0;
|
||||
const maximumCompactMediaGridTileWidth = 120.0;
|
||||
|
||||
class MediaBrowserBody extends ConsumerStatefulWidget {
|
||||
const MediaBrowserBody({
|
||||
@@ -41,10 +43,12 @@ class MediaBrowserBody extends ConsumerStatefulWidget {
|
||||
required this.projectId,
|
||||
required this.grid,
|
||||
this.draggable = false,
|
||||
this.compact = false,
|
||||
});
|
||||
final String projectId;
|
||||
final bool grid;
|
||||
final bool draggable;
|
||||
final bool compact;
|
||||
@override
|
||||
ConsumerState<MediaBrowserBody> createState() => _MediaBrowserBodyState();
|
||||
}
|
||||
@@ -82,16 +86,11 @@ class _MediaBrowserBodyState extends ConsumerState<MediaBrowserBody>
|
||||
Future<void> _action(Future<bool> Function() action) async {
|
||||
final ok = await action();
|
||||
if (!mounted || ok) return;
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
SnackBar(
|
||||
content: Text(
|
||||
context.l10n.failureMessage(
|
||||
ref.read(projectsProvider).asData?.value.error ??
|
||||
const AppFailure(AppErrorCode.operationFailed),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
final failure =
|
||||
ref.read(projectsProvider).asData?.value.error ??
|
||||
const AppFailure(AppErrorCode.operationFailed);
|
||||
ErrorNotificationHost.of(context)
|
||||
.showFailure(failure, context.l10n.failureMessage(failure));
|
||||
}
|
||||
|
||||
Future<void> _rename(AssetDocument asset) async {
|
||||
@@ -166,7 +165,17 @@ class _MediaBrowserBodyState extends ConsumerState<MediaBrowserBody>
|
||||
);
|
||||
Widget _buildBrowser(BuildContext context) {
|
||||
ref.watch(externalMediaImportProvider(widget.projectId));
|
||||
final workspace = ref.watch(projectsProvider).asData?.value;
|
||||
ref.watch(
|
||||
projectsProvider.select(
|
||||
(value) => (
|
||||
value.value?.activeProject?.id,
|
||||
value.value?.assets,
|
||||
value.value?.timeline?.id,
|
||||
value.value?.projectBusy,
|
||||
),
|
||||
),
|
||||
);
|
||||
final workspace = ref.read(projectsProvider).value;
|
||||
final active = workspace?.activeProject?.id == widget.projectId;
|
||||
final allAssets = active ? workspace!.assets : <AssetDocument>[];
|
||||
final assets = _filter == MediaFilter.all
|
||||
@@ -197,15 +206,22 @@ class _MediaBrowserBodyState extends ConsumerState<MediaBrowserBody>
|
||||
)
|
||||
: LayoutBuilder(
|
||||
builder: (context, constraints) {
|
||||
const spacing = AppSpacing.small;
|
||||
final width = math.max(
|
||||
1.0,
|
||||
constraints.maxWidth - AppSpacing.compact * 2,
|
||||
);
|
||||
final spacing = widget.compact
|
||||
? AppSpacing.gap
|
||||
: AppSpacing.small;
|
||||
final padding = widget.compact
|
||||
? AppSidebarMetrics.outerPadding
|
||||
: AppSpacing.compact;
|
||||
final width = math.max(1.0, constraints.maxWidth - padding * 2);
|
||||
final columns = math.max(
|
||||
1,
|
||||
((width + spacing) / (maximumMediaGridTileWidth + spacing))
|
||||
.ceil(),
|
||||
widget.compact
|
||||
? ((width + spacing) /
|
||||
(maximumCompactMediaGridTileWidth + spacing))
|
||||
.ceil()
|
||||
: ((width + spacing) /
|
||||
(maximumMediaGridTileWidth + spacing))
|
||||
.ceil(),
|
||||
);
|
||||
final tileWidth = (width - spacing * (columns - 1)) / columns;
|
||||
final textStyle = Theme.of(context).textTheme.bodySmall!;
|
||||
@@ -308,23 +324,26 @@ class _MediaBrowserBodyState extends ConsumerState<MediaBrowserBody>
|
||||
? ListView.separated(
|
||||
key: PageStorageKey(('media-list', widget.projectId)),
|
||||
controller: controller,
|
||||
padding: const EdgeInsets.all(AppSpacing.compact),
|
||||
padding: EdgeInsets.all(padding),
|
||||
itemCount: assets.length,
|
||||
itemBuilder: item,
|
||||
separatorBuilder: (_, _) =>
|
||||
const SizedBox(height: AppSpacing.small),
|
||||
separatorBuilder: (_, _) => SizedBox(height: spacing),
|
||||
)
|
||||
: GridView.builder(
|
||||
key: PageStorageKey(('media-grid', widget.projectId)),
|
||||
controller: controller,
|
||||
padding: const EdgeInsets.all(AppSpacing.compact),
|
||||
padding: EdgeInsets.all(padding),
|
||||
gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(
|
||||
crossAxisCount: columns,
|
||||
crossAxisSpacing: spacing,
|
||||
mainAxisSpacing: AppSpacing.compact,
|
||||
mainAxisSpacing: widget.compact
|
||||
? spacing
|
||||
: AppSpacing.compact,
|
||||
mainAxisExtent:
|
||||
tileWidth * 9 / 16 +
|
||||
AppSpacing.small +
|
||||
(widget.compact
|
||||
? AppSpacing.gap
|
||||
: AppSpacing.small) +
|
||||
labelHeight +
|
||||
2,
|
||||
),
|
||||
@@ -403,7 +422,7 @@ class _MediaBrowserBodyState extends ConsumerState<MediaBrowserBody>
|
||||
],
|
||||
),
|
||||
),
|
||||
const SizedBox(height: AppSpacing.small),
|
||||
SizedBox(height: widget.compact ? AppSpacing.gap : AppSpacing.small),
|
||||
name,
|
||||
],
|
||||
);
|
||||
|
||||
Reference in new issue
Block a user