Skip to content

Commit

Permalink
serverから規約等を配信するように
Browse files Browse the repository at this point in the history
  • Loading branch information
mehm8128 committed Mar 23, 2024
1 parent 8ca2552 commit 661364b
Show file tree
Hide file tree
Showing 14 changed files with 60 additions and 10 deletions.
19 changes: 19 additions & 0 deletions workspaces/app/src/features/consts/apiClient/constApiClient.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { inject } from 'regexparam';

import type { DomainSpecificApiClientInterface } from '../../../lib/api/DomainSpecificApiClientInterface';
import { apiClient } from '../../../lib/api/apiClient';

type ConstApiClient = DomainSpecificApiClientInterface<{
fetch: [{ params: { id: 'company' | 'contact' | 'overview' | 'question' | 'term' } }, string];
}>;

export const constApiClient: ConstApiClient = {
fetch: async ({ params }) => {
const response = await apiClient.get<string>(inject('/api/v1/consts/:id', params));
return response.data;
},
fetch$$key: (options) => ({
requestUrl: `/api/v1/consts/:id`,
...options,
}),
};
7 changes: 7 additions & 0 deletions workspaces/app/src/features/consts/hooks/useConst.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import useSWR from 'swr';

import { constApiClient } from '../apiClient/constApiClient';

export function useConst(...[options]: Parameters<typeof constApiClient.fetch>) {
return useSWR(constApiClient.fetch$$key(options), constApiClient.fetch, { suspense: true });
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { useId } from 'react';
import styled from 'styled-components';

import { COMPANY } from '../constants/Company';
import { useConst } from '../../features/consts/hooks/useConst';
import { Color, Space, Typography } from '../styles/variables';

import { Spacer } from './Spacer';
Expand All @@ -11,6 +11,7 @@ const _Content = styled.section`
white-space: pre-line;
`;
export default function CompanyDialogContent() {
const { data } = useConst({ params: { id: 'company' } });
const companyDialogA11yId = useId();

return (
Expand All @@ -20,7 +21,7 @@ export default function CompanyDialogContent() {
</Text>
<Spacer height={Space * 1} />
<Text as="p" color={Color.MONO_100} typography={Typography.NORMAL12}>
{COMPANY}
{data}
</Text>
</_Content>
);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { useId } from 'react';
import styled from 'styled-components';

import { CONTACT } from '../constants/Contact';
import { useConst } from '../../features/consts/hooks/useConst';
import { Color, Space, Typography } from '../styles/variables';

import { Spacer } from './Spacer';
Expand All @@ -11,6 +11,7 @@ const _Content = styled.section`
white-space: pre-line;
`;
export default function ContactDialogContent() {
const { data } = useConst({ params: { id: 'contact' } });
const contactDialogA11yId = useId();

return (
Expand All @@ -20,7 +21,7 @@ export default function ContactDialogContent() {
</Text>
<Spacer height={Space * 1} />
<Text as="p" color={Color.MONO_100} typography={Typography.NORMAL12}>
{CONTACT}
{data}
</Text>
</_Content>
);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { useId } from 'react';
import styled from 'styled-components';

import { OVERVIEW } from '../constants/Overview';
import { useConst } from '../../features/consts/hooks/useConst';
import { Color, Space, Typography } from '../styles/variables';

import { Spacer } from './Spacer';
Expand All @@ -11,6 +11,7 @@ const _Content = styled.section`
white-space: pre-line;
`;
export default function OverviewDialogContent() {
const { data } = useConst({ params: { id: 'overview' } });
const overviewDialogA11yId = useId();

return (
Expand All @@ -20,7 +21,7 @@ export default function OverviewDialogContent() {
</Text>
<Spacer height={Space * 1} />
<Text as="p" color={Color.MONO_100} typography={Typography.NORMAL12}>
{OVERVIEW}
{data}
</Text>
</_Content>
);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { useId } from 'react';
import styled from 'styled-components';

import { QUESTION } from '../constants/Question';
import { useConst } from '../../features/consts/hooks/useConst';
import { Color, Space, Typography } from '../styles/variables';

import { Spacer } from './Spacer';
Expand All @@ -11,6 +11,7 @@ const _Content = styled.section`
white-space: pre-line;
`;
export default function QuestionDialogContent() {
const { data } = useConst({ params: { id: 'question' } });
const questionDialogA11yId = useId();

return (
Expand All @@ -20,7 +21,7 @@ export default function QuestionDialogContent() {
</Text>
<Spacer height={Space * 1} />
<Text as="p" color={Color.MONO_100} typography={Typography.NORMAL12}>
{QUESTION}
{data}
</Text>
</_Content>
);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { useId } from 'react';
import styled from 'styled-components';

import { TERM } from '../constants/Term';
import { useConst } from '../../features/consts/hooks/useConst';
import { Color, Space, Typography } from '../styles/variables';

import { Spacer } from './Spacer';
Expand All @@ -11,6 +11,7 @@ const _Content = styled.section`
white-space: pre-line;
`;
export default function TermDialogContent() {
const { data } = useConst({ params: { id: 'term' } });
const termDialogA11yId = useId();

return (
Expand All @@ -20,7 +21,7 @@ export default function TermDialogContent() {
</Text>
<Spacer height={Space * 1} />
<Text as="p" color={Color.MONO_100} typography={Typography.NORMAL12}>
{TERM}
{data}
</Text>
</_Content>
);
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
17 changes: 17 additions & 0 deletions workspaces/server/src/routes/api/consts/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { Hono } from 'hono';

import { COMPANY } from '../../../constants/company';
import { CONTACT } from '../../../constants/contact';
import { OVERVIEW } from '../../../constants/overview';
import { QUESTION } from '../../../constants/question';
import { TERM } from '../../../constants/term';

const app = new Hono();

app.get('/api/v1/consts/company', (c) => c.text(COMPANY));
app.get('/api/v1/consts/contact', (c) => c.text(CONTACT));
app.get('/api/v1/consts/overview', (c) => c.text(OVERVIEW));
app.get('/api/v1/consts/question', (c) => c.text(QUESTION));
app.get('/api/v1/consts/term', (c) => c.text(TERM));

export { app as constsApp };
2 changes: 2 additions & 0 deletions workspaces/server/src/routes/api/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { OpenAPIHono } from '@hono/zod-openapi';
import { authApp } from './auth';
import { authorApp } from './authors';
import { bookApp } from './books';
import { constsApp } from './consts';
import { episodePageApp } from './episodePages';
import { episodeApp } from './episodes';
import { featureApp } from './features';
Expand Down Expand Up @@ -31,6 +32,7 @@ app.get(
app.route('/', authorApp);
app.route('/', episodeApp);
app.route('/', bookApp);
app.route('/', constsApp);
app.route('/', episodePageApp);
app.route('/', imageApp);
app.route('/', featureApp);
Expand Down

0 comments on commit 661364b

Please sign in to comment.