issue-148 Clean up files with "2" in them #149

Merged
Irev-Dev merged 1 commits from kurt/issue-148 into main 2020-12-12 09:32:01 +01:00
31 changed files with 235 additions and 261 deletions

View File

@@ -34,19 +34,19 @@ const Routes = () => {
<Router>
<Route path="/account-recovery/update-password" page={UpdatePasswordPage} name="updatePassword" />
<Route path="/account-recovery" page={AccountRecoveryPage} name="accountRecovery" />
<Route path="/" page={PartsPage} name="home" />
<Route path="/" page={HomePage} name="home" />
<Route notfound page={NotFoundPage} />
{/* Ownership enforced routes */}
<Route path="/u/{userName}/new" page={NewPart2Page} name="newPart2" />
<Route path="/u/{userName}/new" page={NewPartPage} name="newPart" />
<Private unauthenticated="home" role="user">
<Route path="/u/{userName}/edit" page={EditUser2Page} name="editUser2" />
<Route path="/u/{userName}/{partTitle}/edit" page={EditPart2Page} name="editPart2" />
<Route path="/u/{userName}/edit" page={EditUserPage} name="editUser" />
<Route path="/u/{userName}/{partTitle}/edit" page={EditPartPage} name="editPart" />
</Private>
{/* End ownership enforced routes */}
<Route path="/u/{userName}" page={User2Page} name="user2" />
<Route path="/u/{userName}/{partTitle}" page={Part2Page} name="part2" />
<Route path="/u/{userName}" page={UserPage} name="user" />
<Route path="/u/{userName}/{partTitle}" page={PartPage} name="part" />
<Route path="/u/{userName}/{partTitle}/ide" page={IdePartPage} name="ide" />
<Private unauthenticated="home" role="admin">

View File

@@ -36,7 +36,7 @@ export const Success = ({ user }) => {
const { addMessage } = useFlash()
const [updateUser, { loading, error }] = useMutation(UPDATE_USER_MUTATION, {
onCompleted: ({ updateUserByUserName }) => {
navigate(routes.user2({ userName: updateUserByUserName.userName }))
navigate(routes.user({ userName: updateUserByUserName.userName }))
addMessage('User updated.', { classes: 'rw-flash-success' })
},
})

View File

@@ -1,6 +1,6 @@
// Define your own mock data here:
export const standard = (/* vars, { ctx, req } */) => ({
editUser2: {
editUser: {
id: 42,
},
})

View File

@@ -1,5 +1,5 @@
import { Loading, Empty, Failure, Success } from './EditUser2Cell'
import { standard } from './EditUser2Cell.mock'
import { Loading, Empty, Failure, Success } from './EditUserCell'
import { standard } from './EditUserCell.mock'
export const loading = () => {
return Loading ? <Loading /> : null
@@ -17,4 +17,4 @@ export const success = () => {
return Success ? <Success {...standard()} /> : null
}
export default { title: 'Cells/EditUser2Cell' }
export default { title: 'Cells/EditUserCell' }

View File

@@ -1,8 +1,8 @@
import { render, screen } from '@redwoodjs/testing'
import { Loading, Empty, Failure, Success } from './EditUser2Cell'
import { standard } from './EditUser2Cell.mock'
import { Loading, Empty, Failure, Success } from './EditUserCell'
import { standard } from './EditUserCell.mock'
describe('EditUser2Cell', () => {
describe('EditUserCell', () => {
test('Loading renders successfully', () => {
render(<Loading />)
// Use screen.debug() to see output
@@ -20,7 +20,7 @@ describe('EditUser2Cell', () => {
})
test('Success renders successfully', async () => {
render(<Success editUser2={standard().editUser2} />)
render(<Success editUser={standard().editUser} />)
expect(screen.getByText(/42/i)).toBeInTheDocument()
})
})

View File

@@ -48,7 +48,7 @@ const IdeToolbar = ({ canEdit, isChanges, onSave, onExport, userNamePart }) => {
/>
</div>
<div className="text-indigo-400 ml-2 mr-8">
<Link to={routes.user2({ userName: userNamePart?.userName })}>
<Link to={routes.user({ userName: userNamePart?.userName })}>
{userNamePart?.userName}
</Link>
</div>
@@ -58,7 +58,7 @@ const IdeToolbar = ({ canEdit, isChanges, onSave, onExport, userNamePart }) => {
className="ml-3 shadow-md hover:shadow-lg border-indigo-600 border-2 border-opacity-0 hover:border-opacity-100 bg-indigo-800 text-indigo-200"
shouldAnimateHover
onClick={() => {
navigate(routes.part2(userNamePart))
navigate(routes.part(userNamePart))
}}
>
Part Profile

View File

@@ -1,166 +0,0 @@
import { useMutation, useFlash } from '@redwoodjs/web'
import { navigate, routes } from '@redwoodjs/router'
import { useAuth } from '@redwoodjs/auth'
import PartProfile from 'src/components/PartProfile'
export const QUERY = gql`
query FIND_PART_BY_USERNAME_TITLE(
$userName: String!
$partTitle: String
$currentUserId: String
) {
userPart: userName(userName: $userName) {
id
name
userName
bio
image
Part(partTitle: $partTitle) {
id
title
description
code
mainImage
createdAt
updatedAt
userId
Reaction {
emote
}
userReactions: Reaction(userId: $currentUserId) {
emote
}
Comment {
id
text
user {
userName
image
}
}
}
}
}
`
const UPDATE_PART_MUTATION = gql`
mutation UpdatePartMutation($id: String!, $input: UpdatePartInput!) {
updatePart: updatePart(id: $id, input: $input) {
id
title
user {
id
userName
}
}
}
`
const CREATE_PART_MUTATION = gql`
mutation CreatePartMutation($input: CreatePartInput!) {
createPart(input: $input) {
id
title
user {
id
userName
}
}
}
`
const TOGGLE_REACTION_MUTATION = gql`
mutation ToggleReactionMutation($input: TogglePartReactionInput!) {
togglePartReaction(input: $input) {
id
emote
}
}
`
const CREATE_COMMENT_MUTATION = gql`
mutation CreateCommentMutation($input: CreateCommentInput!) {
createComment(input: $input) {
id
text
}
}
`
export const Loading = () => <div>Loading...</div>
export const Empty = () => <div>Empty</div>
export const Failure = ({ error }) => <div>Error: {error.message}</div>
export const Success = ({ userPart, variables: { isEditable }, refetch }) => {
const { currentUser } = useAuth()
const { addMessage } = useFlash()
const [updateUser, { loading, error }] = useMutation(UPDATE_PART_MUTATION, {
onCompleted: ({ updatePart }) => {
navigate(
routes.part2({
userName: updatePart.user.userName,
partTitle: updatePart.title,
})
)
addMessage('Part updated.', { classes: 'rw-flash-success' })
},
})
const [createUser] = useMutation(CREATE_PART_MUTATION, {
onCompleted: ({ createPart }) => {
navigate(
routes.part2({
userName: createPart?.user?.userName,
partTitle: createPart?.title,
})
)
addMessage('Part Created.', { classes: 'rw-flash-success' })
},
})
const onSave = (id, input) => {
if (!id) {
createUser({ variables: { input } })
return
}
updateUser({ variables: { id, input } })
}
const [toggleReaction] = useMutation(TOGGLE_REACTION_MUTATION, {
onCompleted: () => refetch(),
})
const onReaction = (emote) =>
toggleReaction({
variables: {
input: {
emote,
userId: currentUser.sub,
partId: userPart?.Part?.id,
},
},
})
const [createComment] = useMutation(CREATE_COMMENT_MUTATION, {
onCompleted: () => refetch(),
})
const onComment = (text) =>
createComment({
variables: {
input: {
text,
userId: currentUser.sub,
partId: userPart?.Part?.id,
},
},
})
return (
<PartProfile
userPart={userPart}
onSave={onSave}
loading={loading}
error={error}
isEditable={isEditable}
onReaction={onReaction}
onComment={onComment}
/>
)
}

View File

@@ -1,24 +1,166 @@
import Part from 'src/components/Part'
import { useMutation, useFlash } from '@redwoodjs/web'
import { navigate, routes } from '@redwoodjs/router'
import { useAuth } from '@redwoodjs/auth'
import PartProfile from 'src/components/PartProfile'
export const QUERY = gql`
query FIND_PART_BY_ID($id: String!) {
part: part(id: $id) {
query FIND_PART_BY_USERNAME_TITLE(
$userName: String!
$partTitle: String
$currentUserId: String
) {
userPart: userName(userName: $userName) {
id
name
userName
bio
image
Part(partTitle: $partTitle) {
id
title
description
code
mainImage
createdAt
updatedAt
userId
Reaction {
emote
}
userReactions: Reaction(userId: $currentUserId) {
emote
}
Comment {
id
text
user {
userName
image
}
}
}
}
}
`
const UPDATE_PART_MUTATION = gql`
mutation UpdatePartMutation($id: String!, $input: UpdatePartInput!) {
updatePart: updatePart(id: $id, input: $input) {
id
title
description
code
mainImage
createdAt
updatedAt
userId
user {
id
userName
}
}
}
`
const CREATE_PART_MUTATION = gql`
mutation CreatePartMutation($input: CreatePartInput!) {
createPart(input: $input) {
id
title
user {
id
userName
}
}
}
`
const TOGGLE_REACTION_MUTATION = gql`
mutation ToggleReactionMutation($input: TogglePartReactionInput!) {
togglePartReaction(input: $input) {
id
emote
}
}
`
const CREATE_COMMENT_MUTATION = gql`
mutation CreateCommentMutation($input: CreateCommentInput!) {
createComment(input: $input) {
id
text
}
}
`
export const Loading = () => <div>Loading...</div>
export const Empty = () => <div>Part not found</div>
export const Empty = () => <div>Empty</div>
export const Success = ({ part }) => {
return <Part part={part} />
export const Failure = ({ error }) => <div>Error: {error.message}</div>
export const Success = ({ userPart, variables: { isEditable }, refetch }) => {
const { currentUser } = useAuth()
const { addMessage } = useFlash()
const [updateUser, { loading, error }] = useMutation(UPDATE_PART_MUTATION, {
onCompleted: ({ updatePart }) => {
navigate(
routes.part({
userName: updatePart.user.userName,
partTitle: updatePart.title,
})
)
addMessage('Part updated.', { classes: 'rw-flash-success' })
},
})
const [createUser] = useMutation(CREATE_PART_MUTATION, {
onCompleted: ({ createPart }) => {
navigate(
routes.part({
userName: createPart?.user?.userName,
partTitle: createPart?.title,
})
)
addMessage('Part Created.', { classes: 'rw-flash-success' })
},
})
const onSave = (id, input) => {
if (!id) {
createUser({ variables: { input } })
return
}
updateUser({ variables: { id, input } })
}
const [toggleReaction] = useMutation(TOGGLE_REACTION_MUTATION, {
onCompleted: () => refetch(),
})
const onReaction = (emote) =>
toggleReaction({
variables: {
input: {
emote,
userId: currentUser.sub,
partId: userPart?.Part?.id,
},
},
})
const [createComment] = useMutation(CREATE_COMMENT_MUTATION, {
onCompleted: () => refetch(),
})
const onComment = (text) =>
createComment({
variables: {
input: {
text,
userId: currentUser.sub,
partId: userPart?.Part?.id,
},
},
})
return (
<PartProfile
userPart={userPart}
onSave={onSave}
loading={loading}
error={error}
isEditable={isEditable}
onReaction={onReaction}
onComment={onComment}
/>
)
}

View File

@@ -1,6 +1,6 @@
// Define your own mock data here:
export const standard = (/* vars, { ctx, req } */) => ({
part2: {
part: {
id: 42,
},
})

View File

@@ -1,5 +1,5 @@
import { Loading, Empty, Failure, Success } from './Part2Cell'
import { standard } from './Part2Cell.mock'
import { Loading, Empty, Failure, Success } from './PartCell'
import { standard } from './PartCell.mock'
export const loading = () => {
return Loading ? <Loading /> : null
@@ -17,4 +17,4 @@ export const success = () => {
return Success ? <Success {...standard()} /> : null
}
export default { title: 'Cells/Part2Cell' }
export default { title: 'Cells/PartCell' }

View File

@@ -1,8 +1,8 @@
import { render, screen } from '@redwoodjs/testing'
import { Loading, Empty, Failure, Success } from './Part2Cell'
import { standard } from './Part2Cell.mock'
import { Loading, Empty, Failure, Success } from './PartCell'
import { standard } from './PartCell.mock'
describe('Part2Cell', () => {
describe('PartCell', () => {
test('Loading renders successfully', () => {
render(<Loading />)
// Use screen.debug() to see output
@@ -20,7 +20,7 @@ describe('Part2Cell', () => {
})
test('Success renders successfully', async () => {
render(<Success part2={standard().part2} />)
render(<Success part={standard().part} />)
expect(screen.getByText(/42/i)).toBeInTheDocument()
})
})

View File

@@ -28,7 +28,7 @@ const PartProfile = ({
isEditable &&
!canEdit &&
navigate(
routes.part2({ userName: userPart.userName, partTitle: part?.title })
routes.part({ userName: userPart.userName, partTitle: part?.title })
)
}, [currentUser])
const [input, setInput] = useState({
@@ -54,7 +54,7 @@ const PartProfile = ({
return
}
navigate(
routes.editPart2({ userName: userPart?.userName, partTitle: part?.title })
routes.editPart({ userName: userPart?.userName, partTitle: part?.title })
)
}
return (
@@ -73,7 +73,7 @@ const PartProfile = ({
width={300}
/>
<h4 className="text-indigo-800 text-xl underline text-right py-4">
<Link to={routes.user2({ userName: userPart?.userName })}>
<Link to={routes.user({ userName: userPart?.userName })}>
{userPart?.name}
</Link>
</h4>
@@ -177,7 +177,7 @@ const PartProfile = ({
</div>
<div className="ml-4 font-roboto">
<div className="text-gray-800 font-bold text-lg mb-1">
<Link to={routes.user2({ userName: user?.userName })}>
<Link to={routes.user({ userName: user?.userName })}>
{user?.userName}
</Link>
</div>

View File

@@ -16,7 +16,7 @@ const PartsList = ({ parts }) => {
key={`${user?.userName}--${title}`}
>
<Link
to={routes.part2({ userName: user?.userName, partTitle: title })}
to={routes.part({ userName: user?.userName, partTitle: title })}
>
<div className="flex items-center p-2 bg-gray-200 border-gray-300 rounded-t-lg border-t border-l border-r">
<div className="w-8 h-8 overflow-hidden rounded-full border border-indigo-300 shadow">

View File

@@ -11,9 +11,7 @@ const UserProfile = ({ user, isEditable, loading, onSave, error }) => {
const { currentUser } = useAuth()
const canEdit = currentUser?.sub === user.id
useEffect(() => {
isEditable &&
!canEdit &&
navigate(routes.user2({ userName: user.userName }))
isEditable && !canEdit && navigate(routes.user({ userName: user.userName }))
}, [currentUser])
const [input, setInput] = useState({
userName: user.userName,
@@ -67,7 +65,7 @@ const UserProfile = ({ user, isEditable, loading, onSave, error }) => {
className="bg-indigo-200"
iconName="pencil"
onClick={() =>
navigate(routes.editUser2({ userName: user.userName }))
navigate(routes.editUser({ userName: user.userName }))
}
>
Edit Profile

View File

@@ -157,7 +157,7 @@ const MainLayout = ({ children }) => {
{isAuthenticated && data?.user?.userName ? (
<Link
className="h-full w-full"
to={routes.newPart2({ userName: data?.user?.userName })}
to={routes.newPart({ userName: data?.user?.userName })}
>
<Svg name="plus" className="text-indigo-300 w-full h-full" />
</Link>
@@ -210,14 +210,14 @@ const MainLayout = ({ children }) => {
}}
>
<div className="p-4 w-40">
<Link to={routes.user2({ userName: data?.user?.userName })}>
<Link to={routes.user({ userName: data?.user?.userName })}>
<h3 className="text-indigo-800" style={{ fontWeight: '500' }}>
Hello {data?.user?.name}
</h3>
</Link>
<hr />
<br />
<Link to={routes.editUser2({ userName: data?.user?.userName })}>
<Link to={routes.editUser({ userName: data?.user?.userName })}>
<div className="text-indigo-800">Edit Profile</div>
</Link>
<a href="#" className="text-indigo-800" onClick={logOut}>

View File

@@ -1,7 +0,0 @@
import EditPart2Page from './EditPart2Page'
export const generated = () => {
return <EditPart2Page />
}
export default { title: 'Pages/EditPart2Page' }

View File

@@ -1,16 +1,16 @@
import { useAuth } from '@redwoodjs/auth'
import MainLayout from 'src/layouts/MainLayout'
import Part2Cell from 'src/components/Part2Cell'
import PartCell from 'src/components/PartCell'
import Seo from 'src/components/Seo/Seo'
const EditPart2Page = ({ userName, partTitle }) => {
const EditPartPage = ({ userName, partTitle }) => {
const { currentUser } = useAuth()
return (
<MainLayout>
<Seo title={partTitle} description="Edit part page" lang="en-US" />
<Part2Cell
<PartCell
userName={userName}
partTitle={partTitle}
currentUserId={currentUser?.sub}
@@ -20,4 +20,4 @@ const EditPart2Page = ({ userName, partTitle }) => {
)
}
export default EditPart2Page
export default EditPartPage

View File

@@ -0,0 +1,7 @@
import EditPartPage from './EditPartPage'
export const generated = () => {
return <EditPartPage />
}
export default { title: 'Pages/EditPartPage' }

View File

@@ -1,11 +1,11 @@
import { render } from '@redwoodjs/testing'
import NewPart2Page from './NewPart2Page'
import EditPartPage from './EditPartPage'
describe('NewPart2Page', () => {
describe('EditPartPage', () => {
it('renders successfully', () => {
expect(() => {
render(<NewPart2Page />)
render(<EditPartPage />)
}).not.toThrow()
})
})

View File

@@ -1,5 +1,5 @@
import MainLayout from 'src/layouts/MainLayout'
import EditUser2Cell from 'src/components/EditUser2Cell'
import EditUserCell from 'src/components/EditUserCell'
import Seo from 'src/components/Seo/Seo'
const UserPage = ({ userName }) => {
@@ -7,7 +7,7 @@ const UserPage = ({ userName }) => {
<MainLayout>
<Seo title={userName} description="Add new part page" lang="en-US" />
<EditUser2Cell userName={userName} />
<EditUserCell userName={userName} />
</MainLayout>
)
}

View File

@@ -1,7 +0,0 @@
import NewPart2Page from './NewPart2Page'
export const generated = () => {
return <NewPart2Page />
}
export default { title: 'Pages/NewPart2Page' }

View File

@@ -3,10 +3,10 @@ import { useAuth } from '@redwoodjs/auth'
import { navigate, routes } from '@redwoodjs/router'
import MainLayout from 'src/layouts/MainLayout'
import Part2Cell from 'src/components/Part2Cell'
import PartCell from 'src/components/PartCell'
import Seo from 'src/components/Seo/Seo'
const NewPart2Page = ({ userName }) => {
const NewPartPage = ({ userName }) => {
const { isAuthenticated, currentUser } = useAuth()
useEffect(() => {
!isAuthenticated && navigate(routes.home())
@@ -15,7 +15,7 @@ const NewPart2Page = ({ userName }) => {
<MainLayout>
<Seo title="New part" description="Add new part page" lang="en-US" />
<Part2Cell
<PartCell
userName={userName}
currentUserId={currentUser?.sub}
isEditable
@@ -24,4 +24,4 @@ const NewPart2Page = ({ userName }) => {
)
}
export default NewPart2Page
export default NewPartPage

View File

@@ -0,0 +1,7 @@
import NewPartPage from './NewPartPage'
export const generated = () => {
return <NewPartPage />
}
export default { title: 'Pages/NewPartPage' }

View File

@@ -1,11 +1,11 @@
import { render } from '@redwoodjs/testing'
import EditPart2Page from './EditPart2Page'
import NewPartPage from './NewPartPage'
describe('EditPart2Page', () => {
describe('NewPartPage', () => {
it('renders successfully', () => {
expect(() => {
render(<EditPart2Page />)
render(<NewPartPage />)
}).not.toThrow()
})
})

View File

@@ -1,7 +0,0 @@
import Part2Page from './Part2Page'
export const generated = () => {
return <Part2Page />
}
export default { title: 'Pages/Part2Page' }

View File

@@ -1,16 +1,16 @@
import { useAuth } from '@redwoodjs/auth'
import MainLayout from 'src/layouts/MainLayout'
import Part2Cell from 'src/components/Part2Cell'
import PartCell from 'src/components/PartCell'
import Seo from 'src/components/Seo/Seo'
const Part2Page = ({ userName, partTitle }) => {
const PartPage = ({ userName, partTitle }) => {
const { currentUser } = useAuth()
return (
<MainLayout>
<Seo title={partTitle} description={partTitle} lang="en-US" />
<Part2Cell
<PartCell
userName={userName}
partTitle={partTitle}
currentUserId={currentUser?.sub}
@@ -19,4 +19,4 @@ const Part2Page = ({ userName, partTitle }) => {
)
}
export default Part2Page
export default PartPage

View File

@@ -0,0 +1,7 @@
import PartPage from './PartPage'
export const generated = () => {
return <PartPage />
}
export default { title: 'Pages/PartPage' }

View File

@@ -1,11 +1,11 @@
import { render } from '@redwoodjs/testing'
import Part2Page from './Part2Page'
import PartPage from './PartPage'
describe('Part2Page', () => {
describe('PartPage', () => {
it('renders successfully', () => {
expect(() => {
render(<Part2Page />)
render(<PartPage />)
}).not.toThrow()
})
})

View File

@@ -1,5 +1,5 @@
import MainLayout from 'src/layouts/MainLayout'
import User2Cell from 'src/components/User2Cell'
import UserCell from 'src/components/UserCell'
import Seo from 'src/components/Seo/Seo'
const UserPage = ({ userName }) => {
@@ -7,7 +7,7 @@ const UserPage = ({ userName }) => {
<MainLayout>
<Seo title={userName} description="User page" lang="en-US" />
<User2Cell userName={userName} />
<UserCell userName={userName} />
</MainLayout>
)
}