mirror of
https://github.com/zoriya/Kyoo.git
synced 2025-06-23 15:30:34 -04:00
Rework links for one
This commit is contained in:
parent
f9f0231769
commit
b576e5c7d0
2
front/routes.d.ts
vendored
2
front/routes.d.ts
vendored
@ -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
|
||||
|
@ -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);
|
||||
}}
|
||||
>
|
||||
|
@ -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>
|
||||
);
|
||||
};
|
||||
|
Loading…
x
Reference in New Issue
Block a user