Skip to content
This repository has been archived by the owner on Jan 2, 2022. It is now read-only.

Feature/add editpage #133

Merged
merged 30 commits into from
Mar 20, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
52d189f
feat: firebase library
hosonokotaro Feb 16, 2021
bc9cbd1
Squashed commit of the following:
hosonokotaro Feb 21, 2021
58b551b
feat: add auth page
hosonokotaro Feb 21, 2021
f21e634
fix: move store files
hosonokotaro Feb 23, 2021
15d0dae
fix: move page files
hosonokotaro Feb 23, 2021
02c66a7
feat: split edit page
hosonokotaro Feb 23, 2021
222c8d2
fix: delete chunk filename
hosonokotaro Feb 23, 2021
91d4000
wip: add create post
hosonokotaro Feb 27, 2021
03df1c5
feat: login 機能
hosonokotaro Feb 27, 2021
99d07c5
Merge branch 'master' into feature/add-editpage
hosonokotaro Feb 27, 2021
c16bb0b
fix: move createPost logic
hosonokotaro Feb 27, 2021
7f03666
Merge branch 'feature/add-editpage' of github.com:hosonokotaro/hosono…
hosonokotaro Feb 27, 2021
e1deeb2
fix: add regenerator-runtime
hosonokotaro Feb 27, 2021
2acd364
Squashed commit of the following:
hosonokotaro Mar 4, 2021
311daa7
fix: import resolve
hosonokotaro Mar 4, 2021
6f74717
fix: export component name
hosonokotaro Mar 4, 2021
0b84272
fix: component に型を持たせる
hosonokotaro Mar 4, 2021
4fe509a
fix: import path name を resolve 名で指定
hosonokotaro Mar 4, 2021
be0414f
fix: add jest の alias
hosonokotaro Mar 4, 2021
36195eb
feat: add CreatePost test
hosonokotaro Mar 4, 2021
65a4b7a
Squashed commit of the following:
hosonokotaro Mar 6, 2021
0fdc450
fix: dependabot ignore husky v5x
hosonokotaro Mar 6, 2021
64350cc
fix: edit page top
hosonokotaro Mar 6, 2021
b5fa765
fix: component name
hosonokotaro Mar 6, 2021
c0bc793
feat: add edit App test
hosonokotaro Mar 6, 2021
986c332
feat: EditPostList の状態排除、Style
hosonokotaro Mar 6, 2021
8733222
feat: EditPost
hosonokotaro Mar 13, 2021
7eac8a5
Squashed commit of the following:
hosonokotaro Mar 15, 2021
75a83d8
fix: edit spinner
hosonokotaro Mar 15, 2021
f6d247f
Merge branch 'master' into feature/add-editpage
hosonokotaro Mar 20, 2021
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion .babelrc
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
{
"presets": [
"@babel/preset-env",
[
"@babel/preset-env",
{
"useBuiltIns": "usage",
"corejs": 3,
"debug": true
}
],
"@babel/preset-react",
[
"@babel/preset-typescript",
Expand Down
4 changes: 4 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,7 @@ updates:
interval: 'weekly'
day: 'saturday'
timezone: 'Asia/Tokyo'
ignore:
- dependency-name: "husky"
# 5.x の新しいバージョンのみを無視する
versions: ["5.x"]
2 changes: 2 additions & 0 deletions jest.config.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
"preset": "ts-jest",
"moduleNameMapper": {
"^@App/(.*)$": "<rootDir>/src/$1",
"^~/(.+)": "<rootDir>/src/$1",
"^@/(.+)": "<rootDir>/src/components/$1",
".+\\.(css|scss)$": "identity-obj-proxy"
},
"setupFilesAfterEnv": ["@testing-library/jest-dom/extend-expect"],
Expand Down
22,016 changes: 21,975 additions & 41 deletions package-lock.json

Large diffs are not rendered by default.

6 changes: 4 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
"license": "MIT",
"devDependencies": {
"@babel/core": "^7.12.10",
"@babel/polyfill": "^7.12.1",
"@babel/preset-env": "^7.13.8",
"@babel/preset-react": "^7.12.13",
"@babel/preset-typescript": "^7.12.17",
Expand Down Expand Up @@ -89,7 +88,10 @@
"@types/mini-css-extract-plugin": "^1.2.2",
"@types/react-redux": "^7.1.16",
"axios": "^0.21.1",
"core-js": "^3.9.0",
"firebase": "^8.2.7",
"lint-staged": "^10.5.4",
"react-redux": "^7.2.2"
"react-redux": "^7.2.2",
"regenerator-runtime": "^0.13.7"
}
}
25 changes: 25 additions & 0 deletions src/adapter/firebase.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import 'firebase/auth';

import firebase from 'firebase/app';

const firebaseConfig = {
apiKey: 'AIzaSyBsC6ZAinkt3n3fB0B-Yo1UMqwqaoCzi4s',
authDomain: 'hosonokotaro-blog.firebaseapp.com',
databaseURL: 'https://hosonokotaro-blog.firebaseio.com',
projectId: 'hosonokotaro-blog',
storageBucket: 'hosonokotaro-blog.appspot.com',
messagingSenderId: '23911354523',
appId: '1:23911354523:web:56bec2eb2bf7d1b712f63e',
};

firebase.initializeApp(firebaseConfig);

// NOTE: firebase 認証機能を利用する
export const Auth = firebase.auth();

// NOTE: Google 認証を利用する
export const GoogleAuthProvider = new firebase.auth.GoogleAuthProvider();

export type User = firebase.User;

export default firebase;
42 changes: 42 additions & 0 deletions src/components/CreatePost.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import '@testing-library/jest-dom/extend-expect';

import React from 'react';

import { render, screen } from '~/testUtil';

import CreatePost from './CreatePost';

const handleSubmit = jest.fn();
const onTitleChanged = jest.fn();

it('it should render: CreatePost の input area に入れた文字が表示される', () => {
const title = 'test title';
const canSaveNewPost = true;

render(
<CreatePost
title={title}
handleSubmit={handleSubmit}
onTitleChanged={onTitleChanged}
canSaveNewPost={canSaveNewPost}
/>
);

expect(screen.getByRole('textbox').getAttribute('value')).toEqual(title);
});

it('it should render: CreatePost の input area に入れた文字が表示されない', () => {
const title = '';
const canSaveNewPost = false;

render(
<CreatePost
title={title}
handleSubmit={handleSubmit}
onTitleChanged={onTitleChanged}
canSaveNewPost={canSaveNewPost}
/>
);

expect(screen.getByRole('textbox').getAttribute('value')).toEqual(title);
});
46 changes: 46 additions & 0 deletions src/components/CreatePost.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import React from 'react';

import {
StyledButton,
StyledInputText,
StyledLabel,
StyledSection,
StyledWrapper,
} from './styledCreatePost';

export interface Props {
title: string;
handleSubmit: () => void;
onTitleChanged: (e: React.ChangeEvent<HTMLInputElement>) => void;
canSaveNewPost: boolean;
}

const CreatePost: React.FC<Props> = ({
title,
handleSubmit,
onTitleChanged,
canSaveNewPost,
}) => {
return (
<StyledSection>
<h2>記事の新規作成</h2>
<StyledWrapper>
<form>
<StyledLabel htmlFor="postTitle">タイトル</StyledLabel>
<StyledInputText
type="text"
id="postTitle"
name="postTitle"
value={title}
onChange={onTitleChanged}
/>
</form>
<StyledButton onClick={handleSubmit} disabled={!canSaveNewPost}>
記事を準備する
</StyledButton>
</StyledWrapper>
</StyledSection>
);
};

export default CreatePost;
34 changes: 34 additions & 0 deletions src/components/EditPostList.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import '@testing-library/jest-dom/extend-expect';

import React from 'react';
// NOTE: React Router をテストする場合は MemoryRouter を使用する
import { Link, MemoryRouter } from 'react-router-dom';

import { render, screen } from '~/testUtil';

import EditPostList, { Post } from './EditPostList';

const postList: Post[] = [
{
id: 'a1b2c3',
release: true,
createDate: '2021年1月10日 00:57',
routerLink: <Link to="/edit/a1b2c3">test title</Link>,
},
{
id: 'b2c3d4',
release: true,
createDate: '2021年1月11日 00:57',
routerLink: <Link to="/edit/b2c3d4">test title2</Link>,
},
];

it('should render: EditPostList に投稿記事一覧の各リンクが存在するか', () => {
render(
<MemoryRouter>
<EditPostList postList={postList} />
</MemoryRouter>
);

expect(screen.getAllByRole('link')).toHaveLength(postList.length);
});
45 changes: 45 additions & 0 deletions src/components/EditPostList.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import React from 'react';

import {
StyledPost,
StyledPosts,
StyledSection,
StyledTimestamp,
} from './styledEditPostList';

export interface Post {
id: string;
release: boolean;
createDate: string;
routerLink: React.ReactNode;
}

interface Props {
postList: Post[];
}

// TODO: どこかの処理で、release が false の状態だと弾く処理が入っているようだ
const EditPostList: React.FC<Props> = ({ postList }) => {
return (
<StyledSection>
<h2>投稿された記事一覧</h2>
<StyledPosts>
{postList.map(({ id, release, createDate, routerLink }) => (
<StyledPost key={id}>
<div>
{!release && <span>【非公開】</span>}
{routerLink}
</div>
<StyledTimestamp>
作成日時: {createDate}
<br />
id: {id}
</StyledTimestamp>
</StyledPost>
))}
</StyledPosts>
</StyledSection>
);
};

export default EditPostList;
20 changes: 20 additions & 0 deletions src/components/Login.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import React from 'react';

import { Props as EditProps } from '~/pages/edit/useLogin';

import { StyledLogin, StyledUid } from './styledLogin';

const Login: React.FC<EditProps> = ({ user, login, logout }) => {
return (
<StyledLogin>
{user ? (
<button onClick={logout}>ログアウトする</button>
) : (
<button onClick={login}>ログインする</button>
)}
{user && <StyledUid>uid: {user.uid}</StyledUid>}
</StyledLogin>
);
};

export default Login;
48 changes: 48 additions & 0 deletions src/components/styledCreatePost.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import { styled } from '@linaria/react';

export const StyledSection = styled.section`
max-width: 1000px;
margin: 0 auto;
padding: 40px 40px 0 40px;
`;

export const StyledWrapper = styled.div`
padding-top: 20px;
`;

export const StyledLabel = styled.label`
display: block;
input + & {
margin-top: 20px;
}
textarea + & {
margin-top: 20px;
}
`;

export const StyledLabelInlineBlock = styled.label`
display: inline-block;
textarea + & {
margin-top: 20px;
}
`;

export const StyledInputText = styled.input`
width: 100%;
label + & {
margin-top: 4px;
}
`;

export const StyledTextarea = styled.textarea`
width: 100%;
max-width: 100%;
min-height: 400px;
label + & {
margin-top: 4px;
}
`;

export const StyledButton = styled.button`
margin-top: 20px;
`;
26 changes: 26 additions & 0 deletions src/components/styledEditPostList.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import { styled } from '@linaria/react';

export const StyledSection = styled.section`
max-width: 1000px;
margin: 0 auto;
padding: 40px 40px 0 40px;
`;

export const StyledPosts = styled.div`
padding-top: 20px;
`;

export const StyledPost = styled.div`
& + div {
padding-top: 20px;
}
`;

export const StyledTimestamp = styled.div`
padding-top: 20px;
& + label {
margin-top: 80px;
padding-top: 80px;
border-top: 1px solid #333;
}
`;
12 changes: 12 additions & 0 deletions src/components/styledLogin.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { styled } from '@linaria/react';

export const StyledLogin = styled.div`
max-width: 1000px;
margin: 0 auto;
padding: 40px;
text-align: center;
`;

export const StyledUid = styled.div`
margin-top: 20px;
`;
4 changes: 2 additions & 2 deletions src/App.test.tsx → src/pages/App.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ import '@testing-library/jest-dom/extend-expect';
import React from 'react';
import { Provider } from 'react-redux';

import store from '../store/store';
import { render, screen } from '../testUtil';
import App from './App';
import store from './store';
import { render, screen } from './testUtil';

it('it should render: App の article に指定された className が存在する', () => {
// NOTE: App は index に記載がある通り、Provider で wrap する必要がある
Expand Down
8 changes: 4 additions & 4 deletions src/App.tsx → src/pages/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ import { Helmet } from 'react-helmet';
import { hot } from 'react-hot-loader/root';
import { BrowserRouter as Router } from 'react-router-dom';

import Footer from './components/Footer';
import Header from './components/Header';
import Pages from './pages/Pages';
import ScrollToTop from './utility/ScrollToTop';
import Footer from '../components/Footer';
import Header from '../components/Header';
import Pages from '../pages/Pages';
import ScrollToTop from '../utility/ScrollToTop';

const App: React.FC = () => {
return (
Expand Down
Loading