6 Commits

105 changed files with 1242 additions and 657 deletions

1
.gitignore vendored
View File

@ -49,3 +49,4 @@ npm-debug.log*
.DS_Store .DS_Store
.lighthouseci .lighthouseci
.vercel .vercel
*.hbs

View File

@ -1,7 +0,0 @@
.next
.lighthouseci
coverage
node_modules
**/workbox-*.js
**/sw.js
*.hbs

View File

@ -5,7 +5,8 @@ import classNames from 'clsx'
import { useMediaQuery } from 'react-responsive' import { useMediaQuery } from 'react-responsive'
import { useSwipeable } from 'react-swipeable' import { useSwipeable } from 'react-swipeable'
import { Sidebar, DirectionSidebar } from './Sidebar' import type { DirectionSidebar } from './Sidebar'
import { Sidebar } from './Sidebar'
import { IconButton } from '../design/IconButton' import { IconButton } from '../design/IconButton'
import { IconLink } from '../design/IconLink' import { IconLink } from '../design/IconLink'
import { Guilds } from './Guilds/Guilds' import { Guilds } from './Guilds/Guilds'
@ -148,7 +149,9 @@ export const Application: React.FC<
<header className='z-50 flex h-16 items-center justify-between bg-gray-200 px-2 py-3 shadow-lg dark:bg-gray-800'> <header className='z-50 flex h-16 items-center justify-between bg-gray-200 px-2 py-3 shadow-lg dark:bg-gray-800'>
<IconButton <IconButton
className='h-10 w-10 p-2' className='h-10 w-10 p-2'
onClick={() => handleToggleSidebars('left')} onClick={() => {
return handleToggleSidebars('left')
}}
> >
{!visibleSidebars.left ? <MenuIcon /> : <XIcon />} {!visibleSidebars.left ? <MenuIcon /> : <XIcon />}
</IconButton> </IconButton>
@ -163,7 +166,9 @@ export const Application: React.FC<
<IconButton <IconButton
data-cy='icon-button-right-sidebar-members' data-cy='icon-button-right-sidebar-members'
className='h-10 w-10 p-2' className='h-10 w-10 p-2'
onClick={() => handleToggleSidebars('right')} onClick={() => {
return handleToggleSidebars('right')
}}
> >
{!visibleSidebars.right ? <UsersIcon /> : <XIcon />} {!visibleSidebars.right ? <UsersIcon /> : <XIcon />}
</IconButton> </IconButton>

View File

@ -11,11 +11,11 @@ import { useGuildMember } from '../../../contexts/GuildMember'
import { Input } from '../../design/Input' import { Input } from '../../design/Input'
import { Button } from '../../design/Button' import { Button } from '../../design/Button'
import { useAuthentication } from '../../../tools/authentication' import { useAuthentication } from '../../../tools/authentication'
import { import type {
Channel, Channel,
channelSchema,
ChannelWithDefaultChannelId ChannelWithDefaultChannelId
} from '../../../models/Channel' } from '../../../models/Channel'
import { channelSchema } from '../../../models/Channel'
import { ConfirmPopup } from '../ConfirmPopup' import { ConfirmPopup } from '../ConfirmPopup'
import { useFormTranslation } from '../../../hooks/useFormTranslation' import { useFormTranslation } from '../../../hooks/useFormTranslation'

View File

@ -1,10 +1,11 @@
import { memo } from 'react'
import classNames from 'clsx' import classNames from 'clsx'
import Link from 'next/link' import Link from 'next/link'
import { useRouter } from 'next/router' import { useRouter } from 'next/router'
import { CogIcon } from '@heroicons/react/solid' import { CogIcon } from '@heroicons/react/solid'
import { GuildsChannelsPath } from '../Application' import type { GuildsChannelsPath } from '../Application'
import { Channel as ChannelType } from '../../../models/Channel' import type { Channel as ChannelType } from '../../../models/Channel'
import { useGuildMember } from '../../../contexts/GuildMember' import { useGuildMember } from '../../../contexts/GuildMember'
import { IconButton } from '../../design/IconButton' import { IconButton } from '../../design/IconButton'
@ -14,7 +15,7 @@ export interface ChannelProps {
selected?: boolean selected?: boolean
} }
export const Channel: React.FC<ChannelProps> = (props) => { const ChannelMemo: React.FC<ChannelProps> = (props) => {
const { channel, path, selected = false } = props const { channel, path, selected = false } = props
const router = useRouter() const router = useRouter()
@ -53,3 +54,5 @@ export const Channel: React.FC<ChannelProps> = (props) => {
</Link> </Link>
) )
} }
export const Channel = memo(ChannelMemo)

View File

@ -1,7 +1,7 @@
import InfiniteScroll from 'react-infinite-scroll-component' import InfiniteScroll from 'react-infinite-scroll-component'
import { useChannels } from '../../../contexts/Channels' import { useChannels } from '../../../contexts/Channels'
import { GuildsChannelsPath } from '../Application' import type { GuildsChannelsPath } from '../Application'
import { Loader } from '../../design/Loader' import { Loader } from '../../design/Loader'
import { Channel } from './Channel' import { Channel } from './Channel'

View File

@ -17,7 +17,9 @@ export const ConfirmPopup: React.FC<ConfirmPopupProps> = ({ ...props }) => {
const [isLoading, setIsLoading] = useState(false) const [isLoading, setIsLoading] = useState(false)
const handleYesLoading = async (): Promise<void> => { const handleYesLoading = async (): Promise<void> => {
setIsLoading((isLoading) => !isLoading) setIsLoading((isLoading) => {
return !isLoading
})
await props.handleYes() await props.handleYes()
} }

View File

@ -8,7 +8,8 @@ import { Input } from '../../design/Input'
import { Main } from '../../design/Main' import { Main } from '../../design/Main'
import { Button } from '../../design/Button' import { Button } from '../../design/Button'
import { FormState } from '../../design/FormState' import { FormState } from '../../design/FormState'
import { Channel, channelSchema } from '../../../models/Channel' import type { Channel } from '../../../models/Channel'
import { channelSchema } from '../../../models/Channel'
import { useGuildMember } from '../../../contexts/GuildMember' import { useGuildMember } from '../../../contexts/GuildMember'
import { useFormTranslation } from '../../../hooks/useFormTranslation' import { useFormTranslation } from '../../../hooks/useFormTranslation'

View File

@ -1,11 +1,12 @@
import { useRouter } from 'next/router' import { useRouter } from 'next/router'
import useTranslation from 'next-translate/useTranslation' import useTranslation from 'next-translate/useTranslation'
import { Form, useForm } from 'react-component-form' import { Form, useForm } from 'react-component-form'
import { AxiosResponse } from 'axios' import type { AxiosResponse } from 'axios'
import type { HandleUseFormCallback } from 'react-component-form' import type { HandleUseFormCallback } from 'react-component-form'
import { useAuthentication } from '../../../tools/authentication' import { useAuthentication } from '../../../tools/authentication'
import { GuildComplete, guildSchema } from '../../../models/Guild' import type { GuildComplete } from '../../../models/Guild'
import { guildSchema } from '../../../models/Guild'
import { Input } from '../../design/Input' import { Input } from '../../design/Input'
import { Main } from '../../design/Main' import { Main } from '../../design/Main'
import { Button } from '../../design/Button' import { Button } from '../../design/Button'

View File

@ -5,7 +5,7 @@ import { useGuildMember } from '../../../contexts/GuildMember'
import { Divider } from '../../design/Divider' import { Divider } from '../../design/Divider'
import { Channels } from '../Channels' import { Channels } from '../Channels'
import { IconButton } from '../../design/IconButton' import { IconButton } from '../../design/IconButton'
import { GuildsChannelsPath } from '..' import type { GuildsChannelsPath } from '..'
export interface GuildLeftSidebarProps { export interface GuildLeftSidebarProps {
path: GuildsChannelsPath path: GuildsChannelsPath

View File

@ -1,6 +1,7 @@
import { memo } from 'react'
import Image from 'next/image' import Image from 'next/image'
import { GuildWithDefaultChannelId } from '../../../models/Guild' import type { GuildWithDefaultChannelId } from '../../../models/Guild'
import { IconLink } from '../../design/IconLink' import { IconLink } from '../../design/IconLink'
export interface GuildProps { export interface GuildProps {
@ -8,7 +9,7 @@ export interface GuildProps {
selected?: boolean selected?: boolean
} }
export const Guild: React.FC<GuildProps> = (props) => { const GuildMemo: React.FC<GuildProps> = (props) => {
const { guild, selected } = props const { guild, selected } = props
return ( return (
@ -34,3 +35,5 @@ export const Guild: React.FC<GuildProps> = (props) => {
</IconLink> </IconLink>
) )
} }
export const Guild = memo(GuildMemo)

View File

@ -2,7 +2,7 @@ import InfiniteScroll from 'react-infinite-scroll-component'
import { Loader } from '../../design/Loader' import { Loader } from '../../design/Loader'
import { useGuilds } from '../../../contexts/Guilds' import { useGuilds } from '../../../contexts/Guilds'
import { GuildsPath } from '..' import type { GuildsPath } from '..'
import { Guild } from './Guild' import { Guild } from './Guild'
export interface GuildsProps { export interface GuildsProps {

View File

@ -7,7 +7,7 @@ import axios from 'axios'
import { Emoji } from '../../Emoji' import { Emoji } from '../../Emoji'
import { ConfirmPopup } from '../ConfirmPopup' import { ConfirmPopup } from '../ConfirmPopup'
import { import type {
GuildPublic as GuildPublicType, GuildPublic as GuildPublicType,
GuildWithDefaultChannelId GuildWithDefaultChannelId
} from '../../../models/Guild' } from '../../../models/Guild'
@ -25,7 +25,9 @@ export const GuildPublic: React.FC<GuildPublicProps> = (props) => {
const { t } = useTranslation() const { t } = useTranslation()
const handleIsConfirmed = (): void => { const handleIsConfirmed = (): void => {
setIsConfirmed((isConfirmed) => !isConfirmed) setIsConfirmed((isConfirmed) => {
return !isConfirmed
})
} }
const handleYes = async (): Promise<void> => { const handleYes = async (): Promise<void> => {

View File

@ -3,11 +3,12 @@ import { useEffect, useState } from 'react'
import InfiniteScroll from 'react-infinite-scroll-component' import InfiniteScroll from 'react-infinite-scroll-component'
import { useAuthentication } from '../../../tools/authentication' import { useAuthentication } from '../../../tools/authentication'
import { GuildPublic as GuildPublicType } from '../../../models/Guild' import type { GuildPublic as GuildPublicType } from '../../../models/Guild'
import { Loader } from '../../design/Loader' import { Loader } from '../../design/Loader'
import { GuildPublic } from './GuildPublic' import { GuildPublic } from './GuildPublic'
import { usePagination } from '../../../hooks/usePagination' import { usePagination } from '../../../hooks/usePagination'
import { SocketData, handleSocketData } from '../../../tools/handleSocketData' import type { SocketData } from '../../../tools/handleSocketData'
import { handleSocketData } from '../../../tools/handleSocketData'
export const JoinGuildsPublic: React.FC = () => { export const JoinGuildsPublic: React.FC = () => {
const [search, setSearch] = useState('') const [search, setSearch] = useState('')

View File

@ -1,14 +1,15 @@
import { memo } from 'react'
import Image from 'next/image' import Image from 'next/image'
import Link from 'next/link' import Link from 'next/link'
import { MemberWithPublicUser } from '../../../models/Member' import type { MemberWithPublicUser } from '../../../models/Member'
import { Emoji } from '../../Emoji' import { Emoji } from '../../Emoji'
export interface MemberProps { export interface MemberProps {
member: MemberWithPublicUser member: MemberWithPublicUser
} }
export const Member: React.FC<MemberProps> = (props) => { const MemberMemo: React.FC<MemberProps> = (props) => {
const { member } = props const { member } = props
return ( return (
@ -45,3 +46,5 @@ export const Member: React.FC<MemberProps> = (props) => {
</Link> </Link>
) )
} }
export const Member = memo(MemberMemo)

View File

@ -0,0 +1,48 @@
import useTranslation from 'next-translate/useTranslation'
import TextareaAutosize from 'react-textarea-autosize'
import type { MessageProps } from '../Message'
export interface EditMessageProps extends MessageProps {
handleEdit: () => Promise<void>
handleKeyDown: React.KeyboardEventHandler<HTMLFormElement>
textareaRef: React.RefObject<HTMLTextAreaElement>
}
export const EditMessage: React.FC<
React.PropsWithChildren<EditMessageProps>
> = ({ handleEdit, handleKeyDown, textareaRef, message }) => {
const { t } = useTranslation()
const handleEditSubmit: React.FormEventHandler<HTMLFormElement> = async (
event
) => {
event.preventDefault()
await handleEdit()
}
return (
<form
className='flex h-full w-full items-center'
onSubmit={handleEditSubmit}
onKeyDown={handleKeyDown}
>
<TextareaAutosize
className='scrollbar-firefox-support w-full resize-none bg-transparent p-2 tracking-wide outline-none'
placeholder={t('application:write-a-message')}
wrap='soft'
maxRows={6}
name='message'
defaultValue={message.value}
ref={textareaRef}
autoFocus
onFocus={(event) => {
event.currentTarget.setSelectionRange(
event.currentTarget.value.length,
event.currentTarget.value.length
)
}}
/>
</form>
)
}

View File

@ -0,0 +1 @@
export * from './EditMessage'

View File

@ -2,17 +2,18 @@ import { useState, useRef } from 'react'
import Image from 'next/image' import Image from 'next/image'
import Link from 'next/link' import Link from 'next/link'
import date from 'date-and-time' import date from 'date-and-time'
import TextareaAutosize from 'react-textarea-autosize' import type { MotionProps } from 'framer-motion'
import useTranslation from 'next-translate/useTranslation' import { motion } from 'framer-motion'
import { MessageWithMember } from '../../../../models/Message' import type { MessageWithMember } from '../../../../models/Message'
import { MessageText } from './MessageText' import { MessageText } from './MessageText'
import { Loader } from '../../../design/Loader' import { Loader } from '../../../design/Loader'
import { MessageFile } from './MessageFile' import { MessageFile } from './MessageFile'
import { Emoji } from '../../../Emoji'
import { useAuthentication } from '../../../../tools/authentication' import { useAuthentication } from '../../../../tools/authentication'
import { MessageOptions } from './MessageOptions'
import { EditMessage } from './EditMessage'
export interface MessageProps { export interface MessageProps extends MotionProps {
message: MessageWithMember message: MessageWithMember
} }
@ -21,15 +22,8 @@ export const Message: React.FC<MessageProps> = (props) => {
const textareaReference = useRef<HTMLTextAreaElement>(null) const textareaReference = useRef<HTMLTextAreaElement>(null)
const [isEditing, setIsEditing] = useState(false) const [isEditing, setIsEditing] = useState(false)
const { t } = useTranslation()
const { authentication, user } = useAuthentication() const { authentication, user } = useAuthentication()
const handleDeleteMessage = async (): Promise<void> => {
try {
await authentication.api.delete(`/messages/${message.id}`)
} catch {}
}
const handleTextareaKeyDown: React.KeyboardEventHandler<HTMLFormElement> = ( const handleTextareaKeyDown: React.KeyboardEventHandler<HTMLFormElement> = (
event event
) => { ) => {
@ -57,13 +51,6 @@ export const Message: React.FC<MessageProps> = (props) => {
handleEditMode() handleEditMode()
} }
const handleEditSubmit: React.FormEventHandler<HTMLFormElement> = async (
event
) => {
event.preventDefault()
await handleEdit()
}
const handleEditMode = (): void => { const handleEditMode = (): void => {
setIsEditing((oldIsEditing) => { setIsEditing((oldIsEditing) => {
return !oldIsEditing return !oldIsEditing
@ -71,9 +58,19 @@ export const Message: React.FC<MessageProps> = (props) => {
} }
return ( return (
<div <motion.div
className='group flex w-full p-4 transition hover:bg-gray-200 dark:hover:bg-gray-900' layout
initial='initial'
animate='animate'
exit='exit'
data-cy={`message-${message.id}`} data-cy={`message-${message.id}`}
className='group flex w-full p-4 transition hover:bg-gray-200 dark:hover:bg-gray-900'
transition={{ type: 'spring', stiffness: 500, damping: 60 }}
variants={{
initial: { x: -100, opacity: 0 },
animate: { x: 0, opacity: 1 },
exit: { opacity: 0 }
}}
> >
<Link href={`/application/users/${message.member.user.id}`}> <Link href={`/application/users/${message.member.user.id}`}>
<a> <a>
@ -115,54 +112,24 @@ export const Message: React.FC<MessageProps> = (props) => {
{date.format(new Date(message.createdAt), 'DD/MM/YYYY - HH:mm:ss')} {date.format(new Date(message.createdAt), 'DD/MM/YYYY - HH:mm:ss')}
</span> </span>
</div> </div>
{message.member.userId === user.id ? (
<div className='absolute right-6 -top-8 flex opacity-0 transition-opacity group-hover:opacity-100'> {message.member.userId === user.id && (
{message.type === 'text' ? ( <MessageOptions
<div message={message}
className='message-options rounded-l-lg border-l-slate-600' editMode={isEditing ? ':white_check_mark:' : ':pencil2:'}
title={t('application:edit')} handleEdit={isEditing ? handleEdit : handleEditMode}
onClick={isEditing ? handleEdit : handleEditMode} />
> )}
<Emoji
value={isEditing ? ':white_check_mark:' : ':pencil2:'}
size={18}
/>
</div>
) : null}
<div
className='message-options rounded-r-lg border-r-slate-600'
title={t('application:delete')}
onClick={handleDeleteMessage}
>
<Emoji value=':wastebasket:' size={18} />
</div>
</div>
) : null}
{message.type === 'text' ? ( {message.type === 'text' ? (
<> <>
{isEditing ? ( {isEditing ? (
<form <EditMessage
className='flex h-full w-full items-center' message={message}
onSubmit={handleEditSubmit} textareaRef={textareaReference}
onKeyDown={handleTextareaKeyDown} handleEdit={handleEdit}
> handleKeyDown={handleTextareaKeyDown}
<TextareaAutosize />
className='scrollbar-firefox-support w-full resize-none bg-transparent p-2 tracking-wide outline-none'
placeholder={t('application:write-a-message')}
wrap='soft'
maxRows={6}
name='message'
defaultValue={message.value}
ref={textareaReference}
autoFocus
onFocus={(event) => {
event.currentTarget.setSelectionRange(
event.currentTarget.value.length,
event.currentTarget.value.length
)
}}
/>
</form>
) : ( ) : (
<MessageText message={message} /> <MessageText message={message} />
)} )}
@ -173,6 +140,6 @@ export const Message: React.FC<MessageProps> = (props) => {
<Loader /> <Loader />
)} )}
</div> </div>
</div> </motion.div>
) )
} }

View File

@ -3,7 +3,7 @@ import axios from 'axios'
import prettyBytes from 'pretty-bytes' import prettyBytes from 'pretty-bytes'
import { DownloadIcon } from '@heroicons/react/solid' import { DownloadIcon } from '@heroicons/react/solid'
import { MessageWithMember } from '../../../../../models/Message' import type { MessageWithMember } from '../../../../../models/Message'
import { Loader } from '../../../../design/Loader' import { Loader } from '../../../../design/Loader'
import { FileIcon } from './FileIcon' import { FileIcon } from './FileIcon'
import { api } from '../../../../../tools/api' import { api } from '../../../../../tools/api'

View File

@ -0,0 +1,44 @@
import useTranslation from 'next-translate/useTranslation'
import { useAuthentication } from '../../../../../tools/authentication'
import { Emoji } from '../../../../Emoji'
import type { MessageProps } from '../Message'
interface MessageOptionsProps extends MessageProps {
handleEdit: () => void
editMode: ':white_check_mark:' | ':pencil2:'
}
export const MessageOptions: React.FC<
React.PropsWithChildren<MessageOptionsProps>
> = ({ handleEdit, editMode, message }) => {
const { t } = useTranslation()
const { authentication } = useAuthentication()
const handleDeleteMessage = async (): Promise<void> => {
try {
await authentication.api.delete(`/messages/${message.id}`)
} catch {}
}
return (
<div className='absolute right-6 -top-8 flex opacity-0 transition-opacity group-hover:opacity-100'>
{message.type === 'text' && (
<div
className='message-options rounded-l-lg border-l-slate-600'
title={t('application:edit')}
onClick={handleEdit}
>
<Emoji value={editMode} size={18} />
</div>
)}
<div
className='message-options rounded-r-lg border-r-slate-600'
title={t('application:delete')}
onClick={handleDeleteMessage}
>
<Emoji value=':wastebasket:' size={18} />
</div>
</div>
)
}

View File

@ -0,0 +1 @@
export * from './MessageOptions'

View File

@ -10,7 +10,7 @@ import { vscDarkPlus } from 'react-syntax-highlighter/dist/cjs/styles/prism'
import 'katex/dist/katex.min.css' import 'katex/dist/katex.min.css'
import { Emoji, emojiPlugin, isStringWithOnlyOneEmoji } from '../../../../Emoji' import { Emoji, emojiPlugin, isStringWithOnlyOneEmoji } from '../../../../Emoji'
import { MessageWithMember } from '../../../../../models/Message' import type { MessageWithMember } from '../../../../../models/Message'
export interface MessageContentProps { export interface MessageContentProps {
message: MessageWithMember message: MessageWithMember

View File

@ -1,5 +1,6 @@
import useTranslation from 'next-translate/useTranslation' import useTranslation from 'next-translate/useTranslation'
import InfiniteScroll from 'react-infinite-scroll-component' import InfiniteScroll from 'react-infinite-scroll-component'
import { AnimatePresence } from 'framer-motion'
import { Loader } from '../../design/Loader' import { Loader } from '../../design/Loader'
import { Message } from './Message' import { Message } from './Message'
@ -29,19 +30,21 @@ export const Messages: React.FC = () => {
id='messages' id='messages'
className='scrollbar-firefox-support flex w-full flex-1 flex-col-reverse overflow-y-auto transition-all' className='scrollbar-firefox-support flex w-full flex-1 flex-col-reverse overflow-y-auto transition-all'
> >
<InfiniteScroll <AnimatePresence>
scrollableTarget='messages' <InfiniteScroll
className='messages-list !overflow-x-hidden' scrollableTarget='messages'
dataLength={messages.length} className='messages-list !overflow-x-hidden'
next={nextPage} dataLength={messages.length}
inverse next={nextPage}
hasMore={hasMore} inverse
loader={<Loader />} hasMore={hasMore}
> loader={<Loader />}
{messages.map((message) => { >
return <Message key={message.id} message={message} /> {messages.map((message) => {
})} return <Message key={message.id} message={message} />
</InfiniteScroll> })}
</InfiniteScroll>
</AnimatePresence>
</div> </div>
) )
} }

View File

@ -3,9 +3,10 @@ import useTranslation from 'next-translate/useTranslation'
import TextareaAutosize from 'react-textarea-autosize' import TextareaAutosize from 'react-textarea-autosize'
import classNames from 'clsx' import classNames from 'clsx'
import { GuildsChannelsPath } from '..' import type { GuildsChannelsPath } from '..'
import { useAuthentication } from '../../../tools/authentication' import { useAuthentication } from '../../../tools/authentication'
import { EmojiPicker, EmojiPickerOnClick } from '../../Emoji' import type { EmojiPickerOnClick } from '../../Emoji'
import { EmojiPicker } from '../../Emoji'
export interface SendMessageProps { export interface SendMessageProps {
path: GuildsChannelsPath path: GuildsChannelsPath
@ -65,7 +66,9 @@ export const SendMessage: React.FC<SendMessageProps> = (props) => {
} }
const handleVisibleEmojiPicker = (): void => { const handleVisibleEmojiPicker = (): void => {
setIsVisibleEmojiPicker((isVisible) => !isVisible) setIsVisibleEmojiPicker((isVisible) => {
return !isVisible
})
} }
const handleEmojiPicker: EmojiPickerOnClick = (emoji) => { const handleEmojiPicker: EmojiPickerOnClick = (emoji) => {

View File

@ -1,6 +1,6 @@
import classNames from 'clsx' import classNames from 'clsx'
import { ApplicationProps } from '..' import type { ApplicationProps } from '..'
export type DirectionSidebar = 'left' | 'right' export type DirectionSidebar = 'left' | 'right'

View File

@ -2,8 +2,8 @@ import Image from 'next/image'
import date from 'date-and-time' import date from 'date-and-time'
import useTranslation from 'next-translate/useTranslation' import useTranslation from 'next-translate/useTranslation'
import { UserPublic } from '../../../models/User' import type { UserPublic } from '../../../models/User'
import { Guild } from '../../../models/Guild' import type { Guild } from '../../../models/Guild'
export interface UserProfileProps { export interface UserProfileProps {
className?: string className?: string

View File

@ -19,7 +19,8 @@ import { Button } from '../../design/Button'
import { FormState } from '../../design/FormState' import { FormState } from '../../design/FormState'
import { userSchema } from '../../../models/User' import { userSchema } from '../../../models/User'
import { userSettingsSchema } from '../../../models/UserSettings' import { userSettingsSchema } from '../../../models/UserSettings'
import { ProviderOAuth, providers } from '../../../models/OAuth' import type { ProviderOAuth } from '../../../models/OAuth'
import { providers } from '../../../models/OAuth'
import { useFormTranslation } from '../../../hooks/useFormTranslation' import { useFormTranslation } from '../../../hooks/useFormTranslation'
const schema = { const schema = {
@ -56,7 +57,9 @@ export const UserSettings: React.FC = () => {
const { getFirstErrorTranslation } = useFormTranslation() const { getFirstErrorTranslation } = useFormTranslation()
const hasAllProviders = useMemo(() => { const hasAllProviders = useMemo(() => {
return providers.every((provider) => user.strategies.includes(provider)) return providers.every((provider) => {
return user.strategies.includes(provider)
})
}, [user.strategies]) }, [user.strategies])
const onSubmit: HandleUseFormCallback<typeof schema> = async (formData) => { const onSubmit: HandleUseFormCallback<typeof schema> = async (formData) => {
@ -189,9 +192,9 @@ export const UserSettings: React.FC = () => {
setUser((oldUser) => { setUser((oldUser) => {
return { return {
...oldUser, ...oldUser,
strategies: oldUser.strategies.filter( strategies: oldUser.strategies.filter((strategy) => {
(strategy) => strategy !== provider return strategy !== provider
) })
} }
}) })
setMessage('application:success-deleted-provider') setMessage('application:success-deleted-provider')

View File

@ -14,10 +14,8 @@ import { FormState } from '../design/FormState'
import { AuthenticationForm } from '.' import { AuthenticationForm } from '.'
import { userSchema } from '../../models/User' import { userSchema } from '../../models/User'
import { api } from '../../tools/api' import { api } from '../../tools/api'
import { import type { Tokens } from '../../tools/authentication'
Tokens, import { Authentication as AuthenticationClass } from '../../tools/authentication'
Authentication as AuthenticationClass
} from '../../tools/authentication'
import { AuthenticationSocialMedia } from './AuthenticationSocialMedia' import { AuthenticationSocialMedia } from './AuthenticationSocialMedia'
import { useFormTranslation } from '../../hooks/useFormTranslation' import { useFormTranslation } from '../../hooks/useFormTranslation'

View File

@ -1,5 +1,6 @@
import classNames from 'clsx' import classNames from 'clsx'
import { Form, FormProps } from 'react-component-form' import type { FormProps } from 'react-component-form'
import { Form } from 'react-component-form'
export const AuthenticationForm: React.FC<FormProps> = (props) => { export const AuthenticationForm: React.FC<FormProps> = (props) => {
const { className, children, ...rest } = props const { className, children, ...rest } = props

View File

@ -3,7 +3,8 @@ import { useRouter } from 'next/router'
import { api } from '../../tools/api' import { api } from '../../tools/api'
import { Authentication, isTokens } from '../../tools/authentication' import { Authentication, isTokens } from '../../tools/authentication'
import { SocialMediaButton, SocialMedia } from '../design/SocialMediaButton' import type { SocialMedia } from '../design/SocialMediaButton'
import { SocialMediaButton } from '../design/SocialMediaButton'
import { providers } from '../../models/OAuth' import { providers } from '../../models/OAuth'
export const AuthenticationSocialMedia: React.FC = () => { export const AuthenticationSocialMedia: React.FC = () => {

View File

@ -1,5 +1,6 @@
import 'emoji-mart/css/emoji-mart.css' import 'emoji-mart/css/emoji-mart.css'
import { EmojiData, Picker } from 'emoji-mart' import type { EmojiData } from 'emoji-mart'
import { Picker } from 'emoji-mart'
import { useTheme } from 'next-themes' import { useTheme } from 'next-themes'
import { EMOJI_SET } from '../emojiPlugin' import { EMOJI_SET } from '../emojiPlugin'

View File

@ -1,6 +1,6 @@
import { visit } from 'unist-util-visit' import { visit } from 'unist-util-visit'
import { Plugin, Transformer } from 'unified' import type { Plugin, Transformer } from 'unified'
import { Literal, Parent } from 'unist' import type { Literal, Parent } from 'unist'
import type { ElementContent } from 'hast' import type { ElementContent } from 'hast'
import type { EmojiSet } from 'emoji-mart' import type { EmojiSet } from 'emoji-mart'

View File

@ -19,10 +19,14 @@ export const Language: React.FC<LanguageProps> = (props) => {
const languageClickRef = useRef<HTMLDivElement | null>(null) const languageClickRef = useRef<HTMLDivElement | null>(null)
const handleHiddenMenu = useCallback(() => { const handleHiddenMenu = useCallback(() => {
setHiddenMenu((oldHiddenMenu) => !oldHiddenMenu) setHiddenMenu((oldHiddenMenu) => {
return !oldHiddenMenu
})
}, []) }, [])
useClickOutsideAlerter(languageClickRef, () => setHiddenMenu(true)) useClickOutsideAlerter(languageClickRef, () => {
return setHiddenMenu(true)
})
const handleLanguage = async (language: string): Promise<void> => { const handleLanguage = async (language: string): Promise<void> => {
await setLanguage(language) await setLanguage(language)
@ -59,7 +63,9 @@ export const Language: React.FC<LanguageProps> = (props) => {
<li <li
key={index} key={index}
className='flex h-12 w-full items-center justify-center pl-2 hover:bg-[#4f545c] hover:bg-opacity-20' className='flex h-12 w-full items-center justify-center pl-2 hover:bg-[#4f545c] hover:bg-opacity-20'
onClick={async () => await handleLanguage(language)} onClick={async () => {
return await handleLanguage(language)
}}
> >
<LanguageFlag language={language} /> <LanguageFlag language={language} />
</li> </li>

View File

@ -2,7 +2,7 @@ import { useMemo } from 'react'
import Image from 'next/image' import Image from 'next/image'
import classNames from 'clsx' import classNames from 'clsx'
import { ProviderOAuth } from '../../../models/OAuth' import type { ProviderOAuth } from '../../../models/OAuth'
export type SocialMedia = ProviderOAuth export type SocialMedia = ProviderOAuth

View File

@ -1,6 +1,5 @@
import TextareaAutosize, { import type { TextareaAutosizeProps } from 'react-textarea-autosize'
TextareaAutosizeProps import TextareaAutosize from 'react-textarea-autosize'
} from 'react-textarea-autosize'
export interface TextareaProps extends TextareaAutosizeProps { export interface TextareaProps extends TextareaAutosizeProps {
label: string label: string

View File

@ -1,12 +1,15 @@
import { createContext, useContext, useEffect } from 'react' import { createContext, useContext, useEffect, useMemo } from 'react'
import { useRouter } from 'next/router' import { useRouter } from 'next/router'
import { NextPage, usePagination } from '../hooks/usePagination' import type { NextPage } from '../hooks/usePagination'
import { usePagination } from '../hooks/usePagination'
import { useAuthentication } from '../tools/authentication' import { useAuthentication } from '../tools/authentication'
import { Channel, ChannelWithDefaultChannelId } from '../models/Channel' import type { Channel, ChannelWithDefaultChannelId } from '../models/Channel'
import { GuildsChannelsPath } from '../components/Application' import type { GuildsChannelsPath } from '../components/Application'
import { handleSocketData, SocketData } from '../tools/handleSocketData' import type { SocketData } from '../tools/handleSocketData'
import { CacheKey, CHANNELS_CACHE_KEY } from '../tools/cache' import { handleSocketData } from '../tools/handleSocketData'
import type { CacheKey } from '../tools/cache'
import { CHANNELS_CACHE_KEY } from '../tools/cache'
export interface Channels { export interface Channels {
channels: Channel[] channels: Channel[]
@ -28,7 +31,9 @@ export const ChannelsProvider: React.FC<
const router = useRouter() const router = useRouter()
const { authentication } = useAuthentication() const { authentication } = useAuthentication()
const cacheKey: CacheKey = `${path.guildId}-${CHANNELS_CACHE_KEY}` const cacheKey = useMemo<CacheKey>(() => {
return `${path.guildId}-${CHANNELS_CACHE_KEY}`
}, [path.guildId])
const { const {
items: channels, items: channels,
@ -75,7 +80,7 @@ export const ChannelsProvider: React.FC<
export const useChannels = (): Channels => { export const useChannels = (): Channels => {
const channels = useContext(ChannelsContext) const channels = useContext(ChannelsContext)
if (channels === defaultChannelsContext) { if (channels === defaultChannelsContext) {
throw new Error('useChannels must be used within ChannelsProvider') throw new Error('`useChannels` must be used within `ChannelsProvider`')
} }
return channels return channels
} }

View File

@ -1,19 +1,17 @@
import { createContext, useContext, useEffect, useState } from 'react' import { createContext, useContext, useEffect, useState } from 'react'
import { useRouter } from 'next/router' import { useRouter } from 'next/router'
import { GuildWithDefaultChannelId } from '../models/Guild' import type { GuildWithDefaultChannelId } from '../models/Guild'
import { Member } from '../models/Member' import type { Member } from '../models/Member'
import { useAuthentication } from '../tools/authentication' import { useAuthentication } from '../tools/authentication'
import { SocketData } from '../tools/handleSocketData' import type { SocketData } from '../tools/handleSocketData'
export interface GuildMember { export interface GuildMember {
guild: GuildWithDefaultChannelId guild: GuildWithDefaultChannelId
member: Member member: Member
} }
export interface GuildMemberResult extends GuildMember { export interface GuildMemberResult extends GuildMember {}
setGuildMember: React.Dispatch<React.SetStateAction<GuildMember>>
}
export interface GuildMemberProps { export interface GuildMemberProps {
guildMember: GuildMember guildMember: GuildMember
@ -79,8 +77,7 @@ export const GuildMemberProvider: React.FC<
return ( return (
<GuildMemberContext.Provider <GuildMemberContext.Provider
value={{ value={{
...guildMember, ...guildMember
setGuildMember
}} }}
> >
{children} {children}
@ -91,7 +88,9 @@ export const GuildMemberProvider: React.FC<
export const useGuildMember = (): GuildMemberResult => { export const useGuildMember = (): GuildMemberResult => {
const guildMember = useContext(GuildMemberContext) const guildMember = useContext(GuildMemberContext)
if (guildMember === defaultGuildMemberContext) { if (guildMember === defaultGuildMemberContext) {
throw new Error('useGuildMember must be used within GuildMemberProvider') throw new Error(
'`useGuildMember` must be used within `GuildMemberProvider`'
)
} }
return guildMember return guildMember
} }

View File

@ -1,9 +1,11 @@
import { createContext, useContext, useEffect } from 'react' import { createContext, useContext, useEffect } from 'react'
import { NextPage, usePagination } from '../hooks/usePagination' import type { NextPage } from '../hooks/usePagination'
import { usePagination } from '../hooks/usePagination'
import { useAuthentication } from '../tools/authentication' import { useAuthentication } from '../tools/authentication'
import { GuildWithDefaultChannelId } from '../models/Guild' import type { GuildWithDefaultChannelId } from '../models/Guild'
import { handleSocketData, SocketData } from '../tools/handleSocketData' import type { SocketData } from '../tools/handleSocketData'
import { handleSocketData } from '../tools/handleSocketData'
import { GUILDS_CACHE_KEY } from '../tools/cache' import { GUILDS_CACHE_KEY } from '../tools/cache'
export interface Guilds { export interface Guilds {
@ -62,7 +64,7 @@ export const GuildsProvider: React.FC<React.PropsWithChildren<{}>> = (
export const useGuilds = (): Guilds => { export const useGuilds = (): Guilds => {
const guilds = useContext(GuildsContext) const guilds = useContext(GuildsContext)
if (guilds === defaultGuildsContext) { if (guilds === defaultGuildsContext) {
throw new Error('useGuilds must be used within GuildsProvider') throw new Error('`useGuilds` must be used within `GuildsProvider`')
} }
return guilds return guilds
} }

View File

@ -1,12 +1,15 @@
import { createContext, useContext, useEffect } from 'react' import { createContext, useContext, useEffect, useMemo } from 'react'
import { NextPage, usePagination } from '../hooks/usePagination' import type { NextPage } from '../hooks/usePagination'
import { usePagination } from '../hooks/usePagination'
import { useAuthentication } from '../tools/authentication' import { useAuthentication } from '../tools/authentication'
import { MemberWithPublicUser } from '../models/Member' import type { MemberWithPublicUser } from '../models/Member'
import { GuildsChannelsPath } from '../components/Application' import type { GuildsChannelsPath } from '../components/Application'
import { handleSocketData, SocketData } from '../tools/handleSocketData' import type { SocketData } from '../tools/handleSocketData'
import { User } from '../models/User' import { handleSocketData } from '../tools/handleSocketData'
import { CacheKey, MEMBERS_CACHE_KEY } from '../tools/cache' import type { User } from '../models/User'
import type { CacheKey } from '../tools/cache'
import { MEMBERS_CACHE_KEY } from '../tools/cache'
export interface Members { export interface Members {
members: MemberWithPublicUser[] members: MemberWithPublicUser[]
@ -28,7 +31,9 @@ export const MembersProviders: React.FC<
const { authentication } = useAuthentication() const { authentication } = useAuthentication()
const cacheKey: CacheKey = `${path.guildId}-${MEMBERS_CACHE_KEY}` const cacheKey = useMemo<CacheKey>(() => {
return `${path.guildId}-${MEMBERS_CACHE_KEY}`
}, [path.guildId])
const { const {
items: members, items: members,
@ -89,7 +94,7 @@ export const MembersProviders: React.FC<
export const useMembers = (): Members => { export const useMembers = (): Members => {
const members = useContext(MembersContext) const members = useContext(MembersContext)
if (members === defaultMembersContext) { if (members === defaultMembersContext) {
throw new Error('useMembers must be used within MembersProvider') throw new Error('`useMembers` must be used within `MembersProvider`')
} }
return members return members
} }

View File

@ -1,11 +1,14 @@
import { createContext, useContext, useEffect } from 'react' import { createContext, useContext, useEffect, useMemo } from 'react'
import { NextPage, usePagination } from '../hooks/usePagination' import type { NextPage } from '../hooks/usePagination'
import { usePagination } from '../hooks/usePagination'
import { useAuthentication } from '../tools/authentication' import { useAuthentication } from '../tools/authentication'
import { MessageWithMember } from '../models/Message' import type { MessageWithMember } from '../models/Message'
import { GuildsChannelsPath } from '../components/Application' import type { GuildsChannelsPath } from '../components/Application'
import { handleSocketData, SocketData } from '../tools/handleSocketData' import type { SocketData } from '../tools/handleSocketData'
import { CacheKey, MESSAGES_CACHE_KEY } from '../tools/cache' import { handleSocketData } from '../tools/handleSocketData'
import type { CacheKey } from '../tools/cache'
import { MESSAGES_CACHE_KEY } from '../tools/cache'
export interface Messages { export interface Messages {
messages: MessageWithMember[] messages: MessageWithMember[]
@ -26,7 +29,9 @@ export const MessagesProvider: React.FC<
const { path, children } = props const { path, children } = props
const { authentication, user } = useAuthentication() const { authentication, user } = useAuthentication()
const cacheKey: CacheKey = `${path.channelId}-${MESSAGES_CACHE_KEY}` const cacheKey = useMemo<CacheKey>(() => {
return `${path.channelId}-${MESSAGES_CACHE_KEY}`
}, [path.channelId])
const { const {
items: messages, items: messages,
@ -88,7 +93,7 @@ export const MessagesProvider: React.FC<
export const useMessages = (): Messages => { export const useMessages = (): Messages => {
const messages = useContext(MessagesContext) const messages = useContext(MessagesContext)
if (messages === defaultMessagesContext) { if (messages === defaultMessagesContext) {
throw new Error('useMessages must be used within a MessagesProvider') throw new Error('`useMessages` must be used within a `MessagesProvider`')
} }
return messages return messages
} }

View File

@ -5,7 +5,7 @@ import { getLocal } from 'mockttp'
import type { Mockttp } from 'mockttp' import type { Mockttp } from 'mockttp'
import { API_DEFAULT_PORT } from './tools/api' import { API_DEFAULT_PORT } from './tools/api'
import { Handlers, Method } from './cypress/fixtures/handler' import type { Handlers, Method } from './cypress/fixtures/handler'
const UPLOADS_FIXTURES_DIRECTORY = path.join( const UPLOADS_FIXTURES_DIRECTORY = path.join(
process.cwd(), process.cwd(),

View File

@ -1,5 +1,7 @@
describe('Common > Header', () => { describe('Common > Header', () => {
beforeEach(() => cy.visit('/')) beforeEach(() => {
return cy.visit('/')
})
describe('Switch theme color (dark/light)', () => { describe('Switch theme color (dark/light)', () => {
it('should switch theme from `dark` (default) to `light`', () => { it('should switch theme from `dark` (default) to `light`', () => {

View File

@ -241,8 +241,8 @@ describe('Pages > /application/[guildId]/[channelId]', () => {
cy.visit('/application/abc/abc', { cy.visit('/application/abc/abc', {
failOnStatusCode: false failOnStatusCode: false
}) })
.location('pathname') .get('[data-cy=status-code]')
.should('eq', '/404') .contains('404')
}) })
it("should redirect the user to `/404` if `guildId` doesn't exist", () => { it("should redirect the user to `/404` if `guildId` doesn't exist", () => {
@ -253,8 +253,8 @@ describe('Pages > /application/[guildId]/[channelId]', () => {
cy.visit(`/application/123/${channelExample.id}`, { cy.visit(`/application/123/${channelExample.id}`, {
failOnStatusCode: false failOnStatusCode: false
}) })
.location('pathname') .get('[data-cy=status-code]')
.should('eq', '/404') .contains('404')
}) })
it("should redirect the user to `/404` if `channelId` doesn't exist", () => { it("should redirect the user to `/404` if `channelId` doesn't exist", () => {
@ -263,8 +263,8 @@ describe('Pages > /application/[guildId]/[channelId]', () => {
getGuildMemberWithGuildIdHandler getGuildMemberWithGuildIdHandler
]).setCookie('refreshToken', 'refresh-token') ]).setCookie('refreshToken', 'refresh-token')
cy.visit(`/application/${guildExample.id}/123`, { failOnStatusCode: false }) cy.visit(`/application/${guildExample.id}/123`, { failOnStatusCode: false })
.location('pathname') .get('[data-cy=status-code]')
.should('eq', '/404') .contains('404')
}) })
}) })

View File

@ -92,8 +92,8 @@ describe('Pages > /application/[guildId]/[channelId]/settings', () => {
cy.visit(`/application/${guildExample.id}/${channelExample.id}/settings`, { cy.visit(`/application/${guildExample.id}/${channelExample.id}/settings`, {
failOnStatusCode: false failOnStatusCode: false
}) })
.location('pathname') .get('[data-cy=status-code]')
.should('eq', '/404') .contains('404')
}) })
it('should redirect the user to `/404` if `guildId` or `channelId` are not numbers', () => { it('should redirect the user to `/404` if `guildId` or `channelId` are not numbers', () => {
@ -104,8 +104,8 @@ describe('Pages > /application/[guildId]/[channelId]/settings', () => {
cy.visit('/application/abc/abc/settings', { cy.visit('/application/abc/abc/settings', {
failOnStatusCode: false failOnStatusCode: false
}) })
.location('pathname') .get('[data-cy=status-code]')
.should('eq', '/404') .contains('404')
}) })
it("should redirect the user to `/404` if `guildId` doesn't exist", () => { it("should redirect the user to `/404` if `guildId` doesn't exist", () => {
@ -116,8 +116,8 @@ describe('Pages > /application/[guildId]/[channelId]/settings', () => {
cy.visit(`/application/123/${channelExample.id}/settings`, { cy.visit(`/application/123/${channelExample.id}/settings`, {
failOnStatusCode: false failOnStatusCode: false
}) })
.location('pathname') .get('[data-cy=status-code]')
.should('eq', '/404') .contains('404')
}) })
it("should redirect the user to `/404` if `channelId` doesn't exist", () => { it("should redirect the user to `/404` if `channelId` doesn't exist", () => {
@ -128,8 +128,8 @@ describe('Pages > /application/[guildId]/[channelId]/settings', () => {
cy.visit(`/application/${guildExample.id}/123/settings`, { cy.visit(`/application/${guildExample.id}/123/settings`, {
failOnStatusCode: false failOnStatusCode: false
}) })
.location('pathname') .get('[data-cy=status-code]')
.should('eq', '/404') .contains('404')
}) })
}) })

View File

@ -56,8 +56,8 @@ describe('Pages > /application/[guildId]/channels/create', () => {
cy.visit('/application/abc/channels/create', { cy.visit('/application/abc/channels/create', {
failOnStatusCode: false failOnStatusCode: false
}) })
.location('pathname') .get('[data-cy=status-code]')
.should('eq', '/404') .contains('404')
}) })
it("should redirect the user to `/404` if `guildId` doesn't exist", () => { it("should redirect the user to `/404` if `guildId` doesn't exist", () => {
@ -68,8 +68,8 @@ describe('Pages > /application/[guildId]/channels/create', () => {
cy.visit(`/application/123/channels/create`, { cy.visit(`/application/123/channels/create`, {
failOnStatusCode: false failOnStatusCode: false
}) })
.location('pathname') .get('[data-cy=status-code]')
.should('eq', '/404') .contains('404')
}) })
}) })

View File

@ -86,8 +86,8 @@ describe('Pages > /application/[guildId]/settings', () => {
cy.visit('/application/abc/settings', { cy.visit('/application/abc/settings', {
failOnStatusCode: false failOnStatusCode: false
}) })
.location('pathname') .get('[data-cy=status-code]')
.should('eq', '/404') .contains('404')
}) })
it("should redirect the user to `/404` if `guildId` doesn't exist", () => { it("should redirect the user to `/404` if `guildId` doesn't exist", () => {
@ -98,8 +98,8 @@ describe('Pages > /application/[guildId]/settings', () => {
cy.visit(`/application/123/settings`, { cy.visit(`/application/123/settings`, {
failOnStatusCode: false failOnStatusCode: false
}) })
.location('pathname') .get('[data-cy=status-code]')
.should('eq', '/404') .contains('404')
}) })
}) })

View File

@ -29,8 +29,8 @@ describe('Pages > /application/users/[userId]', () => {
'refresh-token' 'refresh-token'
) )
cy.visit(`/application/users/123`, { failOnStatusCode: false }) cy.visit(`/application/users/123`, { failOnStatusCode: false })
.location('pathname') .get('[data-cy=status-code]')
.should('eq', '/404') .contains('404')
}) })
}) })

View File

@ -1,4 +1,4 @@
import { Handler } from '../../handler' import type { Handler } from '../../handler'
import { channelExample, channelExample2 } from '../channel' import { channelExample, channelExample2 } from '../channel'
export const deleteChannelWithChannelIdHandler: Handler = { export const deleteChannelWithChannelIdHandler: Handler = {

View File

@ -1,4 +1,4 @@
import { Handler } from '../../handler' import type { Handler } from '../../handler'
import { channelExample, channelExample2 } from '../channel' import { channelExample, channelExample2 } from '../channel'
export const getChannelWithChannelIdHandler: Handler = { export const getChannelWithChannelIdHandler: Handler = {

View File

@ -1,4 +1,4 @@
import { Handler } from '../../../handler' import type { Handler } from '../../../handler'
import { import {
messageExampleComplete, messageExampleComplete,
messageExampleComplete2, messageExampleComplete2,

View File

@ -1,4 +1,4 @@
import { Handler } from '../../handler' import type { Handler } from '../../handler'
import { channelExample, channelExample2 } from '../channel' import { channelExample, channelExample2 } from '../channel'
export const putChannelWithChannelIdHandler: Handler = { export const putChannelWithChannelIdHandler: Handler = {

View File

@ -1,5 +1,5 @@
import { guildExample } from '../../guild' import { guildExample } from '../../guild'
import { Handler } from '../../../handler' import type { Handler } from '../../../handler'
import { channelExample, channelExample2 } from '../../../channels/channel' import { channelExample, channelExample2 } from '../../../channels/channel'
export const getChannelsWithGuildIdHandler: Handler = { export const getChannelsWithGuildIdHandler: Handler = {

View File

@ -1,5 +1,5 @@
import { guildExample } from '../../guild' import { guildExample } from '../../guild'
import { Handler } from '../../../handler' import type { Handler } from '../../../handler'
import { channelExample, channelExample2 } from '../../../channels/channel' import { channelExample, channelExample2 } from '../../../channels/channel'
export const postChannelsWithGuildIdHandler: Handler = { export const postChannelsWithGuildIdHandler: Handler = {

View File

@ -1,4 +1,4 @@
import { Handler } from '../../handler' import type { Handler } from '../../handler'
import { guildExample } from '../guild' import { guildExample } from '../guild'
export const deleteGuildWithGuildIdHandler: Handler = { export const deleteGuildWithGuildIdHandler: Handler = {

View File

@ -1,4 +1,4 @@
import { Handler } from '../../handler' import type { Handler } from '../../handler'
import { guildExample } from '../guild' import { guildExample } from '../guild'
import { memberExampleComplete } from '../../members/member' import { memberExampleComplete } from '../../members/member'

View File

@ -1,5 +1,5 @@
import { guildExample } from '../../guild' import { guildExample } from '../../guild'
import { Handler } from '../../../handler' import type { Handler } from '../../../handler'
import { memberExampleComplete } from '../../../members/member' import { memberExampleComplete } from '../../../members/member'
export const getMembersWithGuildIdHandler: Handler = { export const getMembersWithGuildIdHandler: Handler = {

View File

@ -1,5 +1,5 @@
import { guildExample } from '../../guild' import { guildExample } from '../../guild'
import { Handler } from '../../../handler' import type { Handler } from '../../../handler'
import { memberExampleComplete } from '../../../members/member' import { memberExampleComplete } from '../../../members/member'
import { channelExample } from '../../../channels/channel' import { channelExample } from '../../../channels/channel'

View File

@ -1,5 +1,5 @@
import { guildExample } from '../../guild' import { guildExample } from '../../guild'
import { Handler } from '../../../handler' import type { Handler } from '../../../handler'
import { memberExample } from '../../../members/member' import { memberExample } from '../../../members/member'
export const deleteLeaveMembersWithGuildIdHandler: Handler = { export const deleteLeaveMembersWithGuildIdHandler: Handler = {

View File

@ -1,4 +1,4 @@
import { Handler } from '../handler' import type { Handler } from '../handler'
import { guildExample, guildExample2 } from './guild' import { guildExample, guildExample2 } from './guild'
export const getGuildsHandler: Handler = { export const getGuildsHandler: Handler = {

View File

@ -1,4 +1,4 @@
import { Guild } from '../../../models/Guild' import type { Guild } from '../../../models/Guild'
export const guildExample: Guild = { export const guildExample: Guild = {
id: 1, id: 1,

View File

@ -1,4 +1,4 @@
import { Handler } from '../handler' import type { Handler } from '../handler'
import { guildExample } from './guild' import { guildExample } from './guild'
import { channelExample } from '../channels/channel' import { channelExample } from '../channels/channel'
import { memberExampleComplete } from '../members/member' import { memberExampleComplete } from '../members/member'

View File

@ -1,4 +1,4 @@
import { Handler } from '../../handler' import type { Handler } from '../../handler'
import { guildExample, guildExample2 } from '../guild' import { guildExample, guildExample2 } from '../guild'
export const getGuildsPublicEmptyHandler: Handler = { export const getGuildsPublicEmptyHandler: Handler = {

View File

@ -1,4 +1,4 @@
import { Handler } from '../../handler' import type { Handler } from '../../handler'
import { import {
messageExampleComplete6, messageExampleComplete6,
messageExampleComplete7, messageExampleComplete7,

View File

@ -1,4 +1,4 @@
import { Handler } from '../../handler' import type { Handler } from '../../handler'
import { userExample, userSettingsExample } from '../user' import { userExample, userSettingsExample } from '../user'
export const getUserByIdHandler: Handler = { export const getUserByIdHandler: Handler = {

View File

@ -1,4 +1,4 @@
import { Handler } from '../../handler' import type { Handler } from '../../handler'
import { userExample, userSettingsExample } from '../user' import { userExample, userSettingsExample } from '../user'
export const getUsersCurrentHandler: Handler = { export const getUsersCurrentHandler: Handler = {

View File

@ -1,4 +1,4 @@
import { Handler } from '../../handler' import type { Handler } from '../../handler'
export const postUsersRefreshTokenHandler: Handler = { export const postUsersRefreshTokenHandler: Handler = {
method: 'POST', method: 'POST',

View File

@ -1,4 +1,4 @@
import { Handler } from '../../handler' import type { Handler } from '../../handler'
export const postUsersResetPasswordHandler: Handler = { export const postUsersResetPasswordHandler: Handler = {
method: 'POST', method: 'POST',

View File

@ -1,4 +1,4 @@
import { Handler } from '../../handler' import type { Handler } from '../../handler'
export const putUsersResetPasswordHandler: Handler = { export const putUsersResetPasswordHandler: Handler = {
method: 'PUT', method: 'PUT',

View File

@ -1,4 +1,4 @@
import { Handler } from '../../handler' import type { Handler } from '../../handler'
export const postUsersSigninHandler: Handler = { export const postUsersSigninHandler: Handler = {
method: 'POST', method: 'POST',

View File

@ -1,4 +1,4 @@
import { Handler } from '../../handler' import type { Handler } from '../../handler'
import { userExample, userSettingsExample } from '../user' import { userExample, userSettingsExample } from '../user'
export const postUsersSignupHandler: Handler = { export const postUsersSignupHandler: Handler = {

View File

@ -1,5 +1,5 @@
import { UserSettings } from '../../../models/UserSettings' import type { UserSettings } from '../../../models/UserSettings'
import { User } from '../../../models/User' import type { User } from '../../../models/User'
export const userExample: User = { export const userExample: User = {
id: 1, id: 1,

View File

@ -4,7 +4,7 @@ export interface {{ properCase name }}Props {
className?: string className?: string
} }
export const {{ properCase name }}: React.FC<React.PropsWithChildren{{ properCase name }}Props>> = (props) => { export const {{ properCase name }}: React.FC<React.PropsWithChildren<{{ properCase name }}Props>> = (props) => {
const { children, className } = props const { children, className } = props
return <main className={classNames(className, '')}>{children}</main> return <main className={classNames(className, '')}>{children}</main>

View File

@ -1,12 +1,9 @@
import { useState, useRef, useCallback } from 'react' import { useState, useRef, useCallback } from 'react'
import { AxiosInstance } from 'axios' import type { AxiosInstance } from 'axios'
import type { FetchState } from 'react-component-form' import type { FetchState } from 'react-component-form'
import { import type { CacheKey } from '../tools/cache'
CacheKey, import { getPaginationCache, savePaginationCache } from '../tools/cache'
getPaginationCache,
savePaginationCache
} from '../tools/cache'
export interface Query { export interface Query {
[key: string]: string [key: string]: string
@ -45,15 +42,6 @@ export const usePagination = <T extends PaginationItem>(
const fetchState = useRef<FetchState>('idle') const fetchState = useRef<FetchState>('idle')
const afterId = useRef<number | null>(null) const afterId = useRef<number | null>(null)
const updateAfterId = (newItems: T[]): void => {
if (!inverse) {
afterId.current =
newItems.length > 0 ? newItems[newItems.length - 1].id : null
} else {
afterId.current = newItems.length > 0 ? newItems[0].id : null
}
}
const nextPageAsync: NextPageAsync = useCallback( const nextPageAsync: NextPageAsync = useCallback(
async (query) => { async (query) => {
if (fetchState.current !== 'idle') { if (fetchState.current !== 'idle') {
@ -68,21 +56,33 @@ export const usePagination = <T extends PaginationItem>(
const { data: newItems } = await api.get<T[]>( const { data: newItems } = await api.get<T[]>(
`${url}?${searchParameters.toString()}` `${url}?${searchParameters.toString()}`
) )
updateAfterId(newItems) if (!inverse) {
afterId.current =
newItems.length > 0 ? newItems[newItems.length - 1].id : null
} else {
afterId.current = newItems.length > 0 ? newItems[0].id : null
}
setItems((oldItems) => { setItems((oldItems) => {
const updatedItems = inverse const updatedItems = inverse
? [...newItems, ...oldItems] ? [...newItems, ...oldItems]
: [...oldItems, ...newItems] : [...oldItems, ...newItems]
const unique = updatedItems.reduce<T[]>((accumulator, item) => {
const isExisting = accumulator.some((itemSome) => {
return itemSome.id === item.id
})
if (!isExisting) {
accumulator.push(item)
}
return accumulator
}, [])
if (cacheKey != null) { if (cacheKey != null) {
savePaginationCache(cacheKey, updatedItems) savePaginationCache(cacheKey, unique)
} }
return updatedItems return unique
}) })
setHasMore(newItems.length > 0) setHasMore(newItems.length > 0)
fetchState.current = 'idle' fetchState.current = 'idle'
}, },
// eslint-disable-next-line react-hooks/exhaustive-deps -- We don't want infinite loops with updateAfterId
[api, url, inverse, cacheKey] [api, url, inverse, cacheKey]
) )
@ -106,13 +106,18 @@ export const usePagination = <T extends PaginationItem>(
afterId.current = null afterId.current = null
setItems([]) setItems([])
} else { } else {
fetchState.current = 'loading'
const newItems = getPaginationCache<T>(cacheKey) const newItems = getPaginationCache<T>(cacheKey)
setItems(newItems) setItems(newItems)
updateAfterId(newItems) if (!inverse) {
afterId.current =
newItems.length > 0 ? newItems[newItems.length - 1].id : null
} else {
afterId.current = newItems.length > 0 ? newItems[0].id : null
}
fetchState.current = 'idle'
} }
}, [cacheKey, inverse])
// eslint-disable-next-line react-hooks/exhaustive-deps -- We don't want infinite loops with updateAfterId
}, [cacheKey])
return { items, hasMore, nextPage, resetPagination, setItems } return { items, hasMore, nextPage, resetPagination, setItems }
} }

View File

@ -1,4 +1,5 @@
import { Type, Static } from '@sinclair/typebox' import type { Static } from '@sinclair/typebox'
import { Type } from '@sinclair/typebox'
import { date, id } from './utils' import { date, id } from './utils'

View File

@ -1,4 +1,5 @@
import { Type, Static } from '@sinclair/typebox' import type { Static } from '@sinclair/typebox'
import { Type } from '@sinclair/typebox'
import { channelSchema } from './Channel' import { channelSchema } from './Channel'
import { memberSchema } from './Member' import { memberSchema } from './Member'

View File

@ -1,7 +1,8 @@
import { Type, Static } from '@sinclair/typebox' import type { Static } from '@sinclair/typebox'
import { Type } from '@sinclair/typebox'
import { date, id } from './utils' import { date, id } from './utils'
import { UserPublicWithoutSettings } from './User' import type { UserPublicWithoutSettings } from './User'
export const memberSchema = { export const memberSchema = {
id, id,

View File

@ -1,7 +1,8 @@
import { Type, Static } from '@sinclair/typebox' import type { Static } from '@sinclair/typebox'
import { Type } from '@sinclair/typebox'
import { date, id } from './utils' import { date, id } from './utils'
import { MemberWithPublicUser } from './Member' import type { MemberWithPublicUser } from './Member'
export const types = [Type.Literal('text'), Type.Literal('file')] export const types = [Type.Literal('text'), Type.Literal('file')]

View File

@ -5,12 +5,12 @@ import { date, id } from './utils'
export const providers = ['Google', 'GitHub', 'Discord'] as const export const providers = ['Google', 'GitHub', 'Discord'] as const
export const strategies = [...providers, 'Local'] as const export const strategies = [...providers, 'Local'] as const
export const strategiesTypebox = strategies.map((strategy) => export const strategiesTypebox = strategies.map((strategy) => {
Type.Literal(strategy) return Type.Literal(strategy)
) })
export const providersTypebox = providers.map((provider) => export const providersTypebox = providers.map((provider) => {
Type.Literal(provider) return Type.Literal(provider)
) })
export type ProviderOAuth = typeof providers[number] export type ProviderOAuth = typeof providers[number]
export type AuthenticationStrategy = typeof strategies[number] export type AuthenticationStrategy = typeof strategies[number]

View File

@ -1,4 +1,5 @@
import { Static, Type } from '@sinclair/typebox' import type { Static } from '@sinclair/typebox'
import { Type } from '@sinclair/typebox'
import { strategiesTypebox } from './OAuth' import { strategiesTypebox } from './OAuth'
import { userSettingsSchema } from './UserSettings' import { userSettingsSchema } from './UserSettings'

View File

@ -1,4 +1,5 @@
import { Type, Static } from '@sinclair/typebox' import type { Static } from '@sinclair/typebox'
import { Type } from '@sinclair/typebox'
import { date, id } from './utils' import { date, id } from './utils'

1003
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -1,6 +1,6 @@
{ {
"name": "@thream/website", "name": "@thream/website",
"version": "1.2.0", "version": "1.3.0",
"private": true, "private": true,
"repository": { "repository": {
"type": "git", "type": "git",
@ -20,7 +20,7 @@
"lint:editorconfig": "editorconfig-checker", "lint:editorconfig": "editorconfig-checker",
"lint:markdown": "markdownlint-cli2", "lint:markdown": "markdownlint-cli2",
"lint:typescript": "eslint \"**/*.{js,jsx,ts,tsx}\" --ignore-path \".gitignore\"", "lint:typescript": "eslint \"**/*.{js,jsx,ts,tsx}\" --ignore-path \".gitignore\"",
"lint:prettier": "prettier \".\" --check", "lint:prettier": "prettier \".\" --check --ignore-path \".gitignore\"",
"lint:staged": "lint-staged", "lint:staged": "lint-staged",
"test:unit": "cypress run --component", "test:unit": "cypress run --component",
"test:html-w3c-validator": "start-server-and-test \"start\" \"http://localhost:3000\" \"html-w3c-validator\"", "test:html-w3c-validator": "start-server-and-test \"start\" \"http://localhost:3000\" \"html-w3c-validator\"",
@ -35,12 +35,13 @@
"@fontsource/montserrat": "4.5.12", "@fontsource/montserrat": "4.5.12",
"@fontsource/roboto": "4.5.8", "@fontsource/roboto": "4.5.8",
"@heroicons/react": "1.0.6", "@heroicons/react": "1.0.6",
"@sinclair/typebox": "0.24.28", "@sinclair/typebox": "0.24.34",
"axios": "0.26.1", "axios": "0.26.1",
"clsx": "1.2.1", "clsx": "1.2.1",
"date-and-time": "2.4.1", "date-and-time": "2.4.1",
"emoji-mart": "3.0.1", "emoji-mart": "3.0.1",
"katex": "0.16.1", "framer-motion": "7.2.1",
"katex": "0.16.2",
"next": "12.2.5", "next": "12.2.5",
"next-pwa": "5.6.0", "next-pwa": "5.6.0",
"next-themes": "0.2.0", "next-themes": "0.2.0",
@ -67,7 +68,7 @@
"universal-cookie": "4.0.4" "universal-cookie": "4.0.4"
}, },
"devDependencies": { "devDependencies": {
"@commitlint/cli": "17.1.1", "@commitlint/cli": "17.1.2",
"@commitlint/config-conventional": "17.1.0", "@commitlint/config-conventional": "17.1.0",
"@lhci/cli": "0.9.0", "@lhci/cli": "0.9.0",
"@saithodev/semantic-release-backmerge": "2.1.2", "@saithodev/semantic-release-backmerge": "2.1.2",
@ -75,18 +76,18 @@
"@types/emoji-mart": "3.0.9", "@types/emoji-mart": "3.0.9",
"@types/hast": "2.3.4", "@types/hast": "2.3.4",
"@types/katex": "0.14.0", "@types/katex": "0.14.0",
"@types/node": "18.7.13", "@types/node": "18.7.14",
"@types/react": "18.0.17", "@types/react": "18.0.18",
"@types/react-responsive": "8.0.5", "@types/react-responsive": "8.0.5",
"@types/react-syntax-highlighter": "15.5.5", "@types/react-syntax-highlighter": "15.5.5",
"@types/unist": "2.0.6", "@types/unist": "2.0.6",
"@typescript-eslint/eslint-plugin": "5.35.1", "@typescript-eslint/eslint-plugin": "5.36.1",
"@typescript-eslint/parser": "5.35.1", "@typescript-eslint/parser": "5.36.1",
"autoprefixer": "10.4.8", "autoprefixer": "10.4.8",
"cypress": "10.6.0", "cypress": "10.7.0",
"editorconfig-checker": "4.0.2", "editorconfig-checker": "4.0.2",
"eslint": "8.23.0", "eslint": "8.23.0",
"eslint-config-conventions": "3.0.0", "eslint-config-conventions": "4.0.0",
"eslint-config-next": "12.2.5", "eslint-config-next": "12.2.5",
"eslint-config-prettier": "8.5.0", "eslint-config-prettier": "8.5.0",
"eslint-plugin-import": "2.26.0", "eslint-plugin-import": "2.26.0",

View File

@ -1,10 +1,11 @@
import { GetStaticProps, NextPage } from 'next' import type { GetStaticProps, NextPage } from 'next'
import useTranslation from 'next-translate/useTranslation' import useTranslation from 'next-translate/useTranslation'
import { ErrorPage } from '../components/ErrorPage' import { ErrorPage } from '../components/ErrorPage'
import { Head } from '../components/Head' import { Head } from '../components/Head'
import { Header } from '../components/Header' import { Header } from '../components/Header'
import { Footer, FooterProps } from '../components/Footer' import type { FooterProps } from '../components/Footer'
import { Footer } from '../components/Footer'
const Error404: NextPage<FooterProps> = (props) => { const Error404: NextPage<FooterProps> = (props) => {
const { t } = useTranslation() const { t } = useTranslation()

View File

@ -1,10 +1,11 @@
import { GetStaticProps, NextPage } from 'next' import type { GetStaticProps, NextPage } from 'next'
import useTranslation from 'next-translate/useTranslation' import useTranslation from 'next-translate/useTranslation'
import { ErrorPage } from '../components/ErrorPage' import { ErrorPage } from '../components/ErrorPage'
import { Head } from '../components/Head' import { Head } from '../components/Head'
import { Header } from '../components/Header' import { Header } from '../components/Header'
import { Footer, FooterProps } from '../components/Footer' import type { FooterProps } from '../components/Footer'
import { Footer } from '../components/Footer'
const Error500: NextPage<FooterProps> = (props) => { const Error500: NextPage<FooterProps> = (props) => {
const { t } = useTranslation() const { t } = useTranslation()

View File

@ -1,5 +1,5 @@
import { useEffect } from 'react' import { useEffect } from 'react'
import { AppProps } from 'next/app' import type { AppProps } from 'next/app'
import { ThemeProvider } from 'next-themes' import { ThemeProvider } from 'next-themes'
import useTranslation from 'next-translate/useTranslation' import useTranslation from 'next-translate/useTranslation'

View File

@ -1,22 +1,20 @@
import { NextPage } from 'next' import type { NextPage } from 'next'
import { Head } from '../../../../components/Head' import { Head } from '../../../../components/Head'
import { Application } from '../../../../components/Application' import { Application } from '../../../../components/Application'
import { Messages } from '../../../../components/Application/Messages' import { Messages } from '../../../../components/Application/Messages'
import { SendMessage } from '../../../../components/Application/SendMessage' import { SendMessage } from '../../../../components/Application/SendMessage'
import type { PagePropsWithAuthentication } from '../../../../tools/authentication'
import { import {
authenticationFromServerSide, authenticationFromServerSide,
AuthenticationProvider, AuthenticationProvider
PagePropsWithAuthentication
} from '../../../../tools/authentication' } from '../../../../tools/authentication'
import { import type { GuildMember } from '../../../../contexts/GuildMember'
GuildMember, import { GuildMemberProvider } from '../../../../contexts/GuildMember'
GuildMemberProvider
} from '../../../../contexts/GuildMember'
import { GuildLeftSidebar } from '../../../../components/Application/GuildLeftSidebar' import { GuildLeftSidebar } from '../../../../components/Application/GuildLeftSidebar'
import { ChannelsProvider } from '../../../../contexts/Channels' import { ChannelsProvider } from '../../../../contexts/Channels'
import { GuildsProvider } from '../../../../contexts/Guilds' import { GuildsProvider } from '../../../../contexts/Guilds'
import { Channel } from '../../../../models/Channel' import type { Channel } from '../../../../models/Channel'
import { MessagesProvider } from '../../../../contexts/Messages' import { MessagesProvider } from '../../../../contexts/Messages'
import { MembersProviders } from '../../../../contexts/Members' import { MembersProviders } from '../../../../contexts/Members'
@ -68,10 +66,7 @@ export const getServerSideProps = authenticationFromServerSide({
const guildId = Number(context?.params?.guildId) const guildId = Number(context?.params?.guildId)
if (isNaN(channelId) || isNaN(guildId)) { if (isNaN(channelId) || isNaN(guildId)) {
return { return {
redirect: { notFound: true
destination: '/404',
permanent: false
}
} }
} }
const { data: guildMember } = await api.get(`/guilds/${guildId}`) const { data: guildMember } = await api.get(`/guilds/${guildId}`)

View File

@ -1,21 +1,19 @@
import { NextPage } from 'next' import type { NextPage } from 'next'
import { Head } from '../../../../components/Head' import { Head } from '../../../../components/Head'
import { Application } from '../../../../components/Application' import { Application } from '../../../../components/Application'
import type { PagePropsWithAuthentication } from '../../../../tools/authentication'
import { import {
authenticationFromServerSide, authenticationFromServerSide,
AuthenticationProvider, AuthenticationProvider
PagePropsWithAuthentication
} from '../../../../tools/authentication' } from '../../../../tools/authentication'
import { import type { GuildMember } from '../../../../contexts/GuildMember'
GuildMember, import { GuildMemberProvider } from '../../../../contexts/GuildMember'
GuildMemberProvider
} from '../../../../contexts/GuildMember'
import { GuildLeftSidebar } from '../../../../components/Application/GuildLeftSidebar' import { GuildLeftSidebar } from '../../../../components/Application/GuildLeftSidebar'
import { ChannelSettings } from '../../../../components/Application/ChannelSettings' import { ChannelSettings } from '../../../../components/Application/ChannelSettings'
import { ChannelsProvider } from '../../../../contexts/Channels' import { ChannelsProvider } from '../../../../contexts/Channels'
import { GuildsProvider } from '../../../../contexts/Guilds' import { GuildsProvider } from '../../../../contexts/Guilds'
import { Channel } from '../../../../models/Channel' import type { Channel } from '../../../../models/Channel'
import { MembersProviders } from '../../../../contexts/Members' import { MembersProviders } from '../../../../contexts/Members'
export interface ChannelSettingsPageProps extends PagePropsWithAuthentication { export interface ChannelSettingsPageProps extends PagePropsWithAuthentication {
@ -63,10 +61,7 @@ export const getServerSideProps = authenticationFromServerSide({
const guildId = Number(context?.params?.guildId) const guildId = Number(context?.params?.guildId)
if (isNaN(channelId) || isNaN(guildId)) { if (isNaN(channelId) || isNaN(guildId)) {
return { return {
redirect: { notFound: true
destination: '/404',
permanent: false
}
} }
} }
const { data: guildMember } = await api.get<GuildMember>( const { data: guildMember } = await api.get<GuildMember>(
@ -74,10 +69,7 @@ export const getServerSideProps = authenticationFromServerSide({
) )
if (!guildMember.member.isOwner) { if (!guildMember.member.isOwner) {
return { return {
redirect: { notFound: true
destination: '/404',
permanent: false
}
} }
} }
const { data: selectedChannelData } = await api.get( const { data: selectedChannelData } = await api.get(

View File

@ -1,19 +1,17 @@
import { NextPage } from 'next' import type { NextPage } from 'next'
import useTranslation from 'next-translate/useTranslation' import useTranslation from 'next-translate/useTranslation'
import { Head } from '../../../../components/Head' import { Head } from '../../../../components/Head'
import { Application } from '../../../../components/Application' import { Application } from '../../../../components/Application'
import type { PagePropsWithAuthentication } from '../../../../tools/authentication'
import { import {
authenticationFromServerSide, authenticationFromServerSide,
AuthenticationProvider, AuthenticationProvider
PagePropsWithAuthentication
} from '../../../../tools/authentication' } from '../../../../tools/authentication'
import { CreateChannel } from '../../../../components/Application/CreateChannel' import { CreateChannel } from '../../../../components/Application/CreateChannel'
import { GuildsProvider } from '../../../../contexts/Guilds' import { GuildsProvider } from '../../../../contexts/Guilds'
import { import type { GuildMember } from '../../../../contexts/GuildMember'
GuildMember, import { GuildMemberProvider } from '../../../../contexts/GuildMember'
GuildMemberProvider
} from '../../../../contexts/GuildMember'
export interface CreateChannelPageProps extends PagePropsWithAuthentication { export interface CreateChannelPageProps extends PagePropsWithAuthentication {
guildId: number guildId: number
@ -49,10 +47,7 @@ export const getServerSideProps = authenticationFromServerSide({
const guildId = Number(context?.params?.guildId) const guildId = Number(context?.params?.guildId)
if (isNaN(guildId)) { if (isNaN(guildId)) {
return { return {
redirect: { notFound: true
destination: '/404',
permanent: false
}
} }
} }
const { data: guildMember } = await api.get(`/guilds/${guildId}`) const { data: guildMember } = await api.get(`/guilds/${guildId}`)

View File

@ -1,14 +1,15 @@
import { NextPage } from 'next' import type { NextPage } from 'next'
import useTranslation from 'next-translate/useTranslation' import useTranslation from 'next-translate/useTranslation'
import { Head } from '../../../components/Head' import { Head } from '../../../components/Head'
import { Application } from '../../../components/Application' import { Application } from '../../../components/Application'
import type { PagePropsWithAuthentication } from '../../../tools/authentication'
import { import {
authenticationFromServerSide, authenticationFromServerSide,
AuthenticationProvider, AuthenticationProvider
PagePropsWithAuthentication
} from '../../../tools/authentication' } from '../../../tools/authentication'
import { GuildMember, GuildMemberProvider } from '../../../contexts/GuildMember' import type { GuildMember } from '../../../contexts/GuildMember'
import { GuildMemberProvider } from '../../../contexts/GuildMember'
import { GuildsProvider } from '../../../contexts/Guilds' import { GuildsProvider } from '../../../contexts/Guilds'
import { GuildSettings } from '../../../components/Application/GuildSettings' import { GuildSettings } from '../../../components/Application/GuildSettings'
@ -43,10 +44,7 @@ export const getServerSideProps = authenticationFromServerSide({
const guildId = Number(context?.params?.guildId) const guildId = Number(context?.params?.guildId)
if (isNaN(guildId)) { if (isNaN(guildId)) {
return { return {
redirect: { notFound: true
destination: '/404',
permanent: false
}
} }
} }
const { data: guildMember } = await api.get<GuildMember>( const { data: guildMember } = await api.get<GuildMember>(

View File

@ -1,12 +1,12 @@
import { NextPage } from 'next' import type { NextPage } from 'next'
import useTranslation from 'next-translate/useTranslation' import useTranslation from 'next-translate/useTranslation'
import { Head } from '../../../components/Head' import { Head } from '../../../components/Head'
import { Application } from '../../../components/Application' import { Application } from '../../../components/Application'
import type { PagePropsWithAuthentication } from '../../../tools/authentication'
import { import {
authenticationFromServerSide, authenticationFromServerSide,
AuthenticationProvider, AuthenticationProvider
PagePropsWithAuthentication
} from '../../../tools/authentication' } from '../../../tools/authentication'
import { CreateGuild } from '../../../components/Application/CreateGuild' import { CreateGuild } from '../../../components/Application/CreateGuild'
import { GuildsProvider } from '../../../contexts/Guilds' import { GuildsProvider } from '../../../contexts/Guilds'

View File

@ -1,12 +1,12 @@
import { NextPage } from 'next' import type { NextPage } from 'next'
import useTranslation from 'next-translate/useTranslation' import useTranslation from 'next-translate/useTranslation'
import { Head } from '../../../components/Head' import { Head } from '../../../components/Head'
import { Application } from '../../../components/Application' import { Application } from '../../../components/Application'
import type { PagePropsWithAuthentication } from '../../../tools/authentication'
import { import {
authenticationFromServerSide, authenticationFromServerSide,
AuthenticationProvider, AuthenticationProvider
PagePropsWithAuthentication
} from '../../../tools/authentication' } from '../../../tools/authentication'
import { JoinGuildsPublic } from '../../../components/Application/JoinGuildsPublic' import { JoinGuildsPublic } from '../../../components/Application/JoinGuildsPublic'
import { GuildsProvider } from '../../../contexts/Guilds' import { GuildsProvider } from '../../../contexts/Guilds'

View File

@ -1,12 +1,12 @@
import { NextPage } from 'next' import type { NextPage } from 'next'
import { Head } from '../../components/Head' import { Head } from '../../components/Head'
import { Application } from '../../components/Application' import { Application } from '../../components/Application'
import { PopupGuild } from '../../components/Application/PopupGuild' import { PopupGuild } from '../../components/Application/PopupGuild'
import type { PagePropsWithAuthentication } from '../../tools/authentication'
import { import {
authenticationFromServerSide, authenticationFromServerSide,
AuthenticationProvider, AuthenticationProvider
PagePropsWithAuthentication
} from '../../tools/authentication' } from '../../tools/authentication'
import { GuildsProvider } from '../../contexts/Guilds' import { GuildsProvider } from '../../contexts/Guilds'

View File

@ -1,16 +1,16 @@
import { NextPage } from 'next' import type { NextPage } from 'next'
import { Head } from '../../../../components/Head' import { Head } from '../../../../components/Head'
import { Application } from '../../../../components/Application' import { Application } from '../../../../components/Application'
import type { PagePropsWithAuthentication } from '../../../../tools/authentication'
import { import {
authenticationFromServerSide, authenticationFromServerSide,
AuthenticationProvider, AuthenticationProvider
PagePropsWithAuthentication
} from '../../../../tools/authentication' } from '../../../../tools/authentication'
import { UserProfile } from '../../../../components/Application/UserProfile' import { UserProfile } from '../../../../components/Application/UserProfile'
import { GuildsProvider } from '../../../../contexts/Guilds' import { GuildsProvider } from '../../../../contexts/Guilds'
import { UserPublic } from '../../../../models/User' import type { UserPublic } from '../../../../models/User'
import { Guild } from '../../../../models/Guild' import type { Guild } from '../../../../models/Guild'
export interface UserProfilePageProps extends PagePropsWithAuthentication { export interface UserProfilePageProps extends PagePropsWithAuthentication {
user: UserPublic user: UserPublic
@ -38,10 +38,7 @@ export const getServerSideProps = authenticationFromServerSide({
const userId = Number(context?.params?.userId) const userId = Number(context?.params?.userId)
if (isNaN(userId)) { if (isNaN(userId)) {
return { return {
redirect: { notFound: true
destination: '/404',
permanent: false
}
} }
} }
const { data } = await api.get(`/users/${userId}`) const { data } = await api.get(`/users/${userId}`)

View File

@ -1,12 +1,12 @@
import { NextPage } from 'next' import type { NextPage } from 'next'
import useTranslation from 'next-translate/useTranslation' import useTranslation from 'next-translate/useTranslation'
import { Head } from '../../../components/Head' import { Head } from '../../../components/Head'
import { Application } from '../../../components/Application' import { Application } from '../../../components/Application'
import type { PagePropsWithAuthentication } from '../../../tools/authentication'
import { import {
authenticationFromServerSide, authenticationFromServerSide,
AuthenticationProvider, AuthenticationProvider
PagePropsWithAuthentication
} from '../../../tools/authentication' } from '../../../tools/authentication'
import { UserSettings } from '../../../components/Application/UserSettings' import { UserSettings } from '../../../components/Application/UserSettings'
import { GuildsProvider } from '../../../contexts/Guilds' import { GuildsProvider } from '../../../contexts/Guilds'

View File

@ -1,4 +1,4 @@
import { NextPage } from 'next' import type { NextPage } from 'next'
import Link from 'next/link' import Link from 'next/link'
import useTranslation from 'next-translate/useTranslation' import useTranslation from 'next-translate/useTranslation'
import axios from 'axios' import axios from 'axios'
@ -9,7 +9,8 @@ import { AuthenticationForm } from '../../components/Authentication'
import { Head } from '../../components/Head' import { Head } from '../../components/Head'
import { Header } from '../../components/Header' import { Header } from '../../components/Header'
import { Main } from '../../components/design/Main' import { Main } from '../../components/design/Main'
import { Footer, FooterProps } from '../../components/Footer' import type { FooterProps } from '../../components/Footer'
import { Footer } from '../../components/Footer'
import { Input } from '../../components/design/Input' import { Input } from '../../components/design/Input'
import { Button } from '../../components/design/Button' import { Button } from '../../components/design/Button'
import { FormState } from '../../components/design/FormState' import { FormState } from '../../components/design/FormState'

View File

@ -1,4 +1,4 @@
import { NextPage } from 'next' import type { NextPage } from 'next'
import { useRouter } from 'next/router' import { useRouter } from 'next/router'
import useTranslation from 'next-translate/useTranslation' import useTranslation from 'next-translate/useTranslation'
import axios from 'axios' import axios from 'axios'
@ -9,7 +9,8 @@ import { Head } from '../../components/Head'
import { Header } from '../../components/Header' import { Header } from '../../components/Header'
import { FormState } from '../../components/design/FormState' import { FormState } from '../../components/design/FormState'
import { Main } from '../../components/design/Main' import { Main } from '../../components/design/Main'
import { Footer, FooterProps } from '../../components/Footer' import type { FooterProps } from '../../components/Footer'
import { Footer } from '../../components/Footer'
import { Input } from '../../components/design/Input' import { Input } from '../../components/design/Input'
import { Button } from '../../components/design/Button' import { Button } from '../../components/design/Button'
import { authenticationFromServerSide } from '../../tools/authentication' import { authenticationFromServerSide } from '../../tools/authentication'

View File

@ -1,10 +1,11 @@
import { NextPage } from 'next' import type { NextPage } from 'next'
import useTranslation from 'next-translate/useTranslation' import useTranslation from 'next-translate/useTranslation'
import { Head } from '../../components/Head' import { Head } from '../../components/Head'
import { Authentication } from '../../components/Authentication' import { Authentication } from '../../components/Authentication'
import { Header } from '../../components/Header' import { Header } from '../../components/Header'
import { Footer, FooterProps } from '../../components/Footer' import type { FooterProps } from '../../components/Footer'
import { Footer } from '../../components/Footer'
import { authenticationFromServerSide } from '../../tools/authentication' import { authenticationFromServerSide } from '../../tools/authentication'
import { ScrollableBody } from '../../components/ScrollableBody' import { ScrollableBody } from '../../components/ScrollableBody'

View File

@ -1,10 +1,11 @@
import { NextPage } from 'next' import type { NextPage } from 'next'
import useTranslation from 'next-translate/useTranslation' import useTranslation from 'next-translate/useTranslation'
import { Head } from '../../components/Head' import { Head } from '../../components/Head'
import { Authentication } from '../../components/Authentication' import { Authentication } from '../../components/Authentication'
import { Header } from '../../components/Header' import { Header } from '../../components/Header'
import { Footer, FooterProps } from '../../components/Footer' import type { FooterProps } from '../../components/Footer'
import { Footer } from '../../components/Footer'
import { authenticationFromServerSide } from '../../tools/authentication' import { authenticationFromServerSide } from '../../tools/authentication'
import { ScrollableBody } from '../../components/ScrollableBody' import { ScrollableBody } from '../../components/ScrollableBody'

View File

@ -1,4 +1,4 @@
import { GetStaticProps, NextPage } from 'next' import type { GetStaticProps, NextPage } from 'next'
import Link from 'next/link' import Link from 'next/link'
import Image from 'next/image' import Image from 'next/image'
import Translation from 'next-translate/Trans' import Translation from 'next-translate/Trans'
@ -7,7 +7,8 @@ import useTranslation from 'next-translate/useTranslation'
import { Head } from '../components/Head' import { Head } from '../components/Head'
import { Header } from '../components/Header' import { Header } from '../components/Header'
import { Main } from '../components/design/Main' import { Main } from '../components/design/Main'
import { Footer, FooterProps } from '../components/Footer' import type { FooterProps } from '../components/Footer'
import { Footer } from '../components/Footer'
import { SocialMediaLink } from '../components/design/SocialMediaButton' import { SocialMediaLink } from '../components/design/SocialMediaButton'
import { ButtonLink } from '../components/design/Button' import { ButtonLink } from '../components/design/Button'
import { ScrollableBody } from '../components/ScrollableBody' import { ScrollableBody } from '../components/ScrollableBody'

View File

@ -1,10 +1,13 @@
import axios, { AxiosInstance } from 'axios' import type { AxiosInstance } from 'axios'
import { io, Socket } from 'socket.io-client' import axios from 'axios'
import type { Socket } from 'socket.io-client'
import { io } from 'socket.io-client'
import { API_URL } from '../api' import { API_URL } from '../api'
import { cookies } from '../cookies' import { cookies } from '../cookies'
import { Tokens } from '.' import type { Tokens } from '.'
import { fetchRefreshToken } from './authenticationFromServerSide' import { fetchRefreshToken } from './authenticationFromServerSide'
import { clearCache } from '../cache'
export class Authentication { export class Authentication {
public tokens: Tokens public tokens: Tokens
@ -15,7 +18,7 @@ export class Authentication {
constructor(tokens: Tokens, disableSocketIO: boolean = false) { constructor(tokens: Tokens, disableSocketIO: boolean = false) {
this.tokens = tokens this.tokens = tokens
this.accessTokenAge = Date.now() this.accessTokenAge = Date.now()
if (disableSocketIO || typeof window === 'undefined') { if (typeof window === 'undefined' || disableSocketIO) {
this.socket = undefined this.socket = undefined
} else { } else {
this.socket = io(API_URL, { this.socket = io(API_URL, {
@ -99,7 +102,7 @@ export class Authentication {
public signout(): void { public signout(): void {
cookies.remove('refreshToken') cookies.remove('refreshToken')
window.localStorage.clear() clearCache()
window.location.href = '/authentication/signin' window.location.href = '/authentication/signin'
} }
@ -120,6 +123,7 @@ export class Authentication {
} }
public signin(): void { public signin(): void {
clearCache()
cookies.set('refreshToken', this.tokens.refreshToken) cookies.set('refreshToken', this.tokens.refreshToken)
} }
} }

Some files were not shown because too many files have changed in this diff Show More