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' {
export namespace OneRouter {
export interface __routes<T extends string = string> extends Record<string, unknown> {
StaticRoutes: `/` | `/(app)` | `/_sitemap`
StaticRoutes: `/` | `/(app)` | `/(app)/` | `/_sitemap`
DynamicRoutes: never
DynamicRouteTemplate: never
IsTyped: true

View File

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

View File

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