Skip to content

Commit

Permalink
Merge branch 'release/1.0.0' into feature/issue-1420
Browse files Browse the repository at this point in the history
  • Loading branch information
NastiaVeret authored Jun 24, 2024
2 parents a09ba42 + 78a55fb commit 9f7a3b8
Show file tree
Hide file tree
Showing 8 changed files with 48 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ const PartnersModal = () => {
})
.catch((error) => {
onCancel();
if (error === 429) {
if (error.status === 429) {
errorMessage(MESSAGE_LIMIT);
}
else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,23 +15,21 @@ import { useAsync } from '@/app/common/hooks/stateful/useAsync.hook';
import { StreetcodeCategoryContent } from '@/models/sources/sources.model';

const SourcesModal = () => {
const { sourcesStore: { srcCategoriesMap } } = useMobx();
const { sourcesStore: { srcCategoriesMap, srcCategoriesContentMap } } = useMobx();
const { modalStore } = useModalContext();
const { streetcodeStore } = useStreetcodeDataContext();
const { setModal, modalsState: { sources } } = modalStore;
const windowsize = useWindowSize();
const [content, setContent] = useState<StreetcodeCategoryContent>();
const [content, setContent] = useState<StreetcodeCategoryContent | null>(null);
const categoryId = sources.fromCardId!;
const category = srcCategoriesMap.get(categoryId);
const clickHandle = () => sources.isOpen = false;
const clickHandle = () => {
sources.isOpen = false;
setContent(null);
};

useAsync(() => {
if (streetcodeStore.getStreetCodeId && categoryId) {
sourcesApi.getCategoryContentByStreetcodeId(streetcodeStore.getStreetCodeId, categoryId)
.then((cont) => {
setContent(cont);
});
}
setContent(srcCategoriesContentMap.get(categoryId) || null);
}, [categoryId]);
return (
<Modal
Expand Down
8 changes: 7 additions & 1 deletion src/app/stores/sources-store.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import { makeAutoObservable, runInAction } from 'mobx';
import sourcesApi from '@api/sources/sources.api';
import { SourceCategory } from '@models/sources/sources.model';
import { SourceCategory, StreetcodeCategoryContent } from '@models/sources/sources.model';

export default class SourcesStore {
public srcCategoriesMap = new Map<number, SourceCategory>();
public srcCategoriesContentMap = new Map<number, StreetcodeCategoryContent>();

public constructor() {
makeAutoObservable(this);
Expand All @@ -15,6 +16,7 @@ export default class SourcesStore {

public setInternalCategoriesMap(srcCategories: SourceCategory[]) {
this.srcCategoriesMap.clear();
this.srcCategoriesContentMap.clear();
srcCategories.forEach(this.setCategoryItem);
}

Expand All @@ -25,6 +27,10 @@ export default class SourcesStore {
public fetchSrcCategoriesByStreetcodeId = async (streetcodeId: number) => {
try {
this.setInternalCategoriesMap(await sourcesApi.getCategoriesByStreetcodeId(streetcodeId));
this.srcCategoriesMap.forEach(async (value, key) => {
const content = await sourcesApi.getCategoryContentByStreetcodeId(streetcodeId,key);
this.srcCategoriesContentMap.set(key, content);
})
} catch (error: unknown) { }
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,6 @@ const CategoriesModal = ({
{
setAvailableCategories(AvailableCats);
}
alert('Категорію успішно додано до списку!');
}
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ const MainBlockAdmin = React.memo(({
]}
name="streetcodeNumber"
>
<InputNumber />
<InputNumber type='number'/>
</Form.Item>

<div className="display-flex-row p-margin">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ import { useAsync } from '@hooks/stateful/useAsync.hook';
import { ModelState } from '@models/enums/model-state';
import { ArtCreateUpdate } from '@models/media/art.model';

import { Button, Modal } from 'antd';
import { Button, Modal, Upload, Typography } from 'antd';
const { Text } = Typography;
import type { UploadFile, UploadFileStatus } from 'antd/es/upload/interface';

import FileUploader from '@/app/common/components/FileUploader/FileUploader.component';
Expand All @@ -31,6 +32,7 @@ const DownloadBlock = () => {
const [isOpen, setIsOpen] = useState(false);
const [visibleModal, setVisibleModal] = useState(false);
const [visibleDeleteButton, setVisibleDeleteButton] = useState(false);
const [visibleError, setVisibleError] = useState(false);
const artsToRemoveIdxs = useRef<Set<string>>(new Set());
const isSecondRender = useRef<boolean>(false);

Expand Down Expand Up @@ -58,6 +60,7 @@ const DownloadBlock = () => {
streetcodeArtSlideStore.hasArtWithId(id) || artGalleryTemplateStore.hasArtWithId(id));

const handleRemove = useCallback((param: UploadFile) => {
setVisibleError(false)
if (isArtInSlides(param.uid)) {
alert('Ви не можете виділити цей файл для видалення оскільки він є у існуючих слайдах');
return;
Expand All @@ -77,6 +80,7 @@ const DownloadBlock = () => {
}, []);

const onPreview = async (file: UploadFile) => {
setVisibleError(false)
const artIdx = artStore.arts.findIndex((a) => a.id.toString() === file.uid);
if (artIdx !== -1) {
setArtPreviewIdx(artIdx);
Expand All @@ -85,6 +89,7 @@ const DownloadBlock = () => {
};

const onSuccessUploadImage = action((file: Image | Audio) => {
setVisibleError(false);
let image: Image = file as Image;
const newId = artStore.getMaxArtId + 1;

Expand Down Expand Up @@ -135,17 +140,32 @@ const DownloadBlock = () => {
setVisibleDeleteButton(false);
};

const handleBeforeUpload = async (file: UploadFile) => {
const isImage = (
(file.type === 'image/jpeg') ||
(file.type === 'image/webp') ||
(file.type === 'image/png') ||
(file.type === 'image/jpg')
)
if (!isImage) {
setVisibleError(true);
}

return isImage || Upload.LIST_IGNORE;
}

return (
<div className="art-gallery-download">
<FileUploader
accept=".jpeg,.png,.jpg,.webp"
listType="picture-card"
fileList={fileList}
multiple={true}
onPreview={onPreview}
uploadTo="image"
beforeUpload={handleBeforeUpload}
onSuccessUpload={onSuccessUploadImage}
onRemove={(e) => handleRemove(e)}
onPreview={onPreview}
onRemove={handleRemove}
className="with-multiple-delete"
itemRender={(element, file) => (
<Draggable id={file.uid} className="streetcode-art-preview">
Expand All @@ -159,19 +179,22 @@ const DownloadBlock = () => {
>
<p>+ Додати</p>
</FileUploader>
{visibleError &&
<Text className="arts-error" type="danger">Тільки файли з розширенням webp, jpeg, png, jpg дозволені!</Text>
}
{visibleDeleteButton ? (
<Button
className="delete-arts-button"
danger
onClick={() => setVisibleModal(true)}
onClick={() => {setVisibleModal(true);setVisibleError(false)}}
>
Видалити
</Button>
) : <></>}
<Modal
title="Ви впевнені, що хочете видалити цей арт?"
open={visibleModal}
onOk={(e) => onRemoveArtsSubmit()}
onOk={onRemoveArtsSubmit}
onCancel={handleCancelModalRemove}
/>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,12 @@

.delete-arts-button{
width: 30%;
margin-left: auto;
margin-right: auto;
}

.art-gallery-download{
display: flex;
justify-content: flex-start;
flex-direction: column;
margin-bottom: pxToRem(10px);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ const StreetcodeSlider = () => {
const windowsize = useWindowSize();
if (windowsize.width <= 1024 && windowsize.width >= 768) STREETCODE_SLIDER_PROPS.centerMode = true;
if (windowsize.width <= 1024) STREETCODE_SLIDER_PROPS.dots = true;
if (windowsize.width <= 1024 && windowsize.width >= 768) STREETCODE_SLIDER_PROPS.initialSlide = 1;
if (windowsize.width <= 1024 && windowsize.width >= 768) STREETCODE_SLIDER_PROPS.initialSlide = 0;
if (windowsize.width <= 768) STREETCODE_SLIDER_PROPS.variableWidth = false;

streetcodeMainPageStore.fetchStreetcodesMainPage(1, DEFAULT_STREETCODE_CARDS_AMOUNT);
Expand Down

0 comments on commit 9f7a3b8

Please sign in to comment.