-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #14 from sweshelo/main
v0.3.0
- Loading branch information
Showing
11 changed files
with
219 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import DeviationRankingPage from '@/features/deviation' | ||
import { fetchDeviationRanking } from '@/service/supabase/deviation-ranking' | ||
|
||
export default async function Page() { | ||
const ranking = await fetchDeviationRanking() | ||
|
||
return ranking ? ( | ||
<DeviationRankingPage ranking={ranking} /> | ||
) : ( | ||
<>ランキング情報の取得に失敗しました</> | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
export default async function Page() { | ||
return ( | ||
<> | ||
<div className="text-center"> | ||
<h1>プレーヤー検索</h1> | ||
<div className="m-4"> | ||
<p>準備中です</p> | ||
</div> | ||
</div> | ||
</> | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
'use client' | ||
|
||
import Link from 'next/link' | ||
|
||
import { useDrawer } from '@/hooks/drawer' | ||
|
||
export const Drawer = () => { | ||
const { isOpen, closeDrawer } = useDrawer() | ||
|
||
return ( | ||
<div> | ||
{/* オーバーレイ */} | ||
<div | ||
className={`fixed inset-0 bg-black bg-opacity-50 transition-opacity z-[1000] ${ | ||
isOpen ? 'opacity-100 visible' : 'opacity-0 invisible' | ||
}`} | ||
onClick={closeDrawer} | ||
/> | ||
|
||
{/* ドロワー本体 */} | ||
<div | ||
className={`fixed top-0 left-0 h-full w-64 bg-white shadow-lg transform transition-transform z-[2000] ${ | ||
isOpen ? 'translate-x-0' : '-translate-x-full' | ||
}`} | ||
> | ||
<div className="w-full bg-red-900"> | ||
<div className="max-w-[800px] mx-auto p-4 flex items-center space-x-4"> | ||
<button className="w-12 h-12 bg-gray-800 rounded-lg flex items-center justify-center bg-[url('/image/icon.png')] bg-contain" /> | ||
<div> | ||
<h1 className="text-white text-2xl font-bold">閻魔帳</h1> | ||
<p className="text-gray-300 text-xs">v2 "medusa" - @sweshelo</p> | ||
</div> | ||
</div> | ||
</div> | ||
<ul className="p-4 space-y-2"> | ||
<li> | ||
<Link href="/ranking" className="block p-2 hover:bg-gray-100"> | ||
ランキング | ||
</Link> | ||
</li> | ||
<li> | ||
<Link href="/deviation" className="block p-2 hover:bg-gray-100"> | ||
偏差値ランキング | ||
</Link> | ||
</li> | ||
<li> | ||
<Link href="/search" className="block p-2 hover:bg-gray-100"> | ||
プレイヤー検索 | ||
</Link> | ||
</li> | ||
</ul> | ||
</div> | ||
</div> | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,24 @@ | ||
'use client' | ||
|
||
import Link from 'next/link' | ||
|
||
import { useDrawer } from '@/hooks/drawer' | ||
|
||
export const Header = () => { | ||
const { openDrawer } = useDrawer() | ||
|
||
return ( | ||
<Link href={'/'}> | ||
<div className="w-full bg-red-900"> | ||
<div className="max-w-[800px] mx-auto p-4 flex items-center space-x-4"> | ||
<div className="w-12 h-12 bg-gray-800 rounded-lg flex items-center justify-center bg-[url('/image/icon.png')] bg-contain" /> | ||
<div className="flex-grow"> | ||
<h1 className="text-white text-2xl font-bold">閻魔帳</h1> | ||
<p className="text-gray-300 text-xs">v2 "medusa" - @sweshelo</p> | ||
</div> | ||
</div> | ||
<div className="w-full bg-red-900"> | ||
<div className="max-w-[800px] mx-auto p-4 flex items-center space-x-4"> | ||
<button | ||
className="w-12 h-12 bg-gray-800 rounded-lg flex items-center justify-center bg-[url('/image/icon.png')] bg-contain z-1" | ||
onClick={openDrawer} | ||
/> | ||
<Link className="flex-grow" href={'/'}> | ||
<h1 className="text-white text-2xl font-bold">閻魔帳</h1> | ||
<p className="text-gray-300 text-xs">v2 "medusa" - @sweshelo</p> | ||
</Link> | ||
</div> | ||
</Link> | ||
</div> | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import React from 'react' | ||
|
||
import { Headline } from '@/components/common/headline' | ||
import { PlayerCard } from '@/components/player/card' | ||
import { Player } from '@/types/player' | ||
import { Record } from '@/types/record' | ||
|
||
interface RankingPageProps { | ||
ranking: (Player & { | ||
record: Record | ||
})[] | ||
} | ||
|
||
const DeviationRankingPage = ({ ranking }: RankingPageProps) => { | ||
return ( | ||
<> | ||
<Headline title="偏差値ランキング" /> | ||
<div className="mt-4 mb-4 space-y-2"> | ||
{ranking.map((player, index) => ( | ||
<PlayerCard player={player} chara={player.record.chara} ranking={index + 1} key={index}> | ||
<div className="text-sm text-gray-600 ml-1">{`| ${player.deviation_value}`}</div> | ||
</PlayerCard> | ||
))} | ||
</div> | ||
</> | ||
) | ||
} | ||
|
||
export default DeviationRankingPage |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
'use client' | ||
|
||
import { createContext, useContext, useState, ReactNode } from 'react' | ||
|
||
type DrawerContextType = { | ||
isOpen: boolean | ||
openDrawer: () => void | ||
closeDrawer: () => void | ||
} | ||
|
||
const DrawerContext = createContext<DrawerContextType | undefined>(undefined) | ||
|
||
export const DrawerProvider = ({ children }: { children: ReactNode }) => { | ||
const [isOpen, setIsOpen] = useState(false) | ||
|
||
const openDrawer = () => setIsOpen(true) | ||
const closeDrawer = () => setIsOpen(false) | ||
|
||
return ( | ||
<DrawerContext.Provider value={{ isOpen, openDrawer, closeDrawer }}> | ||
{children} | ||
</DrawerContext.Provider> | ||
) | ||
} | ||
|
||
export const useDrawer = () => { | ||
const context = useContext(DrawerContext) | ||
if (!context) { | ||
throw new Error('useDrawer must be used within a DrawerProvider') | ||
} | ||
return context | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
'use cache' | ||
|
||
import { supabase } from './client' | ||
|
||
export const fetchDeviationRanking = async () => { | ||
const { data: players, error: playerError } = await supabase | ||
.from('player') | ||
.select('*') | ||
.gt('deviation_value', 50) | ||
.order('deviation_value', { ascending: false }) | ||
|
||
if (playerError) { | ||
console.error(`Error fetching player: ${playerError.message}`) | ||
} | ||
|
||
// 各プレイヤーに対して最新の record を取得する | ||
const playersWithRecord = await Promise.all( | ||
(players ?? []).map(async player => { | ||
const { data: records, error: recordError } = await supabase | ||
.from('record') | ||
.select('*') | ||
.eq('player_name', player.name) | ||
// 最新のレコードを取得するため created_at で降順にソートし、1件だけ取得 | ||
.order('created_at', { ascending: false }) | ||
.limit(1) | ||
|
||
if (recordError) { | ||
console.error(`Error fetching record for player ${player.name}: ${recordError.message}`) | ||
} | ||
|
||
const [record] = records ?? [] | ||
|
||
return { | ||
...player, | ||
record, | ||
} | ||
}) | ||
) | ||
|
||
return playersWithRecord | ||
} |