feat(contexts): add GuildMember

This commit is contained in:
Divlo
2021-12-28 19:18:47 +01:00
parent 3f6ab4a0ea
commit d8667b12a0
7 changed files with 137 additions and 66 deletions

View File

@ -8,33 +8,46 @@ import {
AuthenticationProvider,
PagePropsWithAuthentication
} from 'utils/authentication'
import { GuildMember, GuildMemberProvider } from 'contexts/GuildMember'
import { GuildLeftSidebar } from 'components/Application/GuildLeftSidebar'
export interface ChannelPageProps extends PagePropsWithAuthentication {
channelId: number
guildId: number
guildMember: GuildMember
}
const ChannelPage: NextPage<ChannelPageProps> = (props) => {
const { channelId, guildId, authentication } = props
const { channelId, guildId, authentication, guildMember } = props
return (
<AuthenticationProvider authentication={authentication}>
<Head title='Thream | Application' />
<Application
path={{
channelId,
guildId
}}
>
<Messages />
</Application>
<GuildMemberProvider guildMember={guildMember}>
<Head title='Thream | Application' />
<Application
path={{
channelId,
guildId
}}
guildLeftSidebar={
<GuildLeftSidebar
path={{
channelId,
guildId
}}
/>
}
>
<Messages />
</Application>
</GuildMemberProvider>
</AuthenticationProvider>
)
}
export const getServerSideProps = authenticationFromServerSide({
shouldBeAuthenticated: true,
fetchData: async (context) => {
fetchData: async (context, api) => {
const channelId = Number(context?.params?.channelId)
const guildId = Number(context?.params?.guildId)
if (isNaN(channelId) || isNaN(guildId)) {
@ -45,9 +58,11 @@ export const getServerSideProps = authenticationFromServerSide({
}
}
}
const { data: guildMember } = await api.get(`/guilds/${guildId}`)
return {
channelId,
guildId
guildId,
guildMember
}
}
})