Skip to content

Commit

Permalink
Merge pull request #135 from cuculus-dev/feature/issues-112
Browse files Browse the repository at this point in the history
#128 指摘事項修正
  • Loading branch information
takecchi authored Dec 20, 2023
2 parents c2f92f0 + 850808a commit 5a31eb3
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 49 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

import { IconButton } from '@/app/_components/button/IconButton';
import PostDialog from '@/app/_components/post/PostDialog';
import { useProfile } from '@/swr/client/auth';
import { useAuth } from '@/swr/client/auth';
import { Send } from '@mui/icons-material';
import { Box, styled } from '@mui/material';
import { styled } from '@mui/material';
import { usePathname } from 'next/navigation';
import { useState } from 'react';

Expand Down Expand Up @@ -33,37 +33,38 @@ const StyledButton = styled(IconButton)`
/* FIXME: IconButtonのvariant=containedで色つかない問題が解消したら消す */
color: white;
background-color: #007bbb;
:hover {
background-color: #007bbb;
}
`;

export default function MobileOpenPostDialogButton() {
const [getOpenDialog, setOpenDialog] = useState(false);
const [openDialog, setOpenDialog] = useState(false);
const { data: auth } = useAuth();

const excludePaths = ['/settings', '/invitations', '/messages'];
const pathname = usePathname();

const renderablePaths = ['/home', '/search', '/notifications'];
const renderable = renderablePaths.includes(usePathname() as string);
const { data: profile } = useProfile();
if (!auth || (pathname && excludePaths.includes(pathname))) {
return null;
}

return (
<>
{profile && renderable && (
<Box>
<StyledButton
variant="contained"
color="primary"
onClick={() => setOpenDialog(true)}
>
<Send />
</StyledButton>
<StyledButton
variant="contained"
color="primary"
onClick={() => setOpenDialog(true)}
>
<Send />
</StyledButton>

<PostDialog
fullScreen
open={getOpenDialog}
close={() => setOpenDialog(false)}
/>
</Box>
)}
<PostDialog
fullScreen
open={openDialog}
close={() => setOpenDialog(false)}
/>
</>
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ const SideMenuAccountButton = ({
userName,
profileAvatarImageUrl,
}: Props) => {
const [getShowAccountMenu, setShowAccountMenu] = useState(false);
const [showAccountMenu, setShowAccountMenu] = useState(false);
const accountMenuRef = useRef(null);

return (
Expand All @@ -106,7 +106,7 @@ const SideMenuAccountButton = ({
</HFlex>

<Menu
open={getShowAccountMenu}
open={showAccountMenu}
onClose={() => setShowAccountMenu(false)}
anchorEl={accountMenuRef.current}
anchorOrigin={{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ const Label = styled(`span`)`
}
`;
const SideMenuPostButton = () => {
const [getShowPostDialog, setShowPostDialog] = useState(false);
const [showPostDialog, setShowPostDialog] = useState(false);

return (
<>
Expand All @@ -47,7 +47,7 @@ const SideMenuPostButton = () => {
</Wrapper>

<PostDialog
open={getShowPostDialog}
open={showPostDialog}
close={() => setShowPostDialog(false)}
/>
</>
Expand Down
41 changes: 18 additions & 23 deletions src/app/_components/post/PostDialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,10 @@ interface Props {
}

export default function PostDialog({ fullScreen, open, close }: Props) {
const [getContent, setContent] = useState('');
const [getShowConfirmCloseDialog, setShowConfirmCloseDialog] =
useState(false);
const [getErrorMessage, setErrorMesssage] = useState('');
const [getSucceedMessage, setSucceedMessage] = useState('');
const [content, setContent] = useState('');
const [showConfirmCloseDialog, setShowConfirmCloseDialog] = useState(false);
const [errorMessage, setErrorMessage] = useState('');
const [successMessage, setSuccessMessage] = useState('');
const { mutateLatest } = useHomeTimelineImmutable();

// NOTE: 閉じきる前に微妙に空になるのが見えるので
Expand All @@ -64,55 +63,51 @@ export default function PostDialog({ fullScreen, open, close }: Props) {
<Dialog
fullScreen={fullScreen}
open={open}
onClose={() => (getContent.length ? confirmAndClose() : close())}
onClose={() => (content.length ? confirmAndClose() : close())}
>
<StyledDialogTitle>
<HFlex>
<IconButton
onClick={() => (getContent.length ? confirmAndClose() : close())}
onClick={() => (content.length ? confirmAndClose() : close())}
>
<Close />
</IconButton>
</HFlex>
</StyledDialogTitle>

<StyledDialogContent>
<PostForm
getContent={getContent}
setContent={setContent}
focusEditor
/>
<PostForm getContent={content} setContent={setContent} focusEditor />
</StyledDialogContent>

<StyledDialogActions>
<SendPostButton
disabled={!getContent.length}
sendData={{ plainText: getContent }}
disabled={!content.length}
sendData={{ plainText: content }}
onSucceed={() => {
setSucceedMessage('送信しました。');
setSuccessMessage('送信しました。');
clearContent();
void mutateLatest();
close();
}}
onError={(e) => {
// TODO: リリース前に消す?
console.error(e);
setErrorMesssage('送信に失敗しました。');
setErrorMessage('送信に失敗しました。');
}}
/>
</StyledDialogActions>

<Snackbar
open={!!getErrorMessage.length}
onClose={() => setErrorMesssage('')}
open={!!errorMessage.length}
onClose={() => setErrorMessage('')}
autoHideDuration={2_000}
>
<Alert severity="error">{getErrorMessage}</Alert>
<Alert severity="error">{errorMessage}</Alert>
</Snackbar>
</Dialog>

<ConfirmClosePostDialogDialog
open={getShowConfirmCloseDialog}
open={showConfirmCloseDialog}
close={() => setShowConfirmCloseDialog(false)}
actions={[
{
Expand All @@ -127,11 +122,11 @@ export default function PostDialog({ fullScreen, open, close }: Props) {
/>

<Snackbar
open={!!getSucceedMessage.length}
onClose={() => setSucceedMessage('')}
open={!!successMessage.length}
onClose={() => setSuccessMessage('')}
autoHideDuration={2_000}
>
<Alert severity="success">{getSucceedMessage}</Alert>
<Alert severity="success">{successMessage}</Alert>
</Snackbar>
</Box>
);
Expand Down

0 comments on commit 5a31eb3

Please sign in to comment.