Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
79265f4
feat: add ChannelHeader (WIP)
Meiryo7743 Feb 23, 2025
2243a75
fix: modify the header structure of AppShell and ChannelHeader (but s…
Meiryo7743 Mar 2, 2025
e9052dc
fix: page.tsx
Meiryo7743 Mar 2, 2025
2d02130
feat: add the ChannelHeader to display a channel name at the AppShell…
Meiryo7743 Mar 2, 2025
1d8a8b1
fix: AppShell
Meiryo7743 Mar 2, 2025
b041024
fix: ChannelHeader
Meiryo7743 Mar 2, 2025
28e5b19
fix: errors on import order
Meiryo7743 Mar 2, 2025
2e0b3af
fix: resolve errors found by ESLint
Meiryo7743 Mar 2, 2025
53ce296
fix: ChannelHeader
Meiryo7743 Mar 2, 2025
4cc9e67
fix: resolve errors found by ESLint
Meiryo7743 Mar 2, 2025
3def0b2
fix: title format
Meiryo7743 Mar 7, 2025
6767588
chore: renamed
Meiryo7743 Mar 22, 2025
6e8181d
fix: modify
Meiryo7743 Mar 30, 2025
0537bad
fix: move AppShell as a global component
Meiryo7743 Mar 30, 2025
6226c6b
fix: wrap AppShell
Meiryo7743 Mar 30, 2025
c79d380
Revert "fix: wrap AppShell"
saka-naname May 25, 2025
eb366a7
Revert "fix: move AppShell as a global component"
saka-naname May 25, 2025
d7fd1be
Revert "fix: modify"
saka-naname May 25, 2025
6f22186
Revert "chore: renamed"
saka-naname May 25, 2025
ece91ab
fix: 一旦ChannelHeaderだけにタイトル表示の機能を持たせる
saka-naname May 25, 2025
fedf36e
feat: 現在のチャンネルをContextで管理
saka-naname Jun 8, 2025
734a202
feat: ドキュメントタイトルの変更機能をCurrentChannelControllerに移動
saka-naname Jun 8, 2025
c2309be
Merge branch 'main' into feat/channel-header (resolve conflict)
saka-naname Jun 8, 2025
ab76c1f
fix: 移植
saka-naname Jun 8, 2025
f65a5b6
fix: 誤って追加した参照を削除
saka-naname Jun 8, 2025
cc408fc
feat: タイトルの設定をgenerateMetadataに移管
saka-naname Jun 11, 2025
28be38d
chore: lint
saka-naname Jun 11, 2025
65050ac
feat: チャンネルヘッダーの表示
saka-naname Jun 11, 2025
0f906d6
fix: Change error comment into Japanese
saka-naname Jun 15, 2025
5a72b62
fix: Remove unneccesary include
saka-naname Jun 15, 2025
445a15b
fix: Style
saka-naname Jun 15, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/app/_components/AppShell.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { Burger, Group, AppShell as MantineAppShell } from "@mantine/core";
import { useDisclosure } from "@mantine/hooks";

import styles from "./AppShell.module.css";
import MobileChannelDisplay from "./MobileChannelDisplay";
import Sidebar from "./Sidebar";

type AppShellProps = {
Expand All @@ -30,7 +31,7 @@ const AppShell: React.FC<AppShellProps> = ({ children }) => {
<MantineAppShell.Header>
<Group h="100%" px="md">
<Burger opened={opened} onClick={toggle} hiddenFrom="sm" size="sm" />
digichat
<MobileChannelDisplay />
</Group>
</MantineAppShell.Header>
<Sidebar />
Expand Down
14 changes: 14 additions & 0 deletions src/app/_components/MobileChannelDisplay.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
"use client";

import { Text } from "@mantine/core";

import { useCurrentChannel } from "#/hooks/useCurrentChannel";

/**
* 余計な再描画を防ぐため、チャンネル名を参照する部分を AppShell から分離
*/
export default function MobileChannelDisplay() {
const { currentChannel } = useCurrentChannel();

return <Text hiddenFrom="sm">{currentChannel && currentChannel.slug}</Text>;
}
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
.root {
position: relative;
display: flex;
flex-direction: column;
max-width: 100%;
height: 100svh;
min-height: 100vh;
padding-top: 3rem;
}

.message-area {
display: flex;
flex-direction: column;
height: 100%;
overflow-y: scroll;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { useLayoutEffect, useRef } from "react";
import { Box } from "@mantine/core";

import ChannelFooter from "../ChannelFooter/ChannelFooter";
import ChannelHeader from "../ChannelHeader/ChannelHeader";

import styles from "./Channel.module.css";

Expand Down Expand Up @@ -38,7 +39,8 @@ const Channel: React.FC<ChannelProps> = ({ channel_id, messages, user_id }) => {
}, [messages]);

return (
<Box className={styles["root"]}>
<Box className={styles["root"]} pt={{ base: "3rem", sm: "6rem" }}>
<ChannelHeader />
<Box className={styles["message-area"]}>
{messages.map((message) => (
<Message
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
.root {
position: absolute;
top: 3rem;
z-index: 10;
width: 100%;
Copy link
Member

Choose a reason for hiding this comment

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

sidebarがあるとき横が突き抜けてしまっているようです!

スクリーンショット 2025-06-13 12 57 58

Copy link
Contributor

Choose a reason for hiding this comment

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

修正します!

height: 3rem;
padding-inline: 1rem;
background-color: var(--mantine-color-body);
border-bottom: 1px solid var(--mantine-color-gray-3);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
"use client";

import { Group } from "@mantine/core";

import styles from "./ChannelHeader.module.css";

import { useCurrentChannel } from "#/hooks/useCurrentChannel";

const ChannelHeader: React.FC = () => {
const { currentChannel } = useCurrentChannel();

return (
<Group className={styles["root"]} visibleFrom="sm">
{currentChannel && currentChannel.slug}
</Group>
);
};

export default ChannelHeader;
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
"use client";

import { useEffect } from "react";

import { Channel } from "@prisma/client";

import { useCurrentChannel } from "#/hooks/useCurrentChannel";

export default function CurrentChannelController({
channel,
}: {
channel: Channel | null;
}) {
const { setCurrentChannel } = useCurrentChannel();

/**
* チャンネルのページを開いている間、コンテキストにチャンネルの情報を保存する
*/
useEffect(() => {
setCurrentChannel(channel);

return () => {
setCurrentChannel(null);
};
}, [channel, setCurrentChannel]);

return null;
}
28 changes: 25 additions & 3 deletions src/app/channels/[channel_id]/page.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import { Metadata } from "next";
import { redirect } from "next/navigation";

import Channel from "./_components/Channel/Channel";
import CurrentChannelController from "./_components/CurrentChannelController";

import { auth } from "#/libs/auth";
import { prisma } from "#/libs/prisma";
Expand All @@ -9,8 +11,9 @@ type ChannelIDPageProps = {
params: Promise<{ channel_id: string }>;
};

async function ChannelIDPage({ params }: ChannelIDPageProps) {
const session = await auth();
export async function generateMetadata({
params,
}: ChannelIDPageProps): Promise<Metadata> {
const { channel_id } = await params;
const channel = await prisma.channel.findUnique({
where: {
Expand All @@ -20,6 +23,22 @@ async function ChannelIDPage({ params }: ChannelIDPageProps) {
members: true,
},
});

if (!channel) return {};

return {
title: `${channel.slug} | Digichat`,
};
}

async function ChannelIDPage({ params }: ChannelIDPageProps) {
const session = await auth();
const { channel_id } = await params;
const channel = await prisma.channel.findUnique({
where: {
id: channel_id,
},
});
const messages = await prisma.message.findMany({
where: {
channelId: channel_id,
Expand All @@ -41,7 +60,10 @@ async function ChannelIDPage({ params }: ChannelIDPageProps) {
const user_id = session.user.id;

return (
<Channel channel_id={channel_id} messages={messages} user_id={user_id} />
<>
<CurrentChannelController channel={channel} />
<Channel channel_id={channel_id} messages={messages} user_id={user_id} />
</>
);
}

Expand Down
10 changes: 7 additions & 3 deletions src/app/layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ import "@mantine/code-highlight/styles.css";
import "@mantine/core/styles.css";
import AppShell from "./_components/AppShell";
import ChannelsAccordionProvider from "./_components/ChannelsAccordionProvider";

import { CurrentChannelProvider } from "#/contexts/CurrentChannelContext";
import "./globals.css";

dayjs.extend(utc);
Expand Down Expand Up @@ -38,9 +40,11 @@ export default function RootLayout({ children }: RootRayoutProps) {
<body>
<SessionProvider>
<MantineProvider>
<ChannelsAccordionProvider>
<AppShell>{children}</AppShell>
</ChannelsAccordionProvider>
<CurrentChannelProvider>
<ChannelsAccordionProvider>
<AppShell>{children}</AppShell>
</ChannelsAccordionProvider>
</CurrentChannelProvider>
</MantineProvider>
</SessionProvider>
</body>
Expand Down
32 changes: 32 additions & 0 deletions src/contexts/CurrentChannelContext.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
"use client";

import { createContext, SetStateAction, useState } from "react";

import { Channel } from "@prisma/client";

export type CurrentChannelContextType = {
currentChannel: Channel | null;
setCurrentChannel: React.Dispatch<SetStateAction<Channel | null>>;
};

export const CurrentChannelContext =
createContext<CurrentChannelContextType | null>(null);

export function CurrentChannelProvider({
children,
}: {
children: React.ReactNode;
}) {
const [currentChannel, setCurrentChannel] = useState<Channel | null>(null);

return (
<CurrentChannelContext.Provider
value={{
currentChannel,
setCurrentChannel,
}}
>
{children}
</CurrentChannelContext.Provider>
);
}
20 changes: 20 additions & 0 deletions src/hooks/useCurrentChannel.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
"use client";

import { useContext } from "react";

import { CurrentChannelContext } from "#/contexts/CurrentChannelContext";

/**
* 現在開いているチャンネルの情報を利用する
* @returns getter 及び setter
*/
export function useCurrentChannel() {
const context = useContext(CurrentChannelContext);

if (!context)
throw new Error(
"useCurrentChannel は <CurrentChannelProvider> 内で使用される必要があります"
);

return context;
}