Skip to content

Commit

Permalink
fix: navigate to the profile from the story (#408)
Browse files Browse the repository at this point in the history
## Description
<!-- Briefly explain the purpose of this PR and what it accomplishes.
-->
- update rule in `build.yaml` to optimize the code generation for
`go_router_builder`
- update routing and navigation logic for the story viewer and the
bottom navbar (the bottom navbar is hidden when we open
StoryViewerRoute)
- pause/resume the story's progress during the routing to `ProfileRoute`

## Additional Notes
<!-- Add any extra context or relevant information here. -->

## Type of Change
- [x] Bug fix
- [ ] New feature
- [ ] Breaking change
- [x] Refactoring
- [ ] Documentation
- [ ] Chore

## Screenshots (if applicable)
<!-- Include screenshots to demonstrate any UI changes. -->
<!-- <img width="180" alt="image" src="image_url_here"> -->



https://github.com/user-attachments/assets/24b87b1b-1bdf-47b0-8bf7-cb1646d80b08
  • Loading branch information
ice-alcides authored Dec 12, 2024
1 parent 8410823 commit d292680
Show file tree
Hide file tree
Showing 6 changed files with 79 additions and 97 deletions.
2 changes: 1 addition & 1 deletion build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ targets:
go_router_builder:go_router_builder:
generate_for:
include:
- lib/**.c.dart
- lib/app/router/**.c.dart
drift_dev:
generate_for:
include:
Expand Down
1 change: 1 addition & 0 deletions lib/app/extensions/go_router_state.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import 'package:ion/app/router/main_tabs/components/tab_item.dart';

extension GoRouterStateExtension on GoRouterState {
bool get isMainModalOpen => matchedLocation.endsWith('/main-modal');
bool get shouldHideBottomBar => fullPath?.contains('fullstack') ?? false;

TabItem get currentTab {
return switch (matchedLocation) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import 'package:hooks_riverpod/hooks_riverpod.dart';
import 'package:ion/app/components/list_item/list_item.dart';
import 'package:ion/app/extensions/extensions.dart';
import 'package:ion/app/features/feed/data/models/entities/post_data.c.dart';
import 'package:ion/app/features/feed/stories/providers/story_pause_provider.c.dart';
import 'package:ion/app/features/feed/stories/views/components/story_viewer/components/header/header.dart';
import 'package:ion/app/features/user/providers/user_metadata_provider.c.dart';
import 'package:ion/app/router/app_routes.c.dart';
Expand Down Expand Up @@ -42,7 +43,11 @@ class StoryViewerHeader extends ConsumerWidget {
left: 16.0.s,
right: 22.0.s,
child: GestureDetector(
onTap: () => StoryProfileRoute(pubkey: currentPost.masterPubkey).push<void>(context),
onTap: () async {
ref.read(storyPauseControllerProvider.notifier).paused = true;
await ProfileRoute(pubkey: currentPost.masterPubkey).push<void>(context);
ref.read(storyPauseControllerProvider.notifier).paused = false;
},
child: ListItem.user(
profilePicture: userMetadata.data.picture,
title: Text(
Expand Down
16 changes: 1 addition & 15 deletions lib/app/router/feed_routes.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ part of 'app_routes.c.dart';

class FeedRoutes {
static const routes = <TypedRoute<RouteData>>[
TypedGoRoute<StoryViewerRoute>(path: 'story-viewing-fullstack/:pubkey'),
TypedGoRoute<PostDetailsRoute>(path: 'post/:eventReference'),
TypedGoRoute<NotificationsHistoryRoute>(path: 'notifications-history'),
TypedGoRoute<ArticleDetailsRoute>(path: 'article/:eventReference'),
Expand Down Expand Up @@ -227,12 +228,6 @@ class StoryPreviewRoute extends BaseRouteData {
final String? mimeType;
}

@TypedGoRoute<StoryViewerRoute>(
path: '/story-viewing/:pubkey',
routes: [
TypedGoRoute<StoryProfileRoute>(path: 'story-profile'),
],
)
class StoryViewerRoute extends BaseRouteData {
StoryViewerRoute({required this.pubkey})
: super(
Expand All @@ -242,15 +237,6 @@ class StoryViewerRoute extends BaseRouteData {
final String pubkey;
}

class StoryProfileRoute extends BaseRouteData {
StoryProfileRoute({required this.pubkey})
: super(
child: ProfilePage(pubkey: pubkey),
);

final String pubkey;
}

class StoryContactsShareRoute extends BaseRouteData {
StoryContactsShareRoute()
: super(
Expand Down
131 changes: 70 additions & 61 deletions lib/app/router/main_tabs/main_tab_navigation.dart
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
// SPDX-License-Identifier: ice License 1.0

import 'dart:async';

import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_hooks/flutter_hooks.dart';
Expand Down Expand Up @@ -33,70 +31,25 @@ class MainTabNavigation extends HookConsumerWidget {
tabPressStream: tabPressStreamController.stream,
child: shell,
),
bottomNavigationBar: Stack(
children: [
Container(
decoration: BoxDecoration(
color: context.theme.appColors.secondaryBackground,
boxShadow: state.isMainModalOpen
? null
: [
BoxShadow(
color: context.theme.appColors.darkBlue.withAlpha(14),
blurRadius: 10,
),
],
),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: TabItem.values.map((tabItem) {
final isSelected = currentTab == tabItem;
bottomNavigationBar: state.shouldHideBottomBar
? null
: _BottomNavBarContent(
state: state,
currentTab: currentTab,
onTabPressed: (tabItem) {
tabPressStreamController.add((current: currentTab, pressed: tabItem));

return Expanded(
child: GestureDetector(
behavior: HitTestBehavior.opaque,
onTap: () =>
_onTabPress(context, tabItem.index, currentTab, tabPressStreamController),
child: Container(
padding: EdgeInsets.only(
top: 9.0.s,
// Adding extra padding to the bottom of the tab bar if the device has a bottom padding
bottom: MediaQuery.of(context).padding.bottom > 0 ? 23.0.s : 9.0.s,
),
color: context.theme.appColors.secondaryBackground,
child: _getTabButton(tabItem, isSelected),
),
),
);
}).toList(),
if (tabItem == TabItem.main) {
_handleMainButtonTap(context, currentTab);
} else {
_navigateToTab(context, tabItem, initialLocation: currentTab == tabItem);
}
},
conversationsEditMode: conversationsEditMode,
),
),
if (conversationsEditMode && currentTab == TabItem.chat)
const ConversationEditBottomBar(),
],
),
);
}

Widget _getTabButton(TabItem tabItem, bool isSelected) {
return tabItem.getIcon(isSelected: isSelected);
}

void _onTabPress(
BuildContext context,
int index,
TabItem currentTab,
StreamController<TabPressSteamData> tabPressStream,
) {
final pressedTab = TabItem.values[index];
tabPressStream.add((current: currentTab, pressed: pressedTab));
if (pressedTab == TabItem.main) {
_handleMainButtonTap(context, currentTab);
} else {
_navigateToTab(context, pressedTab, initialLocation: currentTab == pressedTab);
}
}

void _handleMainButtonTap(BuildContext context, TabItem currentTab) {
HapticFeedback.mediumImpact();

Expand All @@ -110,3 +63,59 @@ class MainTabNavigation extends HookConsumerWidget {
? context.go(tabItem.baseRouteLocation)
: shell.goBranch(tabItem.navigationIndex, initialLocation: initialLocation);
}

class _BottomNavBarContent extends StatelessWidget {
const _BottomNavBarContent({
required this.state,
required this.currentTab,
required this.onTabPressed,
required this.conversationsEditMode,
});

final GoRouterState state;
final TabItem currentTab;
final bool conversationsEditMode;
final ValueChanged<TabItem> onTabPressed;

@override
Widget build(BuildContext context) {
return Stack(
children: [
Container(
decoration: BoxDecoration(
color: context.theme.appColors.secondaryBackground,
boxShadow: state.isMainModalOpen
? null
: [
BoxShadow(
color: context.theme.appColors.darkBlue.withAlpha(14),
blurRadius: 10,
),
],
),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: TabItem.values.map((tabItem) {
final isSelected = currentTab == tabItem;
return Expanded(
child: GestureDetector(
behavior: HitTestBehavior.opaque,
onTap: () => onTabPressed(tabItem),
child: Container(
padding: EdgeInsets.only(
top: 9.0.s,
bottom: MediaQuery.of(context).padding.bottom > 0 ? 23.0.s : 9.0.s,
),
color: context.theme.appColors.secondaryBackground,
child: tabItem.getIcon(isSelected: isSelected),
),
),
);
}).toList(),
),
),
if (conversationsEditMode && currentTab == TabItem.chat) const ConversationEditBottomBar(),
],
);
}
}
19 changes: 0 additions & 19 deletions scripts/create_sed_script.sh

This file was deleted.

0 comments on commit d292680

Please sign in to comment.