mirror of
https://github.com/muerwre/vault-frontend.git
synced 2025-04-25 04:46:40 +07:00
made transitional Anchor component for next/cra
This commit is contained in:
parent
8bac6bb2f7
commit
7658068caa
12 changed files with 57 additions and 28 deletions
16
src/components/common/Anchor/index.tsx
Normal file
16
src/components/common/Anchor/index.tsx
Normal file
|
@ -0,0 +1,16 @@
|
||||||
|
import React, { VFC } from 'react';
|
||||||
|
import { LinkProps } from '~/utils/types';
|
||||||
|
import { CONFIG } from '~/utils/config';
|
||||||
|
import NextLink from 'next/link';
|
||||||
|
import { Link } from 'react-router-dom';
|
||||||
|
|
||||||
|
interface AnchorProps extends LinkProps {}
|
||||||
|
|
||||||
|
const Anchor: VFC<AnchorProps> = ({ ref, href, ...rest }) =>
|
||||||
|
CONFIG.isNextEnvironment ? (
|
||||||
|
<NextLink {...rest} href={href ?? ''} />
|
||||||
|
) : (
|
||||||
|
<Link {...rest} to={href ?? ''} />
|
||||||
|
);
|
||||||
|
|
||||||
|
export { Anchor };
|
|
@ -4,9 +4,9 @@ import styles from './styles.module.scss';
|
||||||
import { URLS } from '~/constants/urls';
|
import { URLS } from '~/constants/urls';
|
||||||
import { NodeRelatedItem } from '~/components/node/NodeRelatedItem';
|
import { NodeRelatedItem } from '~/components/node/NodeRelatedItem';
|
||||||
import { getPrettyDate } from '~/utils/dom';
|
import { getPrettyDate } from '~/utils/dom';
|
||||||
import { Link } from 'react-router-dom';
|
|
||||||
import classNames from 'classnames';
|
import classNames from 'classnames';
|
||||||
import { Icon } from '~/components/input/Icon';
|
import { Icon } from '~/components/input/Icon';
|
||||||
|
import { Anchor } from '~/components/common/Anchor';
|
||||||
|
|
||||||
interface IProps {
|
interface IProps {
|
||||||
node: Partial<INode>;
|
node: Partial<INode>;
|
||||||
|
@ -15,7 +15,7 @@ interface IProps {
|
||||||
|
|
||||||
const FlowRecentItem: FC<IProps> = ({ node, has_new }) => {
|
const FlowRecentItem: FC<IProps> = ({ node, has_new }) => {
|
||||||
return (
|
return (
|
||||||
<Link key={node.id} className={styles.item} to={URLS.NODE_URL(node.id)}>
|
<Anchor key={node.id} className={styles.item} href={URLS.NODE_URL(node.id)}>
|
||||||
<div
|
<div
|
||||||
className={classNames(styles.thumb, {
|
className={classNames(styles.thumb, {
|
||||||
[styles.new]: has_new,
|
[styles.new]: has_new,
|
||||||
|
@ -33,7 +33,7 @@ const FlowRecentItem: FC<IProps> = ({ node, has_new }) => {
|
||||||
<span>{getPrettyDate(node.created_at)}</span>
|
<span>{getPrettyDate(node.created_at)}</span>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</Link>
|
</Anchor>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -1,9 +1,10 @@
|
||||||
import React from 'react';
|
import React from 'react';
|
||||||
import styles from './styles.module.scss';
|
import styles from './styles.module.scss';
|
||||||
import { Link } from 'react-router-dom';
|
import { Anchor } from '~/components/common/Anchor';
|
||||||
|
import { URLS } from '~/constants/urls';
|
||||||
|
|
||||||
export const Logo = () => (
|
export const Logo = () => (
|
||||||
<Link className={styles.logo} to="/">
|
<Anchor className={styles.logo} href={URLS.BASE}>
|
||||||
VAULT
|
VAULT
|
||||||
</Link>
|
</Anchor>
|
||||||
);
|
);
|
||||||
|
|
|
@ -4,7 +4,7 @@ import { NodeRelated } from '~/components/node/NodeRelated';
|
||||||
import { URLS } from '~/constants/urls';
|
import { URLS } from '~/constants/urls';
|
||||||
import { INode } from '~/types';
|
import { INode } from '~/types';
|
||||||
import { INodeRelated } from '~/types/node';
|
import { INodeRelated } from '~/types/node';
|
||||||
import { Link } from 'react-router-dom';
|
import { Anchor } from '~/components/common/Anchor';
|
||||||
|
|
||||||
interface IProps {
|
interface IProps {
|
||||||
isLoading: boolean;
|
isLoading: boolean;
|
||||||
|
@ -27,7 +27,9 @@ const NodeRelatedBlock: FC<IProps> = ({ isLoading, node, related }) => {
|
||||||
.map(album => (
|
.map(album => (
|
||||||
<NodeRelated
|
<NodeRelated
|
||||||
title={
|
title={
|
||||||
<Link to={URLS.NODE_TAG_URL(node.id!, encodeURIComponent(album))}>{album}</Link>
|
<Anchor href={URLS.NODE_TAG_URL(node.id!, encodeURIComponent(album))}>
|
||||||
|
{album}
|
||||||
|
</Anchor>
|
||||||
}
|
}
|
||||||
items={related.albums[album]}
|
items={related.albums[album]}
|
||||||
key={album}
|
key={album}
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
import React, { FC } from 'react';
|
import React, { FC } from 'react';
|
||||||
import styles from './styles.module.scss';
|
import styles from './styles.module.scss';
|
||||||
import { Icon } from '~/components/input/Icon';
|
import { Icon } from '~/components/input/Icon';
|
||||||
import { Link } from 'react-router-dom';
|
import { Anchor } from '~/components/common/Anchor';
|
||||||
|
|
||||||
interface IProps {
|
interface IProps {
|
||||||
path: string;
|
path: string;
|
||||||
|
@ -12,10 +12,10 @@ const ProfileSidebarMenu: FC<IProps> = ({ path }) => {
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className={styles.wrap}>
|
<div className={styles.wrap}>
|
||||||
<Link className={styles.row} to={`${cleaned}/settings`}>
|
<Anchor className={styles.row} href={`${cleaned}/settings`}>
|
||||||
<Icon icon="settings" />
|
<Icon icon="settings" />
|
||||||
<span>Настройки</span>
|
<span>Настройки</span>
|
||||||
</Link>
|
</Anchor>
|
||||||
|
|
||||||
<div className={styles.row}>
|
<div className={styles.row}>
|
||||||
<Icon icon="messages" />
|
<Icon icon="messages" />
|
||||||
|
|
|
@ -3,10 +3,10 @@ import { OAuthProvider } from '~/types/auth';
|
||||||
import { CONFIG } from '~/utils/config';
|
import { CONFIG } from '~/utils/config';
|
||||||
|
|
||||||
export const API = {
|
export const API = {
|
||||||
BASE: CONFIG.API_HOST,
|
BASE: CONFIG.apiHost,
|
||||||
USER: {
|
USER: {
|
||||||
LOGIN: '/user/login',
|
LOGIN: '/user/login',
|
||||||
OAUTH_WINDOW: (provider: OAuthProvider) => `${CONFIG.API_HOST}oauth/${provider}/redirect`,
|
OAUTH_WINDOW: (provider: OAuthProvider) => `${CONFIG.apiHost}oauth/${provider}/redirect`,
|
||||||
ME: '/user/',
|
ME: '/user/',
|
||||||
PROFILE: (username: string) => `/user/user/${username}/profile`,
|
PROFILE: (username: string) => `/user/user/${username}/profile`,
|
||||||
MESSAGES: (username: string) => `/user/user/${username}/messages`,
|
MESSAGES: (username: string) => `/user/user/${username}/messages`,
|
||||||
|
|
|
@ -1,5 +1,4 @@
|
||||||
import React, { FC, useCallback, useMemo } from 'react';
|
import React, { FC, useCallback, useMemo } from 'react';
|
||||||
import { Link } from 'react-router-dom';
|
|
||||||
import { Logo } from '~/components/main/Logo';
|
import { Logo } from '~/components/main/Logo';
|
||||||
|
|
||||||
import { Filler } from '~/components/containers/Filler';
|
import { Filler } from '~/components/containers/Filler';
|
||||||
|
@ -19,6 +18,7 @@ import { useModal } from '~/hooks/modal/useModal';
|
||||||
import { useScrollTop } from '~/hooks/dom/useScrollTop';
|
import { useScrollTop } from '~/hooks/dom/useScrollTop';
|
||||||
import { useFlow } from '~/hooks/flow/useFlow';
|
import { useFlow } from '~/hooks/flow/useFlow';
|
||||||
import { useUpdates } from '~/hooks/updates/useUpdates';
|
import { useUpdates } from '~/hooks/updates/useUpdates';
|
||||||
|
import { Anchor } from '~/components/common/Anchor';
|
||||||
|
|
||||||
type HeaderProps = {};
|
type HeaderProps = {};
|
||||||
|
|
||||||
|
@ -62,32 +62,32 @@ const Header: FC<HeaderProps> = observer(() => {
|
||||||
|
|
||||||
<div className={styles.plugs}>
|
<div className={styles.plugs}>
|
||||||
<Authorized>
|
<Authorized>
|
||||||
<Link
|
<Anchor
|
||||||
className={classNames(styles.item, {
|
className={classNames(styles.item, {
|
||||||
[styles.has_dot]: hasFlowUpdates,
|
[styles.has_dot]: hasFlowUpdates,
|
||||||
})}
|
})}
|
||||||
to={URLS.BASE}
|
href={URLS.BASE}
|
||||||
>
|
>
|
||||||
ФЛОУ
|
ФЛОУ
|
||||||
</Link>
|
</Anchor>
|
||||||
|
|
||||||
<Link
|
<Anchor
|
||||||
className={classNames(styles.item, styles.lab, {
|
className={classNames(styles.item, styles.lab, {
|
||||||
[styles.has_dot]: hasLabUpdates,
|
[styles.has_dot]: hasLabUpdates,
|
||||||
})}
|
})}
|
||||||
to={URLS.LAB}
|
href={URLS.LAB}
|
||||||
>
|
>
|
||||||
ЛАБ
|
ЛАБ
|
||||||
</Link>
|
</Anchor>
|
||||||
|
|
||||||
<Link
|
<Anchor
|
||||||
className={classNames(styles.item, styles.boris, {
|
className={classNames(styles.item, styles.boris, {
|
||||||
[styles.has_dot]: hasBorisUpdates,
|
[styles.has_dot]: hasBorisUpdates,
|
||||||
})}
|
})}
|
||||||
to={URLS.BORIS}
|
href={URLS.BORIS}
|
||||||
>
|
>
|
||||||
БОРИС
|
БОРИС
|
||||||
</Link>
|
</Anchor>
|
||||||
</Authorized>
|
</Authorized>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|
|
@ -15,10 +15,13 @@ import { AudioPlayerProvider } from '~/utils/providers/AudioPlayerProvider';
|
||||||
import { MetadataProvider } from '~/utils/providers/MetadataProvider';
|
import { MetadataProvider } from '~/utils/providers/MetadataProvider';
|
||||||
import { AuthProvider } from '~/utils/providers/AuthProvider';
|
import { AuthProvider } from '~/utils/providers/AuthProvider';
|
||||||
import { MainLayout } from '~/containers/main/MainLayout';
|
import { MainLayout } from '~/containers/main/MainLayout';
|
||||||
|
import { useGlobalLoader } from '~/hooks/dom/useGlobalLoader';
|
||||||
|
|
||||||
const mobxStore = getMOBXStore();
|
const mobxStore = getMOBXStore();
|
||||||
|
|
||||||
export default function MyApp({ Component, pageProps }) {
|
export default function MyApp({ Component, pageProps }) {
|
||||||
|
useGlobalLoader();
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<StoreContextProvider store={mobxStore}>
|
<StoreContextProvider store={mobxStore}>
|
||||||
<SWRConfigProvider>
|
<SWRConfigProvider>
|
||||||
|
|
|
@ -13,7 +13,7 @@ export class AuthStore {
|
||||||
makeAutoObservable(this);
|
makeAutoObservable(this);
|
||||||
|
|
||||||
void makePersistable(this, {
|
void makePersistable(this, {
|
||||||
name: `vault48_auth_${CONFIG.API_HOST}`,
|
name: `vault48_auth_${CONFIG.apiHost}`,
|
||||||
properties: ['token', 'user', 'isTesterInternal'],
|
properties: ['token', 'user', 'isTesterInternal'],
|
||||||
storage: typeof window !== 'undefined' ? window.localStorage : undefined,
|
storage: typeof window !== 'undefined' ? window.localStorage : undefined,
|
||||||
});
|
});
|
||||||
|
|
|
@ -1,5 +1,7 @@
|
||||||
export const CONFIG = {
|
export const CONFIG = {
|
||||||
API_HOST: process.env.REACT_APP_API_HOST || process.env.NEXT_PUBLIC_API_HOST || '',
|
apiHost: process.env.REACT_APP_API_HOST || process.env.NEXT_PUBLIC_API_HOST || '',
|
||||||
REMOTE_CURRENT:
|
remoteCurrent:
|
||||||
process.env.REACT_APP_REMOTE_CURRENT || process.env.NEXT_PUBLIC_REMOTE_CURRENT || '',
|
process.env.REACT_APP_REMOTE_CURRENT || process.env.NEXT_PUBLIC_REMOTE_CURRENT || '',
|
||||||
|
// transitional prop, marks migration to nextjs
|
||||||
|
isNextEnvironment: false,
|
||||||
};
|
};
|
||||||
|
|
|
@ -68,10 +68,10 @@ export const getURLFromString = (
|
||||||
size?: typeof PRESETS[keyof typeof PRESETS]
|
size?: typeof PRESETS[keyof typeof PRESETS]
|
||||||
): string => {
|
): string => {
|
||||||
if (size) {
|
if (size) {
|
||||||
return (url || '').replace('REMOTE_CURRENT://', `${CONFIG.REMOTE_CURRENT}cache/${size}/`);
|
return (url || '').replace('REMOTE_CURRENT://', `${CONFIG.remoteCurrent}cache/${size}/`);
|
||||||
}
|
}
|
||||||
|
|
||||||
return (url || '').replace('REMOTE_CURRENT://', CONFIG.REMOTE_CURRENT);
|
return (url || '').replace('REMOTE_CURRENT://', CONFIG.remoteCurrent);
|
||||||
};
|
};
|
||||||
|
|
||||||
export const getURL = (
|
export const getURL = (
|
||||||
|
|
|
@ -16,3 +16,8 @@ export type ButtonProps = React.DetailedHTMLProps<
|
||||||
React.ButtonHTMLAttributes<HTMLButtonElement>,
|
React.ButtonHTMLAttributes<HTMLButtonElement>,
|
||||||
HTMLButtonElement
|
HTMLButtonElement
|
||||||
>;
|
>;
|
||||||
|
|
||||||
|
export type LinkProps = React.DetailedHTMLProps<
|
||||||
|
React.AnchorHTMLAttributes<HTMLAnchorElement>,
|
||||||
|
HTMLAnchorElement
|
||||||
|
>;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue