fix: responsive

This commit is contained in:
Sonny
2024-05-29 18:10:17 +02:00
committed by Sonny
parent f2478bcf56
commit e9ccefd938
16 changed files with 183 additions and 52 deletions

View File

@@ -54,13 +54,21 @@ export default class FaviconsController {
throw new FaviconNotFoundException(`No favicon path found in ${url}`); throw new FaviconNotFoundException(`No favicon path found in ${url}`);
} }
if (faviconPath.startsWith('http')) {
try {
return await this.fetchFavicon(faviconPath);
} catch {
logger.debug(`Unable to retrieve favicon from ${faviconPath}`);
}
}
return this.fetchFaviconFromPath(url, faviconPath); return this.fetchFaviconFromPath(url, faviconPath);
} }
private async fetchFavicon(url: string): Promise<Favicon> { private async fetchFavicon(url: string): Promise<Favicon> {
const response = await this.fetchWithUserAgent(url); const response = await this.fetchWithUserAgent(url);
if (!response.ok) { if (!response.ok) {
throw new FaviconNotFoundException(`Request to ${url} failed`); throw new FaviconNotFoundException(`Request to favicon ${url} failed`);
} }
const blob = await response.blob(); const blob = await response.blob();

View File

@@ -1,12 +1,11 @@
import { resolvePageComponent } from '@adonisjs/inertia/helpers'; import { resolvePageComponent } from '@adonisjs/inertia/helpers';
import { createInertiaApp } from '@inertiajs/react'; import { createInertiaApp } from '@inertiajs/react';
import { hydrateRoot } from 'react-dom/client';
import 'react-toggle/style.css';
import { primaryColor } from '~/styles/theme';
import '../i18n/index';
import 'dayjs/locale/en'; import 'dayjs/locale/en';
import 'dayjs/locale/fr'; import 'dayjs/locale/fr';
import { hydrateRoot } from 'react-dom/client';
import 'react-toggle/style.css';
import { primaryColor } from '~/styles/common_colors';
import '../i18n/index';
const appName = import.meta.env.VITE_APP_NAME || 'MyLinks'; const appName = import.meta.env.VITE_APP_NAME || 'MyLinks';

View File

@@ -1,10 +1,17 @@
import styled from '@emotion/styled'; import styled from '@emotion/styled';
import { ReactNode } from 'react';
import CollectionHeader from '~/components/dashboard/collection/header/collection_header'; import CollectionHeader from '~/components/dashboard/collection/header/collection_header';
import LinkList from '~/components/dashboard/link/link_list'; import LinkList from '~/components/dashboard/link/link_list';
import { NoCollection } from '~/components/dashboard/link/no_item'; import { NoCollection } from '~/components/dashboard/link/no_item';
import Footer from '~/components/footer/footer'; import Footer from '~/components/footer/footer';
import useActiveCollection from '~/hooks/use_active_collection'; import useActiveCollection from '~/hooks/use_active_collection';
export interface CollectionHeaderProps {
openNavigationItem: ReactNode;
openCollectionItem: ReactNode;
showButtons: boolean;
}
const CollectionContainerStyle = styled.div({ const CollectionContainerStyle = styled.div({
height: '100%', height: '100%',
minWidth: 0, minWidth: 0,
@@ -14,15 +21,7 @@ const CollectionContainerStyle = styled.div({
flexDirection: 'column', flexDirection: 'column',
}); });
interface CollectionContainerProps { export default function CollectionContainer(props: CollectionHeaderProps) {
isMobile: boolean;
openSideMenu: () => void;
}
export default function CollectionContainer({
isMobile: _,
openSideMenu: __,
}: Readonly<CollectionContainerProps>) {
const { activeCollection } = useActiveCollection(); const { activeCollection } = useActiveCollection();
if (activeCollection === null) { if (activeCollection === null) {
@@ -31,7 +30,7 @@ export default function CollectionContainer({
return ( return (
<CollectionContainerStyle> <CollectionContainerStyle>
<CollectionHeader /> <CollectionHeader {...props} />
<LinkList links={activeCollection.links} /> <LinkList links={activeCollection.links} />
<Footer css={{ paddingBottom: 0 }} /> <Footer css={{ paddingBottom: 0 }} />
</CollectionContainerStyle> </CollectionContainerStyle>

View File

@@ -11,10 +11,8 @@ const CollectionDescriptionStyle = styled.div({
export default function CollectionDescription() { export default function CollectionDescription() {
const { activeCollection } = useActiveCollection(); const { activeCollection } = useActiveCollection();
return ( return (
activeCollection && (
<CollectionDescriptionStyle> <CollectionDescriptionStyle>
<TextEllipsis lines={3}>{activeCollection?.description}</TextEllipsis> <TextEllipsis lines={3}>{activeCollection!.description}</TextEllipsis>
</CollectionDescriptionStyle> </CollectionDescriptionStyle>
)
); );
} }

View File

@@ -2,6 +2,7 @@ import styled from '@emotion/styled';
import { Fragment } from 'react'; import { Fragment } from 'react';
import { useTranslation } from 'react-i18next'; import { useTranslation } from 'react-i18next';
import TextEllipsis from '~/components/common/text_ellipsis'; import TextEllipsis from '~/components/common/text_ellipsis';
import { CollectionHeaderProps } from '~/components/dashboard/collection/collection_container';
import CollectionControls from '~/components/dashboard/collection/header/collection_controls'; import CollectionControls from '~/components/dashboard/collection/header/collection_controls';
import CollectionDescription from '~/components/dashboard/collection/header/collection_description'; import CollectionDescription from '~/components/dashboard/collection/header/collection_description';
import VisibilityBadge from '~/components/visibilty/visibilty'; import VisibilityBadge from '~/components/visibilty/visibilty';
@@ -10,11 +11,13 @@ import useActiveCollection from '~/hooks/use_active_collection';
const paddingLeft = '1.25em'; const paddingLeft = '1.25em';
const paddingRight = '1.65em'; const paddingRight = '1.65em';
const CollectionHeaderWrapper = styled.div({ const CollectionHeaderWrapper = styled.div<{ padding?: boolean }>(
({ padding }) => ({
minWidth: 0, minWidth: 0,
width: '100%', width: '100%',
paddingInline: `${paddingLeft} ${paddingRight}`, paddingInline: padding ? `${paddingLeft} ${paddingRight}` : 0,
}); })
);
const CollectionHeaderStyle = styled.div({ const CollectionHeaderStyle = styled.div({
display: 'flex', display: 'flex',
@@ -41,7 +44,11 @@ const LinksCount = styled.div(({ theme }) => ({
color: theme.colors.grey, color: theme.colors.grey,
})); }));
export default function CollectionHeader() { export default function CollectionHeader({
openNavigationItem,
openCollectionItem,
showButtons,
}: CollectionHeaderProps) {
const { t } = useTranslation('common'); const { t } = useTranslation('common');
const { activeCollection } = useActiveCollection(); const { activeCollection } = useActiveCollection();
@@ -51,6 +58,7 @@ export default function CollectionHeader() {
return ( return (
<CollectionHeaderWrapper> <CollectionHeaderWrapper>
<CollectionHeaderStyle> <CollectionHeaderStyle>
{showButtons && openNavigationItem && openNavigationItem}
<CollectionName title={name}> <CollectionName title={name}>
<TextEllipsis>{name}</TextEllipsis> <TextEllipsis>{name}</TextEllipsis>
{links.length > 0 && <LinksCount> {links.length}</LinksCount>} {links.length > 0 && <LinksCount> {links.length}</LinksCount>}
@@ -60,8 +68,9 @@ export default function CollectionHeader() {
/> />
</CollectionName> </CollectionName>
<CollectionControls collectionId={activeCollection.id} /> <CollectionControls collectionId={activeCollection.id} />
{showButtons && openCollectionItem && openCollectionItem}
</CollectionHeaderStyle> </CollectionHeaderStyle>
<CollectionDescription /> {activeCollection.description && <CollectionDescription />}
</CollectionHeaderWrapper> </CollectionHeaderWrapper>
); );
} }

View File

@@ -8,6 +8,8 @@ import useShortcut from '~/hooks/use_shortcut';
const SideMenu = styled.nav(({ theme }) => ({ const SideMenu = styled.nav(({ theme }) => ({
height: '100%', height: '100%',
width: '300px',
backgroundColor: theme.colors.background,
paddingLeft: '10px', paddingLeft: '10px',
marginLeft: '5px', marginLeft: '5px',
borderLeft: `1px solid ${theme.colors.lightGrey}`, borderLeft: `1px solid ${theme.colors.lightGrey}`,

View File

@@ -81,7 +81,7 @@ export default function LinkItem({
}) { }) {
const { id, name, url, description, favorite } = link; const { id, name, url, description, favorite } = link;
return ( return (
<LinkWrapper key={id}> <LinkWrapper key={id} title={name}>
<LinkHeader> <LinkHeader>
<LinkFavicon url={url} /> <LinkFavicon url={url} />
<ExternalLink href={url} className="reset"> <ExternalLink href={url} className="reset">

View File

@@ -5,7 +5,7 @@ import { rgba } from '~/lib/color';
export const Item = styled.div(({ theme }) => ({ export const Item = styled.div(({ theme }) => ({
userSelect: 'none', userSelect: 'none',
height: '40px', height: '40px',
width: '250px', width: '100%',
color: theme.colors.font, color: theme.colors.font,
backgroundColor: theme.colors.background, backgroundColor: theme.colors.background,
padding: '8px 12px', padding: '8px 12px',

View File

@@ -13,12 +13,16 @@ import useUser from '~/hooks/use_user';
import { rgba } from '~/lib/color'; import { rgba } from '~/lib/color';
import { appendCollectionId } from '~/lib/navigation'; import { appendCollectionId } from '~/lib/navigation';
const SideMenu = styled.nav({ const SideMenu = styled.nav(({ theme }) => ({
height: '100%', height: '100%',
width: '300px',
backgroundColor: theme.colors.background,
borderRight: `1px solid ${theme.colors.lightGrey}`,
marginRight: '5px',
display: 'flex', display: 'flex',
gap: '.35em', gap: '.35em',
flexDirection: 'column', flexDirection: 'column',
}); }));
const AdminButton = styled(ItemLink)(({ theme }) => ({ const AdminButton = styled(ItemLink)(({ theme }) => ({
color: theme.colors.lightRed, color: theme.colors.lightRed,

View File

@@ -14,6 +14,7 @@ const ContentLayoutStyle = styled(TransitionLayout)(({ theme }) => ({
flexDirection: 'column', flexDirection: 'column',
'& main': { '& main': {
width: '100%',
flex: 1, flex: 1,
}, },
})); }));

View File

@@ -4,10 +4,12 @@ import TransitionLayout from '~/components/layouts/_transition_layout';
import BaseLayout from './_base_layout'; import BaseLayout from './_base_layout';
const DashboardLayoutStyle = styled(TransitionLayout)(({ theme }) => ({ const DashboardLayoutStyle = styled(TransitionLayout)(({ theme }) => ({
position: 'relative',
height: '100%', height: '100%',
width: theme.media.medium_desktop, width: theme.media.medium_desktop,
maxWidth: '100%', maxWidth: '100%',
padding: '0.75em 1em', padding: '0.75em 1em',
overflow: 'hidden',
})); }));
const DashboardLayout = ({ children }: { children: ReactNode }) => ( const DashboardLayout = ({ children }: { children: ReactNode }) => (

View File

@@ -53,6 +53,11 @@ const UserCard = styled.div({
justifyContent: 'center', justifyContent: 'center',
}); });
const DropdownItemButtonWithPadding = styled(DropdownItemButton)({
cursor: 'pointer',
padding: 0,
});
export default function Navbar() { export default function Navbar() {
const { t } = useTranslation('common'); const { t } = useTranslation('common');
const { isAuthenticated, user } = useUser(); const { isAuthenticated, user } = useUser();
@@ -89,7 +94,7 @@ export default function Navbar() {
) : ( ) : (
<> <>
<li> <li>
<ModalSettings openItem={DropdownItemButton} /> <ModalSettings openItem={DropdownItemButtonWithPadding} />
</li> </li>
<li> <li>
<Link href={route('auth.login').url}>{t('login')}</Link> <Link href={route('auth.login').url}>{t('login')}</Link>

View File

@@ -20,7 +20,7 @@ export default function ModalSettings({
return ( return (
<> <>
<OpenItem onClick={open}> <OpenItem onClick={open}>
<PiGearLight /> <PiGearLight size={20} />
{t('settings')} {t('settings')}
</OpenItem> </OpenItem>
<Modal title={t('settings')} opened={isShowing} close={close}> <Modal title={t('settings')} opened={isShowing} close={close}>

View File

@@ -1,5 +1,7 @@
import { useTheme } from '@emotion/react';
import styled from '@emotion/styled'; import styled from '@emotion/styled';
import { ReactNode, useEffect } from 'react'; import { ReactNode, useEffect } from 'react';
import { CiMenuBurger } from 'react-icons/ci';
import { useSwipeable } from 'react-swipeable'; import { useSwipeable } from 'react-swipeable';
import CollectionContainer from '~/components/dashboard/collection/collection_container'; import CollectionContainer from '~/components/dashboard/collection/collection_container';
import CollectionList from '~/components/dashboard/collection/list/collection_list'; import CollectionList from '~/components/dashboard/collection/list/collection_list';
@@ -9,6 +11,7 @@ import SwiperHandler from '~/components/dashboard/swiper_handler';
import DashboardLayout from '~/components/layouts/dashboard_layout'; import DashboardLayout from '~/components/layouts/dashboard_layout';
import { useMediaQuery } from '~/hooks/use_media_query'; import { useMediaQuery } from '~/hooks/use_media_query';
import useToggle from '~/hooks/use_modal'; import useToggle from '~/hooks/use_modal';
import { rgba } from '~/lib/color';
import { CollectionWithLinks } from '~/types/app'; import { CollectionWithLinks } from '~/types/app';
interface DashboardPageProps { interface DashboardPageProps {
@@ -16,38 +19,135 @@ interface DashboardPageProps {
activeCollection: CollectionWithLinks; activeCollection: CollectionWithLinks;
} }
const SideBar = styled.div(({ theme }) => ({ const SideBar = styled.div<{
borderRight: `1px solid ${theme.colors.lightGrey}`, floating?: boolean;
marginRight: '5px', opened: boolean;
}>(({ theme, opened, floating = false }) => ({
zIndex: 9,
position: floating ? 'absolute' : 'unset',
top: 0,
height: '100%',
width: opened ? '100%' : 'fit-content',
display: 'flex',
flexDirection: 'column',
transition: 'left 0.15s, right 0.15s',
'&::before': {
zIndex: -1,
position: floating ? 'absolute' : 'unset',
top: 0,
left: 0,
height: '100%',
width: '100%',
background: rgba(theme.colors.black, 0.35),
backdropFilter: 'blur(0.1em)',
content: '""',
display: opened ? 'block' : 'none',
},
}));
const LeftSideBar = styled(SideBar)(({ opened }) => ({
left: opened ? 0 : '-100%',
}));
const RightSideBar = styled(SideBar)(({ opened }) => ({
right: opened ? 0 : '-100%',
alignItems: 'flex-end',
})); }));
function DashboardPage(props: Readonly<DashboardPageProps>) { function DashboardPage(props: Readonly<DashboardPageProps>) {
const isMobile = useMediaQuery('(max-width: 768px)'); const theme = useTheme();
const { isShowing, open, close } = useToggle(); const isMobile = useMediaQuery(`(max-width: ${theme.media.mobile})`);
const isTablet = useMediaQuery(`(max-width: ${theme.media.tablet})`);
const {
isShowing: isNavigationOpen,
open: openNavigation,
close: closeNavigation,
} = useToggle();
const {
isShowing: isCollectionListOpen,
open: openCollectionList,
close: closeCollectionList,
} = useToggle();
const handleSwipeLeft = () => {
if (!isMobile && !isTablet) return;
if (isNavigationOpen) {
closeNavigation();
} else {
openCollectionList();
}
};
const handleSwipeRight = () => {
if (!isMobile && !isTablet) return;
if (isCollectionListOpen) {
closeCollectionList();
} else {
openNavigation();
}
};
const handlers = useSwipeable({ const handlers = useSwipeable({
trackMouse: true, trackMouse: true,
onSwipedRight: open, onSwipedLeft: handleSwipeLeft,
onSwipedRight: handleSwipeRight,
}); });
useEffect(() => { useEffect(() => {
if (!isMobile && isShowing) { if (!isMobile && !isTablet) {
close(); closeCollectionList();
closeNavigation();
} }
}, [close, isMobile, isShowing]); }, [isMobile, isTablet, closeCollectionList, closeNavigation]);
console.log(isMobile, isTablet, isNavigationOpen, isCollectionListOpen);
return ( return (
<DashboardProviders <DashboardProviders
collections={props.collections} collections={props.collections}
activeCollection={props.activeCollection} activeCollection={props.activeCollection}
> >
<SwiperHandler {...handlers}> <SwiperHandler {...handlers}>
{!isMobile && ( <LeftSideBar
<SideBar> opened={isNavigationOpen}
floating={isMobile || isTablet}
onClick={closeNavigation}
>
<SideNavigation /> <SideNavigation />
</SideBar> </LeftSideBar>
)} <CollectionContainer
<CollectionContainer isMobile={isMobile} openSideMenu={open} /> openNavigationItem={
<CiMenuBurger
size={24}
onClick={openNavigation}
css={{
cursor: 'pointer',
marginRight: '1em',
color: theme.colors.primary,
}}
/>
}
openCollectionItem={
<CiMenuBurger
size={24}
onClick={openCollectionList}
css={{
cursor: 'pointer',
marginLeft: '1em',
color: theme.colors.primary,
}}
/>
}
showButtons={isMobile || isTablet}
/>
<RightSideBar
opened={isCollectionListOpen}
floating={isMobile || isTablet}
onClick={closeCollectionList}
>
<CollectionList /> <CollectionList />
</RightSideBar>
</SwiperHandler> </SwiperHandler>
</DashboardProviders> </DashboardProviders>
); );

View File

@@ -12,6 +12,8 @@ const LoginContainer = styled.div({
width: '100%', width: '100%',
maxWidth: '100%', maxWidth: '100%',
whiteSpace: 'nowrap', whiteSpace: 'nowrap',
marginTop: '50px',
paddingInline: '1rem',
display: 'flex', display: 'flex',
alignItems: 'center', alignItems: 'center',
gap: '1.5em', gap: '1.5em',
@@ -19,7 +21,8 @@ const LoginContainer = styled.div({
}); });
const FormWrapper = styled.div(({ theme }) => ({ const FormWrapper = styled.div(({ theme }) => ({
width: '100%', width: '500px',
maxWidth: '100%',
backgroundColor: theme.colors.secondary, backgroundColor: theme.colors.secondary,
padding: '2em', padding: '2em',
borderRadius: theme.border.radius, borderRadius: theme.border.radius,
@@ -55,7 +58,7 @@ const ButtonLink = styled(Button.withComponent('a'))({
function LoginPage() { function LoginPage() {
const { t } = useTranslation(); const { t } = useTranslation();
return ( return (
<LoginContainer css={{ width: '500px', marginTop: '50px' }}> <LoginContainer>
<Head title={t('login:title')} /> <Head title={t('login:title')} />
<img <img
src={'/logo-light.png'} src={'/logo-light.png'}

View File

@@ -10,6 +10,7 @@
href='https://fonts.googleapis.com/css2?family=Poppins:ital,wght@0,400;0,500;0,700;1,400;1,500;1,700&family=Rubik:ital,wght@0,400;0,700;1,400;1,700&display=swap' href='https://fonts.googleapis.com/css2?family=Poppins:ital,wght@0,400;0,500;0,700;1,400;1,500;1,700&family=Rubik:ital,wght@0,400;0,700;1,400;1,700&display=swap'
rel='stylesheet' rel='stylesheet'
/> />
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta charSet='UTF-8' /> <meta charSet='UTF-8' />
<link <link
rel='shortcut icon' rel='shortcut icon'