Skip to content

Commit

Permalink
feat: add mobile header (#659)
Browse files Browse the repository at this point in the history
Co-authored-by: Léo Pradel <pradel.leo@gmail.com>
  • Loading branch information
gregogun and pradel committed Sep 8, 2022
1 parent 4ceeeb6 commit 361ae92
Show file tree
Hide file tree
Showing 10 changed files with 477 additions and 21 deletions.
5 changes: 5 additions & 0 deletions .changeset/smart-numbers-jump.md
@@ -0,0 +1,5 @@
---
'@sigle/app': minor
---

Add mobile header with drag-to-close functionality.
16 changes: 15 additions & 1 deletion pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions sigle/package.json
Expand Up @@ -105,6 +105,7 @@
"react-cool-inview": "3.0.1",
"react-div-100vh": "0.6.0",
"react-dom": "18.2.0",
"react-draggable": "4.4.5",
"react-dropzone": "11.4.2",
"react-query": "3.39.1",
"react-toastify": "8.2.0",
Expand Down
78 changes: 78 additions & 0 deletions sigle/src/modules/layout/components/AppHeader.tsx
Expand Up @@ -3,6 +3,7 @@ import {
TwitterLogoIcon,
DiscordLogoIcon,
SunIcon,
HamburgerMenuIcon,
} from '@radix-ui/react-icons';
import Link from 'next/link';
import Image from 'next/image';
Expand All @@ -14,6 +15,19 @@ import { useAuth } from '../../auth/AuthContext';
import { sigleConfig } from '../../../config';
import { useGetUserMe } from '../../../hooks/users';
import { HeaderDropdown } from './HeaderDropdown';
import { MobileHeader } from './MobileHeader';
import { useState } from 'react';
import {
createNewEmptyStory,
getStoriesFile,
saveStoriesFile,
saveStoryFile,
} from '../../../utils';
import { createSubsetStory } from '../../editor/utils';
import * as Fathom from 'fathom-client';
import { Goals } from '../../../utils/fathom';
import { toast } from 'react-toastify';
import { useRouter } from 'next/router';

const Header = styled('header', Container, {
display: 'flex',
Expand All @@ -31,6 +45,31 @@ export const AppHeader = () => {
const { resolvedTheme, setTheme } = useTheme();
const { user, isLegacy } = useAuth();
const { status } = useSession();
const [showMobileHeaderDialog, setShowMobileHeaderDialog] = useState(false);
const [loadingCreate, setLoadingCreate] = useState(false);
const router = useRouter();

const handleCreateNewPrivateStory = async () => {
setLoadingCreate(true);
try {
const storiesFile = await getStoriesFile();
const story = createNewEmptyStory();

storiesFile.stories.unshift(
createSubsetStory(story, { plainContent: '' })
);

await saveStoriesFile(storiesFile);
await saveStoryFile(story);

Fathom.trackGoal(Goals.CREATE_NEW_STORY, 0);
router.push('/stories/[storyId]', `/stories/${story.id}`);
} catch (error) {
console.error(error);
toast.error(error.message);
setLoadingCreate(false);
}
};

/**
* This query is used to register the user in the DB. As the header is part of all the
Expand All @@ -57,6 +96,10 @@ export const AppHeader = () => {
break;
}

const handleShowMobileHeader = () => setShowMobileHeaderDialog(true);

const handleCloseMobileHeader = () => setShowMobileHeaderDialog(false);

return (
<Header>
<Flex
Expand Down Expand Up @@ -90,6 +133,41 @@ export const AppHeader = () => {
</Box>
</Link>
</Flex>

<Flex gap="2">
<Flex
css={{
display: 'flex',
'@md': {
display: 'none',
},
}}
gap="5"
>
<Button
disabled={loadingCreate}
onClick={handleCreateNewPrivateStory}
>
{!loadingCreate ? 'Write' : 'Creating...'}
</Button>
<IconButton
css={{
'&:hover': {
backgroundColor: 'transparent',
},
}}
onClick={handleShowMobileHeader}
>
<HamburgerMenuIcon />
</IconButton>

<MobileHeader
open={showMobileHeaderDialog}
onClose={handleCloseMobileHeader}
/>
</Flex>
</Flex>

<Flex
css={{
display: 'none',
Expand Down
1 change: 1 addition & 0 deletions sigle/src/modules/layout/components/LoginLayout.tsx
Expand Up @@ -83,6 +83,7 @@ export const LoginLayout = ({
href={sigleConfig.landingUrl}
target="_blank"
rel="noreferrer"
css={{ pt: '$5', '@md': { pt: 0 } }}
>
<Image src={src} alt="Logo" width={123} height={45} />
</Box>
Expand Down

1 comment on commit 361ae92

@vercel
Copy link

@vercel vercel bot commented on 361ae92 Sep 8, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

sigle – ./

app.sigle.io
sigle-git-main-sigle.vercel.app
sigle.vercel.app
sigle-sigle.vercel.app

Please sign in to comment.