This commit is contained in:
xeltica 2021-09-04 23:29:41 +09:00
parent 8adeb4fe5b
commit 2c2385ac59
2 changed files with 69 additions and 47 deletions

View File

@ -1,18 +1,39 @@
import React from 'react'; import React from 'react';
import { useGetScoreQuery } from '../services/session'; import { useGetScoreQuery, useGetSessionQuery } from '../services/session';
export const SessionData: React.VFC = () => { export const SessionData: React.VFC = () => {
const { data: score, error, isLoading } = useGetScoreQuery(undefined); const session = useGetSessionQuery(undefined);
const score = useGetScoreQuery(undefined);
return isLoading ? ( return session.isLoading || score.isLoading ? (
<div>Loading...</div> <div>Loading...</div>
) : score === undefined ? (
<div>No score</div>
) : ( ) : (
<> <>
{session.data && (
<section>
<p>
<a
href={`https://${session.data.host}/@${session.data.username}`}
target="_blank"
rel="noreferrer noopener"
>
@{session.data.username}@{session.data.host}
</a>
</p>
<p>
<strong>
:
</strong>
{session.data.rating}
</p>
</section>
)}
{score.data && (
<section> <section>
<h2></h2> <h2></h2>
<table className="table"> <table className="table fluid">
<thead> <thead>
<tr> <tr>
<th></th> <th></th>
@ -23,22 +44,23 @@ export const SessionData: React.VFC = () => {
<tbody> <tbody>
<tr> <tr>
<td></td> <td></td>
<td>{score.notesCount}</td> <td>{score.data.notesCount}</td>
<td>{score.notesDelta}</td> <td>{score.data.notesDelta}</td>
</tr> </tr>
<tr> <tr>
<td></td> <td></td>
<td>{score.followingCount}</td> <td>{score.data.followingCount}</td>
<td>{score.followingDelta}</td> <td>{score.data.followingDelta}</td>
</tr> </tr>
<tr> <tr>
<td></td> <td></td>
<td>{score.followersCount}</td> <td>{score.data.followersCount}</td>
<td>{score.followersDelta}</td> <td>{score.data.followersDelta}</td>
</tr> </tr>
</tbody> </tbody>
</table> </table>
</section> </section>
)}
</> </>
); );
}; };

View File

@ -2,12 +2,12 @@ import React, { useMemo, useState } from 'react';
import { Header } from '../components/Header'; import { Header } from '../components/Header';
import { SessionData } from '../components/SessionData'; import { SessionData } from '../components/SessionData';
import { Ranking } from '../components/Ranking';
import { Tab, TabItem } from '../components/Tab'; import { Tab, TabItem } from '../components/Tab';
import { useGetSessionQuery } from '../services/session';
export const IndexSessionPage: React.VFC = () => { export const IndexSessionPage: React.VFC = () => {
const { data: session, error, isLoading } = useGetSessionQuery(undefined);
const [selectedTab, setSelectedTab] = useState<number>(0); const [selectedTab, setSelectedTab] = useState<number>(0);
const items = useMemo<TabItem[]>(() => ([ const items = useMemo<TabItem[]>(() => ([
{ {
label: 'データ', label: 'データ',
@ -20,21 +20,21 @@ export const IndexSessionPage: React.VFC = () => {
}, },
]), []); ]), []);
return isLoading ? ( const component = useMemo(() => {
<div>Loading...</div> switch (selectedTab) {
) : error ? ( case 0: return <SessionData />;
<div>Error: {error}</div> case 1: return <Ranking limit={10}/>;
) : ( default: return null;
}
}, [selectedTab]);
return (
<> <>
<Header> <Header />
<article className="mt-4">
{session?.username}
</article>
</Header>
<div className="xarticle card" style={{borderRadius: 'var(--radius)'}}> <div className="xarticle card" style={{borderRadius: 'var(--radius)'}}>
<Tab items={items} selected={selectedTab} onSelect={setSelectedTab}/> <Tab items={items} selected={selectedTab} onSelect={setSelectedTab}/>
<article className="container"> <article className="container">
{selectedTab === 0 && <SessionData /> } {component}
</article> </article>
</div> </div>
</> </>