-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
212 deny upload (#247), refactor localisation, styles
* refactor ModalAddEditCard - answer and question values sometimes works. С ПЕРВОГО РАЗА НЕ СРАБАТЫВАЕТ! Нужно 2жды открывать модалку * refactor ModalAddEditDeck. Now toast correct and if image remained same I do not send it * refactor ModalAddEditDeck schema * refactor ModalAddEditCard schema * refactor ModalAddEditDeck with custom hook. Works perfect * refactor ModalAddEditCard with custom hook. Works. Need refactor on rtk state * add cardSlice. Less states. It works. Ready to refactor * refactor Cards update. Works fine. * refactor Cards update. Works fine. * refactor words in localisation, styles for table, fixed localisation issues * refactor table styles - cancel padding for columns, refactor learnPage.module - add word-break
- Loading branch information
1 parent
bd80806
commit 462368c
Showing
19 changed files
with
499 additions
and
248 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -34,6 +34,7 @@ section { | |
|
||
.showBtn { | ||
text-align: center; | ||
word-break: break-word; | ||
} | ||
|
||
.radio { | ||
|
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
import { useEffect, useRef, useState } from 'react' | ||
import { Control } from 'react-hook-form' | ||
|
||
import { FormValuesAddEditCard } from '@/common/zodSchemas/cards/cards.schemas' | ||
import { CardResponse } from '@/services/cards/cards.types' | ||
import { cardsActions } from '@/services/cardsSlice/cardsSlice' | ||
import { useAppDispatch } from '@/services/store' | ||
|
||
type Props = { | ||
control: Control<FormValuesAddEditCard, any> | ||
img: null | string | undefined | ||
item?: CardResponse | ||
label: string | ||
} | ||
export const useAddEditCardLogic = (props: Props) => { | ||
const { control, img, item, label } = props | ||
const initPreview = item ? img ?? null : '' | ||
const [preview, setPreview] = useState<null | string>(initPreview) | ||
const [cover, setCover] = useState<File | null | undefined>(undefined) | ||
const refInputImg = useRef<HTMLInputElement>(null) | ||
const dispatch = useAppDispatch() | ||
|
||
useEffect(() => { | ||
if (img) { | ||
setPreview(img) | ||
label === 'question' | ||
? dispatch(cardsActions.setPreviewQuestion({ previewQuestion: img })) | ||
: dispatch(cardsActions.setPreviewAnswer({ previewAnswer: img })) | ||
} | ||
}, [img]) | ||
// Генерируем ссылку на загружаемый файл и сэтаем в preview, который будем отображать, и очищаем после сэта хэш | ||
useEffect(() => { | ||
if (cover) { | ||
const newPreviewQuestion = URL.createObjectURL(cover) | ||
|
||
if (preview) { | ||
URL.revokeObjectURL(preview) | ||
} | ||
|
||
setPreview(newPreviewQuestion) | ||
label === 'question' | ||
? dispatch(cardsActions.setPreviewQuestion({ previewQuestion: newPreviewQuestion })) | ||
: dispatch(cardsActions.setPreviewAnswer({ previewAnswer: newPreviewQuestion })) | ||
|
||
return () => URL.revokeObjectURL(newPreviewQuestion) | ||
} | ||
}, [cover]) | ||
|
||
return { | ||
control, | ||
cover, | ||
preview, | ||
refInputImg, | ||
setCover, | ||
setPreview, | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
import { useEffect, useRef, useState } from 'react' | ||
import { useForm } from 'react-hook-form' | ||
|
||
import { FormValuesAddEditDeck, schemaAddEditDeck } from '@/common/zodSchemas/decks/decks.schemas' | ||
import { Deck } from '@/services/decks/deck.types' | ||
import { zodResolver } from '@hookform/resolvers/zod' | ||
|
||
type Props = { | ||
item?: Deck | ||
} | ||
export const useAddEditDeckLogic = ({ item }: Props) => { | ||
const initPreview = item ? item.cover ?? null : '' | ||
const [preview, setPreview] = useState<null | string>(initPreview) | ||
const [cover, setCover] = useState<File | null | undefined>(undefined) | ||
const refInputImg = useRef<HTMLInputElement>(null) | ||
const { control, handleSubmit } = useForm<FormValuesAddEditDeck>({ | ||
defaultValues: item | ||
? { isPrivate: item.isPrivate, name: item.name } | ||
: { isPrivate: false, name: '' }, | ||
resolver: zodResolver(schemaAddEditDeck), | ||
}) | ||
|
||
useEffect(() => { | ||
if (item?.cover) { | ||
setPreview(item?.cover) | ||
} | ||
}, [item?.cover]) | ||
useEffect(() => { | ||
if (cover) { | ||
const newPreview = URL.createObjectURL(cover) | ||
|
||
if (preview) { | ||
URL.revokeObjectURL(preview) | ||
} | ||
|
||
setPreview(newPreview) | ||
|
||
return () => URL.revokeObjectURL(newPreview) | ||
} | ||
}, [cover]) | ||
|
||
return { | ||
control, | ||
cover, | ||
handleSubmit, | ||
preview, | ||
refInputImg, | ||
setCover, | ||
setPreview, | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
import { FormValuesAddEditCard } from '@/common/zodSchemas/cards/cards.schemas' | ||
import { CardResponse } from '@/services/cards/cards.types' | ||
|
||
export const getEditCardNotifyMsg = ({ | ||
data, | ||
item, | ||
previewAnswerImg, | ||
previewQuestionImg, | ||
}: { | ||
data: FormValuesAddEditCard | ||
item?: CardResponse | ||
previewAnswerImg: null | string | ||
previewQuestionImg: null | string | ||
}) => { | ||
let message = '' | ||
|
||
const answersAndImgsCondition = | ||
data.answer === item?.answer && previewAnswerImg === item?.answerImg | ||
const questionAndImgsCondition = | ||
data.question === item?.question && previewQuestionImg === item?.questionImg | ||
|
||
if (answersAndImgsCondition || questionAndImgsCondition) { | ||
if (answersAndImgsCondition) { | ||
message += 'Answer and answer image are equal to previous. ' | ||
} | ||
if (questionAndImgsCondition) { | ||
message += 'Question and question image are equal to previous. ' | ||
} | ||
} else { | ||
if (data.answer === item?.answer) { | ||
message += 'Answer is equal to previous. ' | ||
} | ||
if (data.question === item?.question) { | ||
message += 'Question is equal to previous. ' | ||
} | ||
if (previewAnswerImg === item?.answerImg) { | ||
message += 'Answer image is equal to previous. ' | ||
} | ||
if (previewQuestionImg === item?.questionImg) { | ||
message += 'Question image is equal to previous. ' | ||
} | ||
} | ||
|
||
return `${message}It is ok, just let you know 👌` | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import { FormValuesAddEditDeck } from '@/common/zodSchemas/decks/decks.schemas' | ||
import { Deck } from '@/services/decks/deck.types' | ||
|
||
export const getEditDeckNotifyMsg = ({ | ||
data, | ||
item, | ||
preview, | ||
}: { | ||
data: FormValuesAddEditDeck | ||
item?: Deck | ||
preview: null | string | ||
}) => { | ||
let message = '' | ||
|
||
if (data.name === item?.name) { | ||
message += 'Deck name is equal to previous. ' | ||
} | ||
if (preview === item?.cover) { | ||
message = 'Image is equal to previous. ' | ||
} | ||
if (data.name === item?.name && preview === item?.cover) { | ||
message = 'Deck name and cover image are equal to previous. ' | ||
} | ||
|
||
return `${message}It is ok, just let you know 👌` | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import { z } from 'zod' | ||
|
||
export const schemaAddEditDeck = z.object({ | ||
isPrivate: z.boolean().optional(), | ||
name: z.string().min(3).max(30), | ||
}) | ||
|
||
export type FormValuesAddEditDeck = z.infer<typeof schemaAddEditDeck> |
Oops, something went wrong.