feat: add guilds and channels CRUD (#14)

This commit is contained in:
Divlo
2022-03-05 18:22:30 +01:00
committed by GitHub
parent 9f56a10305
commit 780788d682
50 changed files with 6459 additions and 9039 deletions

View File

@ -0,0 +1,92 @@
import { NextPage } from 'next'
import { Head } from 'components/Head'
import { Application } from 'components/Application'
import {
authenticationFromServerSide,
AuthenticationProvider,
PagePropsWithAuthentication
} from 'tools/authentication'
import { GuildMember, GuildMemberProvider } from 'contexts/GuildMember'
import { GuildLeftSidebar } from 'components/Application/GuildLeftSidebar'
import { ChannelSettings } from 'components/Application/ChannelSettings'
import { ChannelsProvider } from 'contexts/Channels'
import { GuildsProvider } from 'contexts/Guilds'
import { Channel } from 'models/Channel'
import { MembersProviders } from 'contexts/Members'
export interface ChannelSettingsPageProps extends PagePropsWithAuthentication {
channelId: number
guildId: number
guildMember: GuildMember
selectedChannel: Channel
}
const ChannelSettingsPage: NextPage<ChannelSettingsPageProps> = (props) => {
const { channelId, guildId, authentication, guildMember, selectedChannel } =
props
const path = {
channelId,
guildId
}
return (
<AuthenticationProvider authentication={authentication}>
<GuildsProvider>
<GuildMemberProvider guildMember={guildMember} path={path}>
<MembersProviders path={path}>
<ChannelsProvider path={path}>
<Head title='Thream | Application' />
<Application
path={path}
guildLeftSidebar={<GuildLeftSidebar path={path} />}
title={`# ${selectedChannel.name}`}
>
<ChannelSettings channel={selectedChannel} />
</Application>
</ChannelsProvider>
</MembersProviders>
</GuildMemberProvider>
</GuildsProvider>
</AuthenticationProvider>
)
}
export const getServerSideProps = authenticationFromServerSide({
shouldBeAuthenticated: true,
fetchData: async (context, api) => {
const channelId = Number(context?.params?.channelId)
const guildId = Number(context?.params?.guildId)
if (isNaN(channelId) || isNaN(guildId)) {
return {
redirect: {
destination: '/404',
permanent: false
}
}
}
const { data: guildMember } = await api.get<GuildMember>(
`/guilds/${guildId}`
)
if (!guildMember.member.isOwner) {
return {
redirect: {
destination: '/404',
permanent: false
}
}
}
const { data: selectedChannelData } = await api.get(
`/channels/${channelId}`
)
return {
channelId,
guildId,
guildMember,
selectedChannel: selectedChannelData.channel
}
}
})
export default ChannelSettingsPage

View File

@ -0,0 +1,61 @@
import { NextPage } from 'next'
import { Head } from 'components/Head'
import { Application } from 'components/Application'
import {
authenticationFromServerSide,
AuthenticationProvider,
PagePropsWithAuthentication
} from 'tools/authentication'
import { CreateChannel } from 'components/Application/CreateChannel'
import { GuildsProvider } from 'contexts/Guilds'
import { GuildMember, GuildMemberProvider } from 'contexts/GuildMember'
export interface CreateChannelPageProps extends PagePropsWithAuthentication {
guildId: number
guildMember: GuildMember
}
const CreateChannelPage: NextPage<CreateChannelPageProps> = (props) => {
const { guildId, authentication, guildMember } = props
const path = { guildId }
return (
<AuthenticationProvider authentication={authentication}>
<GuildsProvider>
<GuildMemberProvider guildMember={guildMember} path={path}>
<Head
title={`Thream | Crée un channel`}
description={'Crée un nouveau channel'}
/>
<Application path={path} title={'Crée un channel'}>
<CreateChannel />
</Application>
</GuildMemberProvider>
</GuildsProvider>
</AuthenticationProvider>
)
}
export const getServerSideProps = authenticationFromServerSide({
shouldBeAuthenticated: true,
fetchData: async (context, api) => {
const guildId = Number(context?.params?.guildId)
if (isNaN(guildId)) {
return {
redirect: {
destination: '/404',
permanent: false
}
}
}
const { data: guildMember } = await api.get(`/guilds/${guildId}`)
return {
guildId,
guildMember
}
}
})
export default CreateChannelPage

View File

@ -0,0 +1,60 @@
import { NextPage } from 'next'
import { Head } from 'components/Head'
import { Application } from 'components/Application'
import {
authenticationFromServerSide,
AuthenticationProvider,
PagePropsWithAuthentication
} from 'tools/authentication'
import { GuildMember, GuildMemberProvider } from 'contexts/GuildMember'
import { GuildsProvider } from 'contexts/Guilds'
import { GuildSettings } from 'components/Application/GuildSettings'
export interface GuildSettingsPageProps extends PagePropsWithAuthentication {
guildId: number
guildMember: GuildMember
}
const GuildSettingsPage: NextPage<GuildSettingsPageProps> = (props) => {
const { guildId, authentication, guildMember } = props
const path = { guildId }
return (
<AuthenticationProvider authentication={authentication}>
<GuildsProvider>
<GuildMemberProvider guildMember={guildMember} path={path}>
<Head title='Thream | Guild settings' />
<Application path={path} title='Guild settings'>
<GuildSettings />
</Application>
</GuildMemberProvider>
</GuildsProvider>
</AuthenticationProvider>
)
}
export const getServerSideProps = authenticationFromServerSide({
shouldBeAuthenticated: true,
fetchData: async (context, api) => {
const guildId = Number(context?.params?.guildId)
if (isNaN(guildId)) {
return {
redirect: {
destination: '/404',
permanent: false
}
}
}
const { data: guildMember } = await api.get<GuildMember>(
`/guilds/${guildId}`
)
return {
guildId,
guildMember
}
}
})
export default GuildSettingsPage