Rework links for one

This commit is contained in:
Zoe Roux 2025-02-08 15:36:49 +01:00
parent f9f0231769
commit b576e5c7d0
No known key found for this signature in database
3 changed files with 25 additions and 46 deletions

2
front/routes.d.ts vendored
View File

@ -6,7 +6,7 @@ import type { OneRouter } from 'one'
declare module 'one' { declare module 'one' {
export namespace OneRouter { export namespace OneRouter {
export interface __routes<T extends string = string> extends Record<string, unknown> { export interface __routes<T extends string = string> extends Record<string, unknown> {
StaticRoutes: `/` | `/(app)` | `/_sitemap` StaticRoutes: `/` | `/(app)` | `/(app)/` | `/_sitemap`
DynamicRoutes: never DynamicRoutes: never
DynamicRouteTemplate: never DynamicRouteTemplate: never
IsTyped: true IsTyped: true

View File

@ -18,18 +18,16 @@
* along with Kyoo. If not, see <https://www.gnu.org/licenses/>. * along with Kyoo. If not, see <https://www.gnu.org/licenses/>.
*/ */
import type { UrlObject } from "node:url"; import { useLinkTo } from "one";
import { type ReactNode, forwardRef } from "react"; import { type ReactNode, forwardRef } from "react";
import { import {
Linking,
Platform, Platform,
Pressable, Pressable,
type PressableProps, type PressableProps,
Text,
type TextProps, type TextProps,
type View, type View,
} from "react-native"; } from "react-native";
// import { TextLink, useLink } from "solito/link";
// import { parseNextPath } from "solito/router";
import { useTheme, useYoshiki } from "yoshiki/native"; import { useTheme, useYoshiki } from "yoshiki/native";
import { alpha } from "./theme"; import { alpha } from "./theme";
@ -37,47 +35,30 @@ export const A = ({
href, href,
replace, replace,
children, children,
target,
...props ...props
}: TextProps & { }: TextProps & {
href?: string | UrlObject | null; href?: string | null;
target?: string; target?: string;
replace?: boolean; replace?: boolean;
children: ReactNode; children: ReactNode;
}) => { }) => {
const { css, theme } = useYoshiki(); const { css, theme } = useYoshiki();
const linkProps = useLinkTo({ href: href ?? "#", replace });
return ( return (
<TextLink <Text
href={href ?? ""} {...linkProps}
target={target} {...css(
replace={replace as any}
experimental={
replace
? {
nativeBehavior: "stack-replace",
isNestedNavigator: true,
}
: undefined
}
textProps={css(
[
{ {
fontFamily: theme.font.normal, fontFamily: theme.font.normal,
color: theme.link, color: theme.link,
},
{
userSelect: "text", userSelect: "text",
} as any,
],
{
hrefAttrs: { target },
...props,
}, },
props,
)} )}
> >
{children} {children}
</TextLink> </Text>
); );
}; };
@ -102,20 +83,19 @@ export const PressableFeedback = forwardRef<View, PressableProps>(function Feedb
}); });
export const Link = ({ export const Link = ({
href: link, href,
replace, replace,
target,
children, children,
...props ...props
}: { href?: string | UrlObject | null; target?: string; replace?: boolean } & PressableProps) => { }: {
const href = link && typeof link === "object" ? parseNextPath(link) : link; href?: string | null;
const linkProps = useLink({ replace?: boolean;
href: href ?? "#", download?: boolean;
replace, target?: string;
experimental: { nativeBehavior: "stack-replace", isNestedNavigator: true }, } & PressableProps) => {
}); const linkProps = useLinkTo({ href: href ?? "#", replace });
// @ts-ignore Missing hrefAttrs type definition.
linkProps.hrefAttrs = { ...linkProps.hrefAttrs, target }; console.warn(children);
return ( return (
<PressableFeedback <PressableFeedback
{...linkProps} {...linkProps}
@ -123,7 +103,6 @@ export const Link = ({
onPress={(e?: any) => { onPress={(e?: any) => {
props?.onPress?.(e); props?.onPress?.(e);
if (e?.defaultPrevented) return; if (e?.defaultPrevented) return;
if (Platform.OS !== "web" && href?.includes("://")) Linking.openURL(href);
else linkProps.onPress(e); else linkProps.onPress(e);
}} }}
> >

View File

@ -20,7 +20,7 @@ export const Unauthorized = ({ missing }: { missing: string[] }) => {
as={Link} as={Link}
href={"/register"} href={"/register"}
text={t("login.register")} text={t("login.register")}
licon={<Icon icon={Register} {...css({ marginRight: ts(2) })} />} // licon={<Icon icon={Register} {...css({ marginRight: ts(2) })} />}
/> />
</View> </View>
); );
@ -45,7 +45,7 @@ export const Unauthorized = ({ missing }: { missing: string[] }) => {
alignItems: "center", alignItems: "center",
})} })}
> >
<P>{t("errors.unauthorized", { permission: missing?.join(", ") })}</P> <P>{t("errors.unauthorized", { permission: missing?.join(", ") ?? "" })}</P>
</View> </View>
); );
}; };