Skip to content
This repository has been archived by the owner on Feb 8, 2025. It is now read-only.

Commit

Permalink
feat(app): use Link for hrefs where possible
Browse files Browse the repository at this point in the history
This allows greater accessibility e.g. middle clicking links
  • Loading branch information
hbriese committed Jan 30, 2024
1 parent ea7e1c9 commit b1df928
Show file tree
Hide file tree
Showing 13 changed files with 260 additions and 263 deletions.
20 changes: 9 additions & 11 deletions app/src/app/(drawer)/[account]/settings.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { useRouter } from 'expo-router';
import { Link, useRouter } from 'expo-router';
import { gql } from '@api/generated';
import { FlashList } from '@shopify/flash-list';
import { EditIcon, NavigateNextIcon } from '@theme/icons';
Expand Down Expand Up @@ -117,17 +117,15 @@ function AccountSettingsScreen() {
</Button>
)}

<Button
mode="contained"
onPress={() =>
router.push({
pathname: `/(drawer)/[account]/policies/[key]/`,
params: { account: account.address, key: 'add' },
})
}
<Link
href={{
pathname: `/(drawer)/[account]/policies/[key]/`,
params: { account: account.address, key: 'add' },
}}
asChild
>
Add policy
</Button>
<Button mode="contained">Add policy</Button>
</Link>
</Actions>
</ScrollableScreenSurface>

Expand Down
24 changes: 11 additions & 13 deletions app/src/app/(drawer)/approvers/[address]/index.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { useRouter } from 'expo-router';
import { Link } from 'expo-router';
import { View } from 'react-native';
import { Actions } from '~/components/layout/Actions';
import { StyleSheet } from 'react-native';
Expand Down Expand Up @@ -55,7 +55,6 @@ const ApproverScreenParams = z.object({ address: zAddress() });

function ApproverScreen() {
const params = useLocalParams(ApproverScreenParams);
const router = useRouter();
const update = useMutation(Update)[1];

const query = useQuery(Query, { approver: params.address });
Expand Down Expand Up @@ -98,18 +97,17 @@ function ApproverScreen() {
</View>

<Actions>
<Button
mode="contained"
icon={QrCodeIcon}
onPress={() =>
router.push({
pathname: `/(modal)/approvers/[address]/qr`,
params: { address: approver.address },
})
}
<Link
href={{
pathname: `/(modal)/approvers/[address]/qr`,
params: { address: approver.address },
}}
asChild
>
View
</Button>
<Button mode="contained" icon={QrCodeIcon}>
View
</Button>
</Link>
</Actions>
</ScrollableScreenSurface>
</>
Expand Down
14 changes: 6 additions & 8 deletions app/src/app/onboard/auth.tsx
Original file line number Diff line number Diff line change
@@ -1,17 +1,15 @@
import { useRouter } from 'expo-router';
import { Button } from 'react-native-paper';
import { Link } from 'expo-router';
import { Button } from '~/components/Button';
import { AuthSettings } from '~/components/shared/AuthSettings';

export default function NotificationsOnboardingScreen() {
const router = useRouter();

return (
<AuthSettings
passwordHref={`/onboard/password`}
passwordHref="/onboard/password"
actions={
<Button mode="contained" onPress={() => router.push(`/onboard/notifications`)}>
Continue
</Button>
<Link href="/onboard/notifications" asChild>
<Button mode="contained">Continue</Button>
</Link>
}
/>
);
Expand Down
8 changes: 5 additions & 3 deletions app/src/components/Button.tsx
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
import { useWithLoading } from '~/hooks/useWithLoading';
import { Keyboard } from 'react-native';
import { Keyboard, View } from 'react-native';
import { Button as PaperButton, ButtonProps as PaperButtonProps } from 'react-native-paper';
import { forwardRef } from 'react';

export interface ButtonProps extends PaperButtonProps {}

export const Button = (props: PaperButtonProps) => {
export const Button = forwardRef<View, PaperButtonProps>((props, ref) => {
const [loading, onPress] = useWithLoading(props.onPress);

return (
<PaperButton
ref={ref}
{...props}
loading={props.loading || (props.loading !== false && loading)}
{...(onPress && {
Expand All @@ -20,4 +22,4 @@ export const Button = (props: PaperButtonProps) => {
})}
/>
);
};
});
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { FragmentType, gql, useFragment } from '@api';
import { PolicyIcon } from '@theme/icons';
import { useRouter } from 'expo-router';
import { Link } from 'expo-router';
import { Suggestion } from '~/components/home/GettingStarted/suggestions';
import { ListItem } from '~/components/list/ListItem';

Expand All @@ -23,21 +23,18 @@ export interface UseCreatePolicySuggestionParams {

export function useCreatePolicySuggestion(props: UseCreatePolicySuggestionParams): Suggestion {
const account = useFragment(Account, props.account);
const router = useRouter();

return {
Item: (props) => (
<ListItem
leading={PolicyIcon}
headline="Create a policy"
onPress={() =>
router.push({
pathname: `/(drawer)/[account]/policies/[key]/`,
params: { account: account.address, key: 'add' },
})
}
{...props}
/>
<Link
href={{
pathname: `/(drawer)/[account]/policies/[key]/`,
params: { account: account.address, key: 'add' },
}}
asChild
>
<ListItem leading={PolicyIcon} headline="Create a policy" {...props} />
</Link>
),
complete: account.policies.filter((p) => p.state).length > 1,
};
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { FragmentType, gql, useFragment } from '@api';
import { useApproverAddress } from '~/lib/network/useApprover';
import { DevicesIcon } from '@theme/icons';
import { useRouter } from 'expo-router';
import { Link } from 'expo-router';
import { Suggestion } from '~/components/home/GettingStarted/suggestions';
import { ListItem } from '~/components/list/ListItem';

Expand All @@ -27,16 +27,12 @@ export interface UseLinkDeviceSuggestionProps {
export function useLinkDeviceSuggestion(props: UseLinkDeviceSuggestionProps): Suggestion {
const user = useFragment(User, props.user);
const approver = useApproverAddress();
const router = useRouter();

return {
Item: (props) => (
<ListItem
leading={DevicesIcon}
headline="Link a device"
onPress={() => router.push(`/link/`)}
{...props}
/>
<Link href="/link" asChild>
<ListItem leading={DevicesIcon} headline="Link a device" {...props} />
</Link>
),
complete: !!user.approvers.find(
(a) => a.address !== approver && !a.bluetoothDevices?.length && !a.cloud,
Expand Down
25 changes: 13 additions & 12 deletions app/src/components/item/UserApproverItem.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { FragmentType, gql, useFragment } from '@api/generated';
import { useApproverAddress } from '~/lib/network/useApprover';
import { useRouter } from 'expo-router';
import { Link } from 'expo-router';
import { ListItem, ListItemProps } from '~/components/list/ListItem';
import { truncateAddr } from '~/util/format';

Expand All @@ -23,19 +23,20 @@ export interface UserApproverItemProps extends Partial<ListItemProps> {

export function UserApproverItem(props: UserApproverItemProps) {
const a = useFragment(UserApprover, props.approver);
const router = useRouter();
const selected = useApproverAddress() === a.address;

return (
<ListItem
leading={a.address}
headline={a.name}
supporting={truncateAddr(a.address)}
{...(selected && { trailing: 'This device' })}
onPress={() =>
router.push({ pathname: `/(drawer)/approvers/[address]/`, params: { address: a.address } })
}
{...props}
/>
<Link
href={{ pathname: `/(drawer)/approvers/[address]/`, params: { address: a.address } }}
asChild
>
<ListItem
leading={a.address}
headline={a.name}
supporting={truncateAddr(a.address)}
{...(selected && { trailing: 'This device' })}
{...props}
/>
</Link>
);
}
Loading

0 comments on commit b1df928

Please sign in to comment.