-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
272 additions
and
170 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,22 @@ | ||
import React, { useEffect, useState } from 'react'; | ||
|
||
/** | ||
* A component that | ||
*/ | ||
export const DelayedLoadingMessage = () => { | ||
const [showLoading, setShowLoading] = useState(false); | ||
const loadingTimeout = 500; | ||
|
||
useEffect(() => { | ||
// Showing a loading message right away contributes to worse perceived performance | ||
const timeout = setTimeout(() => setShowLoading(true), loadingTimeout); | ||
|
||
return () => clearTimeout(timeout); | ||
}); | ||
|
||
if (showLoading) { | ||
return (<p>loading...</p>); | ||
} | ||
|
||
return null; | ||
}; |
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,40 @@ | ||
import React from 'react'; | ||
import { Link } from 'react-router-dom'; | ||
|
||
import { DelayedLoadingMessage } from './DelayedLoadingMessage'; | ||
import { useGuildMemberData } from './use-guild-member-data'; | ||
import { Welcome } from './Welcome'; | ||
import { GuildUserData } from '../App'; | ||
|
||
const getWelcomeMessage = (guildUser: GuildUserData) => { | ||
const welcome = 'welcome to the trash compactor'; | ||
|
||
if (guildUser?.user?.username) { | ||
return `${welcome}, ${guildUser.user.username}`; | ||
} | ||
|
||
return `${welcome}, <unknown>`; | ||
}; | ||
|
||
export const Home = () => { | ||
const guildUser = useGuildMemberData(); | ||
|
||
// TODO: FIXME: if not a guild member, user just sees 'loading...' forever | ||
if (guildUser) { | ||
return ( | ||
<> | ||
<ul className="navigation-list"> | ||
<li> | ||
<Link to="/new">new</Link> | ||
</li> | ||
<li> | ||
<Link to="/worlds">worlds</Link> | ||
</li> | ||
</ul> | ||
<Welcome message={getWelcomeMessage(guildUser)} /> | ||
</> | ||
); | ||
} | ||
|
||
return (<DelayedLoadingMessage />); | ||
}; |
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,23 @@ | ||
import React from 'react'; | ||
import { Link } from 'react-router-dom'; | ||
|
||
export const NewWorld = () => { | ||
return ( | ||
<> | ||
<ul className="navigation-list"> | ||
<li> | ||
<Link to="/">back</Link> | ||
</li> | ||
</ul> | ||
<form> | ||
<label htmlFor="version">version</label> | ||
<select name="version"> | ||
<option>1.20.1</option> | ||
</select> | ||
<label htmlFor="name">name</label> | ||
<input name="name" /> | ||
<button>create</button> | ||
</form> | ||
</> | ||
); | ||
}; |
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,11 @@ | ||
import React from 'react'; | ||
import { useParams } from 'react-router-dom'; | ||
|
||
export const WorldDetail = () => { | ||
const { worldId } = useParams(); | ||
return ( | ||
<> | ||
<h2>{worldId}</h2> | ||
</> | ||
); | ||
}; |
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 @@ | ||
import React from 'react'; | ||
import { Link, Outlet } from 'react-router-dom'; | ||
|
||
import { useRequest } from '../hooks/use-request'; | ||
|
||
type World = { | ||
id: number, | ||
label: string, | ||
version: string, | ||
createdAt: string, | ||
lastOnline: string, | ||
createdBy: string, | ||
}; | ||
|
||
type Worlds = World[]; | ||
|
||
export const Worlds = () => { | ||
const useWrapped = useRequest<Worlds>('/api/v1/worlds'); | ||
const { data: fakeWorlds } = useWrapped(); | ||
|
||
return ( | ||
<> | ||
<ul className="navigation-list"> | ||
<li> | ||
<Link to="/">back</Link> | ||
</li> | ||
</ul> | ||
<table> | ||
<thead> | ||
<tr> | ||
<td>name</td> | ||
<td>version</td> | ||
<td>created</td> | ||
<td>last online</td> | ||
<td>created by</td> | ||
</tr> | ||
</thead> | ||
<tbody> | ||
{fakeWorlds && fakeWorlds.map(({ id, label, version, createdAt, createdBy, lastOnline }) => { | ||
return ( | ||
<tr key={`${id}-${label}-${version}`}> | ||
<td><Link to={`${id}`}>{label}</Link></td> | ||
<td>{version}</td> | ||
<td>{new Date(createdAt).toLocaleDateString()}</td> | ||
<td>{new Date(lastOnline).toLocaleDateString()}</td> | ||
<td>{createdBy}</td> | ||
</tr> | ||
); | ||
})} | ||
</tbody> | ||
</table> | ||
<Outlet /> | ||
</> | ||
); | ||
}; |
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,7 @@ | ||
// import { renderHook } from '@testing-library/react'; | ||
|
||
describe('useGuildMemberData', () => { | ||
it('truths', () => { | ||
expect(true).toBeTruthy(); | ||
}); | ||
}); |
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
Oops, something went wrong.