Skip to content
This repository was archived by the owner on Feb 2, 2023. It is now read-only.

Commit 98b22f9

Browse files
committed
Add basic solution creation process
1 parent 014bf1b commit 98b22f9

File tree

12 files changed

+311
-13
lines changed

12 files changed

+311
-13
lines changed

client/src/App.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -150,11 +150,11 @@ class App extends Component<AppProps, {}> {
150150
component={NotImplmented}
151151
/>
152152
<Route exact path="/" component={Pages.Home} />
153-
<Route path="/task/:id" component={Pages.Task} />
154153
<Route
155154
path="/task/:id/add-solution"
156155
component={Pages.AddSolution}
157156
/>
157+
<Route path="/task/:id" component={Pages.Task} />
158158
<Route path="*" render={redirectToHome} />
159159
</Switch>
160160
</div>

client/src/generic/Photos.tsx

+3-1
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ const Photos: FunctionComponent<PhotosProps> = ({
1919
filesLength,
2020
fullWidth,
2121
onFilesUpdate,
22+
photosPlaceholderText = 'Dodaj zdjęcia zadania',
2223
}) => {
2324
const [previewPhotoId, updatePreviewPhotoId] = useState('')
2425

@@ -57,7 +58,7 @@ const Photos: FunctionComponent<PhotosProps> = ({
5758
>
5859
{fullWidth && (
5960
<p className={classes.browsePhotoParagraph}>
60-
Dodaj zdjęcia zadania
61+
{photosPlaceholderText}
6162
</p>
6263
)}
6364
<AddPhotoIcon className={classes.photoIcon} />
@@ -209,6 +210,7 @@ interface PhotosProps extends WithStyles<typeof styles> {
209210
filesLength: number
210211
fullWidth?: boolean
211212
onFilesUpdate: (files: ExtendedFile[]) => void
213+
photosPlaceholderText?: string
212214
}
213215

214216
export interface ExtendedFile extends File {

client/src/generic/Stepper/Step.tsx

+3-1
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ const Step: FunctionComponent<StepProps> = props => {
1919
goToNextStep,
2020
submit,
2121
isValid,
22+
submitButtonName,
2223
} = props
2324

2425
if (isActive === false) return null
@@ -61,7 +62,7 @@ const Step: FunctionComponent<StepProps> = props => {
6162
onClick={submit}
6263
disabled={!isValid}
6364
>
64-
Utwórz
65+
{submitButtonName}
6566
</Button>
6667
)}
6768
</div>
@@ -119,6 +120,7 @@ interface StepProps extends WithStyles<typeof styles> {
119120
goToPreviousStep?: () => void
120121
goToNextStep?: () => void
121122
submit?: () => void
123+
submitButtonName?: string
122124
}
123125

124126
export interface StepItem {

client/src/generic/Stepper/StepList.tsx

+3
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ const StepList: FC<StepListProps> = ({
88
onSubmitClick,
99
classes,
1010
children,
11+
submitButtonName,
1112
}) => {
1213
const goToPreviousStep = () => {
1314
updateStep(step - 1)
@@ -31,6 +32,7 @@ const StepList: FC<StepListProps> = ({
3132
goToPreviousStep,
3233
goToNextStep,
3334
submit: onSubmitClick,
35+
submitButtonName,
3436
})
3537
})
3638

@@ -94,6 +96,7 @@ interface StepListProps extends WithStyles<typeof styles> {
9496
onSubmitClick: () => void
9597
updateStep: (step: number) => void
9698
step: number
99+
submitButtonName: string
97100
}
98101

99102
export default withStyles(styles)(StepList)

client/src/generic/Stepper/index.ts

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
import Step from './Step'
2+
import StepList from './StepList'
3+
4+
export { Step, StepList }

client/src/generic/Task/components/TaskForGuest.tsx

+8-4
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,20 @@ import {
55
} from '@material-ui/icons'
66
import { WithStyles } from '@material-ui/styles'
77
import React, { useState } from 'react'
8+
import { RouteComponentProps, withRouter } from 'react-router'
89
import Button from '~generic/Buttons/Button'
910
import ButtonContainer from '~generic/Buttons/ButtonsContainer'
1011
import InfoDialog from '~generic/InfoDialog'
1112
import { Task as TaskData } from '~interfaces'
1213
import { getTaskStatus, TaskStatus } from '../utils'
1314
import TaskBase from './TaskBase'
1415

15-
const Task = ({ task, classes }: TaskProps) => {
16+
const Task = ({ task, classes, history }: TaskProps) => {
1617
const [isModalOpened, setModalOpened] = useState(false)
17-
const handleModalClose = () => setModalOpened(false)
18+
const handleModalClose = () => {
19+
history.push('/task/' + task.id + '/add-solution')
20+
setModalOpened(false)
21+
}
1822
const handleOpenClick = () => setModalOpened(true)
1923

2024
const title = 'Dodaj rozwiązania!'
@@ -63,8 +67,8 @@ const styles: StyleRulesCallback = _ => ({
6367
},
6468
})
6569

66-
interface TaskProps extends WithStyles<typeof styles> {
70+
interface TaskProps extends WithStyles<typeof styles>, RouteComponentProps<{}> {
6771
task: TaskData
6872
}
6973

70-
export default withStyles(styles)(Task)
74+
export default withStyles(styles)(withRouter(Task))
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
import {
2+
CardContent,
3+
StyleRulesCallback,
4+
TextField,
5+
Typography,
6+
WithStyles,
7+
withStyles,
8+
} from '@material-ui/core'
9+
import React, { FunctionComponent } from 'react'
10+
import LineSeparator from '~generic/LineSeparator'
11+
12+
const SolutionDescriptionEdit: FunctionComponent<TaskDescriptionEditProps> = ({
13+
classes,
14+
description,
15+
onDescriptionUpdate,
16+
}) => {
17+
return (
18+
<CardContent className={classes.cardContent}>
19+
<Typography variant="h3" component="h3">
20+
Opis
21+
<LineSeparator />
22+
</Typography>
23+
24+
<form className={classes.form} noValidate autoComplete="off">
25+
<TextField
26+
fullWidth
27+
id="multiline-static"
28+
margin="normal"
29+
label="Wskazówki do treści rozwiązania"
30+
multiline
31+
value={description}
32+
onChange={onDescriptionUpdate}
33+
/>
34+
</form>
35+
</CardContent>
36+
)
37+
}
38+
39+
const styles: StyleRulesCallback = theme => ({
40+
title: {
41+
textAlign: 'center',
42+
color: theme.palette.secondary.main,
43+
},
44+
cardContent: {
45+
height: '100%',
46+
display: 'grid',
47+
gridTemplateRows: 'max-content minmax(200px, 50vh)',
48+
},
49+
form: {
50+
padding: '2rem',
51+
overflowY: 'auto',
52+
overflowX: 'hidden',
53+
overflowScrolling: 'touch',
54+
},
55+
})
56+
57+
interface TaskDescriptionEditProps extends WithStyles<typeof styles> {
58+
description: string
59+
onDescriptionUpdate: (e: any) => void
60+
}
61+
62+
export default withStyles(styles)(SolutionDescriptionEdit)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,138 @@
1+
import {
2+
CardContent,
3+
StyleRulesCallback,
4+
Theme,
5+
Typography,
6+
WithStyles,
7+
withStyles,
8+
} from '@material-ui/core'
9+
import React, { FunctionComponent } from 'react'
10+
import Photos from '~generic/Photos'
11+
import { OnClick } from '~typings/react'
12+
13+
const TaskPhotoEdit: FunctionComponent<TaskPhotoEditProps> = ({
14+
classes,
15+
files,
16+
onFilesUpdate,
17+
}) => {
18+
return (
19+
<CardContent className={classes.cardContent}>
20+
<Typography variant="h3" component="h3">
21+
Zdjęcia
22+
<hr className={classes.underline} />
23+
</Typography>
24+
<div
25+
className={
26+
!files.length ? classes.contentWithAddPhotoLater : classes.content
27+
}
28+
>
29+
<div className={classes.photosWrapper}>
30+
<Photos
31+
photosPlaceholderText="Dodaj zdjęcie rozwiązania"
32+
filesLength={1}
33+
fullWidth
34+
{...{ files, onFilesUpdate }}
35+
/>
36+
</div>
37+
</div>
38+
</CardContent>
39+
)
40+
}
41+
42+
const styles: StyleRulesCallback = (theme: Theme) => ({
43+
cardContent: {
44+
height: '100%',
45+
paddingBottom: '0 !important',
46+
display: 'grid',
47+
gridTemplateRows: 'max-content',
48+
},
49+
contentWithAddPhotoLater: {
50+
height: '100%',
51+
display: 'grid',
52+
gridTemplateRows: '6fr 5fr',
53+
},
54+
content: {
55+
display: 'grid',
56+
gridTemplateRows: '1fr',
57+
},
58+
closeIcon: {
59+
position: 'absolute',
60+
right: '8px',
61+
color: theme.palette.secondary.main,
62+
backgroundColor: 'white',
63+
borderRadius: '100%',
64+
zIndex: 1,
65+
marginTop: '-9px',
66+
cursor: 'pointer',
67+
},
68+
paper: {
69+
maxHeight: '100%',
70+
margin: '0.5rem 0 0.5rem',
71+
cursor: 'pointer',
72+
},
73+
photosWrapper: {
74+
display: 'grid',
75+
gridGap: '1rem',
76+
marginTop: '2rem',
77+
},
78+
photoPaper: {
79+
display: 'grid',
80+
gridTemplateColumns: '2fr 1fr',
81+
margin: '0.5rem 0 0.5rem',
82+
},
83+
photoIcon: {
84+
fontSize: '6rem',
85+
},
86+
photoNameContainer: {
87+
display: 'flex',
88+
margin: '0 5px 0 5px',
89+
alignItems: 'center',
90+
},
91+
photoName: {
92+
width: '100%',
93+
wordBreak: 'break-all',
94+
},
95+
browsePhotoContainer: {
96+
height: '100%',
97+
justifyContent: 'center',
98+
alignItems: 'center',
99+
display: 'flex',
100+
cursor: 'pointer',
101+
},
102+
browsePhotoTitle: {
103+
display: 'flex',
104+
flexDirection: 'column',
105+
alignItems: 'center',
106+
},
107+
browsePhotoParagraph: {
108+
margin: '0 0 2rem',
109+
},
110+
fileInput: {
111+
display: 'none',
112+
},
113+
filePicture: {
114+
backgroundColor: 'black',
115+
borderRadius: '5px',
116+
backgroundSize: 'contain',
117+
backgroundRepeat: 'no-repeat',
118+
backgroundPosition: 'center',
119+
},
120+
underline: {
121+
height: '1px',
122+
border: 'none',
123+
backgroundColor: theme.palette.grey[300],
124+
},
125+
})
126+
127+
interface TaskPhotoEditProps extends WithStyles<typeof styles> {
128+
files: ExtendedFile[]
129+
onFilesUpdate: (files: ExtendedFile[]) => void
130+
onFilesLater: OnClick
131+
}
132+
133+
export interface ExtendedFile extends File {
134+
id: string
135+
url: string
136+
}
137+
138+
export default withStyles(styles)(TaskPhotoEdit)

0 commit comments

Comments
 (0)