Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Styling inner workings #122

Merged
merged 6 commits into from
Jul 28, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
3 changes: 3 additions & 0 deletions public/locales/de/common.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,11 @@
"reviewModalHeading": "Wie war '{{name}}'?",
"reviewModalRatingLabel": "Bewertung",
"reviewModalImageLabel": "Bild (Optional)",
"reviewModalNoImagesSelected": "Klicke oder ziehe ein Bild hierher um es hochzuladen.",
"reviewModalImagesSelected": "{{amount}} Bilde(r) ausgewählt.",
"reviewModalCommentLabel": "Kommentar (Optional)",
"reviewModalNameLabel": "Nickname (Optional)",
"reviewModalSubmit": "Absenden",
"reviewModalSubmitError": "Es gab einen Fehler beim Absenden deiner Bewertung",
"reviewModalMissingStarValueError": "Du musst eine Sternebewertung angeben",
"reviewModalImageTooBigError": "Eins deiner Bilder ist zu groß. Bilder dürfen maximal {{size}} groß sein",
Expand Down
3 changes: 3 additions & 0 deletions public/locales/en/common.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,11 @@
"reviewModalHeading": "How was '{{name}}'?",
"reviewModalRatingLabel": "Rating",
"reviewModalImageLabel": "Picture (Optional)",
"reviewModalNoImagesSelected": "Click or drop an image to upload.",
"reviewModalImagesSelected": "{{amount}} picture(s) selected.",
"reviewModalCommentLabel": "Comment (Optional)",
"reviewModalNameLabel": "Nickname (Optional)",
"reviewModalSubmit": "Submit",
"reviewModalSubmitError": "There was an error while submitting your review",
"reviewModalMissingStarValueError": "You need to provide a star rating",
"reviewModalImageTooBigError": "One of your pictures is too big. Pictures must not be bigger than {{size}}.",
Expand Down
3 changes: 2 additions & 1 deletion src/components/navigation/profile-button/ProfileButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@ const ProfileButton = () => {
<Icon name={'logout'} />
</button>
) : (
// TODO bene mach mal login button hin
// TODO Add login button
// Also see: https://github.com/mensatt/frontend/issues/120
<></>
)
}
Expand Down
4 changes: 4 additions & 0 deletions src/components/occurrence/review-modal/form/Form.module.scss
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,10 @@
}
}

.draggedOver {
// TODO: @maanex Style the input area if a file is dragged over
}

.stars {
justify-self: center;
}
Expand Down
96 changes: 62 additions & 34 deletions src/components/occurrence/review-modal/form/Form.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@ const Form = ({ occurrenceName, occurrenceId, onSuccessfulSubmit }: Props) => {
{ loading: addReviewLoading, data: addReviewData, error: addReviewError },
] = useMutation<AddReviewMutation, AddReviewMutationVariables>(ADD_REVIEW);

const [fileInputIsDraggedOver, setFileInputIsDraggedOver] = useState(false);
const [fileAmount, setFileAmount] = useState(0);

const [showMissingStarValueError, setShowMissingStarValueError] =
useState(true);
const [showImageTooBigError, setShowImageTooBigError] = useState(false);
Expand Down Expand Up @@ -79,6 +82,7 @@ const Form = ({ occurrenceName, occurrenceId, onSuccessfulSubmit }: Props) => {
if (event.target.files) {
// `FileList` is not an array so we have to "convert" it
const fileList = Array.from(event.target.files);
setFileAmount(fileList.length);

// This function is from here: https://stackoverflow.com/a/12900504
const getFileExt = (file: File) =>
Expand Down Expand Up @@ -109,32 +113,42 @@ const Form = ({ occurrenceName, occurrenceId, onSuccessfulSubmit }: Props) => {
[formState],
);

// TODO @bene bitte useState oder so draus machen
const errors = (
<>
{addReviewError && (
<p className={styles.error}>{t('reviewModalSubmitError')}</p>
)}
{showMissingStarValueError && (
<p className={styles.error}>{t('reviewModalMissingStarValueError')}</p>
)}
{showImageTooBigError && (
<p className={styles.error}>
{t('reviewModalImageTooBigError', {
size: `${MAX_UPLOAD_FILE_SIZE / (1024 * 1024)}MB`,
})}
</p>
)}
{showWrongExtensionError && (
<p className={styles.error}>
{t('reviewModalWrongExtensionError', {
extensions: ALLOWED_EXTENSIONS.map(
(ext) => '.' + ext.toLowerCase(),
).join(' '),
})}
</p>
)}
</>
const errors = useMemo(
() => (
<>
{addReviewError && (
<p className={styles.error}>{t('reviewModalSubmitError')}</p>
)}
{showMissingStarValueError && (
<p className={styles.error}>
{t('reviewModalMissingStarValueError')}
</p>
)}
{showImageTooBigError && (
<p className={styles.error}>
{t('reviewModalImageTooBigError', {
size: `${MAX_UPLOAD_FILE_SIZE / (1024 * 1024)}MB`,
})}
</p>
)}
{showWrongExtensionError && (
<p className={styles.error}>
{t('reviewModalWrongExtensionError', {
extensions: ALLOWED_EXTENSIONS.map(
(ext) => '.' + ext.toLowerCase(),
).join(' '),
})}
</p>
)}
</>
),
[
addReviewError,
showImageTooBigError,
showMissingStarValueError,
showWrongExtensionError,
t,
],
);

return (
Expand All @@ -151,12 +165,27 @@ const Form = ({ occurrenceName, occurrenceId, onSuccessfulSubmit }: Props) => {
/>
</div>
<label>{t('reviewModalImageLabel')}</label>
<div className={styles.fileUpload}>
{/* TODO give this div element an additional class when the user is dragging a file over it */}
<input type="file" onChange={onFileInputChange} multiple />
{/* TODO put this into lang file */}
<span>Click or drop an image to upload.</span>
{/* TODO show a preview of the selected image file here, just add an <img> tag or something i can style if there is a file selected */}
<div
className={
styles.fileUpload +
(fileInputIsDraggedOver ? ' ' + styles.draggedOver : '')
}
>
<input
type="file"
onChange={onFileInputChange}
multiple
onDragEnter={() => setFileInputIsDraggedOver(true)}
onDragLeave={() => setFileInputIsDraggedOver(false)}
/>
<span>
{fileAmount
? t('reviewModalImagesSelected', { amount: fileAmount })
: t('reviewModalNoImagesSelected')}
</span>
{/* TODO Add image preview
Also see: https://github.com/mensatt/frontend/issues/121
*/}
</div>
{formState.images && <p>{t('reviewModalImageDisclaimer')}</p>}
<label htmlFor="reviewModalCommentInput">
Expand Down Expand Up @@ -191,8 +220,7 @@ const Form = ({ occurrenceName, occurrenceId, onSuccessfulSubmit }: Props) => {
className={styles.button}
disabled={addReviewLoading || formIsInvalid}
>
{/* TODO can we change the text here to something like "send review"? */}
{addReviewLoading ? t('loading') : t('rate')}
{addReviewLoading ? t('loading') : t('reviewModalSubmit')}
</button>
</form>
);
Expand Down