-
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.
add initial autor page; add loader to just grab voices for a single a…
…uthor (#11)
- Loading branch information
Showing
6 changed files
with
141 additions
and
5 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,62 @@ | ||
import React from "react"; | ||
import { AuthorLoaderValue } from "../../loaders/author-loader"; | ||
import { useLoaderData, useNavigate } from "react-router-dom"; | ||
import { | ||
Box, | ||
Button, | ||
Card, | ||
CardActions, | ||
CardContent, | ||
Typography, | ||
} from "@mui/material"; | ||
import { useStore } from "../../store/store"; | ||
|
||
export const Author: React.FC = () => { | ||
const [languageMode] = useStore((state) => [state.languageMode]); | ||
const author = useLoaderData() as AuthorLoaderValue; | ||
const navigate = useNavigate(); | ||
|
||
const handleNavigate = () => { | ||
navigate(`/display/author/${author.sys.id}`); | ||
}; | ||
|
||
const group = languageMode === "en-US" ? "Group" : "グループ"; | ||
const viewVoices = | ||
languageMode === "en-US" | ||
? "View all my Voices" | ||
: "自分のボイスをすべて見る"; | ||
|
||
return ( | ||
<Box | ||
sx={{ display: "flex" }} | ||
paddingTop={{ xs: "1rem", md: "5rem" }} | ||
paddingLeft={{ xs: "1rem", md: "5rem" }} | ||
paddingRight={{ xs: "1rem", md: "5rem" }} | ||
paddingBottom={{ xs: "1rem", md: "5rem" }} | ||
display="flex" | ||
justifyContent="center" | ||
> | ||
<Card | ||
sx={{ display: "flex", flexDirection: "column" }} | ||
variant="outlined" | ||
> | ||
<CardContent> | ||
<Typography gutterBottom variant="h1"> | ||
{author.fields.name} | ||
</Typography> | ||
<Typography gutterBottom variant="h5"> | ||
{author.fields.groupLocation} {group} | ||
</Typography> | ||
<Typography gutterBottom component="div" variant="body1"> | ||
{author.fields.biography} | ||
</Typography> | ||
</CardContent> | ||
<CardActions> | ||
<Button size="small" onClick={handleNavigate}> | ||
{viewVoices} | ||
</Button> | ||
</CardActions> | ||
</Card> | ||
</Box> | ||
); | ||
}; |
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 |
---|---|---|
|
@@ -28,7 +28,6 @@ export const Contact: React.FC = () => { | |
} = useForm<IFormInput>(); | ||
const theme = useTheme(); | ||
const emailAddress = "[email protected]"; | ||
|
||
const requiredErrorMessage = "Field is required."; | ||
|
||
const onSubmit: SubmitHandler<IFormInput> = (data) => { | ||
|
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,26 @@ | ||
import { getClient } from "../services/contentful/client"; | ||
import { VoiceEntry } from "../shared/content-types"; | ||
import { Locale } from "../shared/utilities"; | ||
|
||
export const AuthorEntryLoader = async ( | ||
languageMode: Locale, | ||
authorEntryId: string | undefined | ||
) => { | ||
const client = getClient(); | ||
// Add error handling | ||
const res = await client | ||
.getEntries<VoiceEntry>({ | ||
content_type: "entry", | ||
locale: languageMode, | ||
}) | ||
.then((res) => { | ||
return res.items.filter( | ||
(item) => item.fields.voiceAuthor.sys.id === authorEntryId | ||
); | ||
}); | ||
return res; | ||
}; | ||
|
||
export type AuthorEntryLoaderValue = Awaited< | ||
ReturnType<typeof AuthorEntryLoader> | ||
>; |
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,17 @@ | ||
import { getClient } from "../services/contentful/client"; | ||
import { VoiceAuthor } from "../shared/content-types"; | ||
import { Locale } from "../shared/utilities"; | ||
|
||
export const AuthorLoader = async ( | ||
languageMode: Locale, | ||
entryId: string | undefined | ||
) => { | ||
const client = getClient(); | ||
// Add error handling | ||
const res = await client.getEntry<VoiceAuthor>(entryId ?? "", { | ||
locale: languageMode, | ||
}); | ||
return res; | ||
}; | ||
|
||
export type AuthorLoaderValue = Awaited<ReturnType<typeof AuthorLoader>>; |