Skip to content

Commit

Permalink
refactor: refactoring the code according to yuliaHope requirements
Browse files Browse the repository at this point in the history
  • Loading branch information
keksik77 authored and Yuliya Haluza committed Apr 4, 2021
1 parent e282508 commit 46d337d
Show file tree
Hide file tree
Showing 12 changed files with 124 additions and 160 deletions.
63 changes: 60 additions & 3 deletions client/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

19 changes: 0 additions & 19 deletions client/src/components/Schedule/CalendarView.tsx

This file was deleted.

9 changes: 4 additions & 5 deletions client/src/components/Schedule/CalendarView/Calendar.tsx
Original file line number Diff line number Diff line change
@@ -1,21 +1,20 @@
import React from 'react';
import MobileCalendar from './components/MobileCalendar';
import useWindowDimensions from './utils/useWindowDimensions';
import DesktopCalendar from './components/DesktopCalendar';
import { CourseEvent } from 'services/course';
import { isMobile } from 'mobile-device-detect';

type Props = {
data: CourseEvent[];
timeZone: string;
};

export const CalendarView: React.FC<Props> = ({data, timeZone}) => {
const { width } = useWindowDimensions();

return <>
{width > 750
? <DesktopCalendar data={data} timeZone={timeZone}/>
: <MobileCalendar data={data} timeZone={timeZone}/>
{isMobile
? <MobileCalendar data={data} timeZone={timeZone}/>
: <DesktopCalendar data={data} timeZone={timeZone}/>
}
</>
};
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import React, { useState } from 'react';
import { Calendar, Badge } from 'antd';
import { getMonthValue } from '../utils/DateFuncs';
import { getListData } from '../utils/DataFuncs';
import { getMonthValue, getListData } from '../utils/filters';
import { Scrollbars } from 'react-custom-scrollbars';
import { ModalWindow } from './Modal';
import { CourseEvent } from 'services/course';
Expand Down Expand Up @@ -58,12 +57,12 @@ const DesktopCalendar: React.FC<Props> = ({ data, timeZone }) => {
const monthCellRender = (date: unknown | Moment) => {
const num = getMonthValue(date as unknown as Moment, data, timeZone);

return num ? (
return !!num && (
<div >
<span>Number of events</span>
<section>{num}</section>
</div>
) : null;
);
}


Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,23 @@
import React, { useState} from 'react';
import { Calendar, Badge, List } from 'antd';
import { getMonthValue } from '../utils/DateFuncs';
import { getMonthValue, getListData } from '../utils/filters';
import {ModalWindow} from './Modal';
import { getListData } from '../utils/DataFuncs';
import { CourseEvent } from 'services/course';
import { Moment } from 'moment';
import {dateWithTimeZoneRenderer} from 'components/Table';
import css from 'styled-jsx/css';

const numberEventsStyle = css`section {
position: absolute;
bottom: 12px;
background: #FB6216;
right: -13px;
border-radius: 100%;
width: 20px;
height: 20px;
line-height: 19px;
color: white;
}`

type Props = {
data: CourseEvent[];
Expand Down Expand Up @@ -42,48 +54,26 @@ const MobileCalendar: React.FC<Props> = ({ data, timeZone }) => {

function dateCellRender(date: unknown | Moment) {
const numberEvents = getListData(date as unknown as Moment, data, timeZone).length;
return numberEvents > 0 ? (
return !!(numberEvents > 0) && (
<>
<section>{numberEvents}</section>
<style jsx>
{`section {
position: absolute;
bottom: 12px;
background: #FB6216;
right: -13px;
border-radius: 100%;
width: 20px;
height: 20px;
line-height: 20px;
color: white;
}`}
{numberEventsStyle}
</style>
</>
) : null;
);
}

const monthCellRender = (date: unknown | Moment) => {
const num = getMonthValue(date as unknown as Moment, data, timeZone);
return num ? (
const numberEvents = getMonthValue(date as unknown as Moment, data, timeZone);
return !!numberEvents && (
<>
<section>{num}</section>
<section>{numberEvents}</section>
<style jsx>
{`
section {
position: absolute;
bottom: 12px;
background: #FB6216;
right: -13px;
border-radius: 100%;
width: 20px;
height: 20px;
line-height: 20px;
color: white;
}
`}
</style>
{numberEventsStyle}
</style>
</>
) : null;
);
}

return (
Expand All @@ -106,7 +96,7 @@ const MobileCalendar: React.FC<Props> = ({ data, timeZone }) => {
<List.Item.Meta
title={<Badge style={{paddingLeft: 8, paddingRight: 10}} color={item.color} text={item.name} />}
/>
<div><b>Time:</b> {dateWithTimeZoneRenderer(timeZone, 'h:mm')(dateTime)}</div>
<div>Time: {dateWithTimeZoneRenderer(timeZone, 'h:mm')(dateTime)}</div>
</List.Item>
)
}}/>
Expand Down
21 changes: 10 additions & 11 deletions client/src/components/Schedule/CalendarView/components/Modal.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React from 'react';
import { Modal} from 'antd';
import { Modal, Space} from 'antd';
import moment from 'moment';
import {GithubUserLink} from 'components';
import { renderTag, urlRenderer } from 'components/Table/renderers';
Expand All @@ -15,9 +15,6 @@ type Props = {

export function ModalWindow({ isOpen, dataEvent, handleOnClose, timeZone }: Props) {

//!plug
const newTimeZone = timeZone === 'Europe/Yekaterinburg' ? 'Asia/Yekaterinburg' : timeZone;

return (
<>
<Modal
Expand All @@ -28,19 +25,21 @@ export function ModalWindow({ isOpen, dataEvent, handleOnClose, timeZone }: Prop
onCancel={() => handleOnClose()}
visible={isOpen}
>
<div>Date: {moment(dataEvent.dateTime, 'YYYY-MM-DD HH:mmZ').tz(newTimeZone).format('LLL')}</div>
{dataEvent.event.descriptionUrl &&
<div>Url: {urlRenderer(dataEvent.event.descriptionUrl)}</div>
}
<div>Date: {moment(dataEvent.dateTime, 'YYYY-MM-DD HH:mmZ').tz(timeZone).format('LLL')}</div>
{dataEvent.event.description &&
<div>{dataEvent.event.description}</div>
}
<div>
{renderTag(EventTypeToName[dataEvent.event.type] || dataEvent.event.type, EventTypeColor[dataEvent.event.type as keyof typeof EventTypeColor])}
</div>
{!!dataEvent.organizer.githubId &&
<div>Organizer: <GithubUserLink value={dataEvent.organizer.githubId} /></div>
}
<Space>
{dataEvent.event.descriptionUrl &&
<div>Url: {urlRenderer(dataEvent.event.descriptionUrl)}</div>
}
<div>
{renderTag(EventTypeToName[dataEvent.event.type] || dataEvent.event.type, EventTypeColor[dataEvent.event.type as keyof typeof EventTypeColor])}
</div>
</Space>
<style jsx>{`
div {
margin-bottom: 10px;
Expand Down
16 changes: 0 additions & 16 deletions client/src/components/Schedule/CalendarView/utils/DataFuncs.ts

This file was deleted.

21 changes: 0 additions & 21 deletions client/src/components/Schedule/CalendarView/utils/DateFuncs.ts

This file was deleted.

22 changes: 22 additions & 0 deletions client/src/components/Schedule/CalendarView/utils/filters.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import moment, { Moment } from 'moment';
import { CourseEvent } from 'services/course';
import { EventTypeColor} from 'components/Schedule/model';

export function getListData(calendarCellDate: Moment, data: CourseEvent[], timeZone: string) {
return filterByDate(calendarCellDate, data, timeZone).map((el: CourseEvent) => {
const tagColor = EventTypeColor[el.event.type as keyof typeof EventTypeColor];
return { color: tagColor || '#d9d9d9' , name: el.event.name, key: el.id };
});
}

export function filterByDate(calendarCellDate: Moment, data: CourseEvent[], timeZone: string) {
return data.filter(
(event) => calendarCellDate.format('YYYY-MM-DD') === moment(event.dateTime, 'YYYY-MM-DD HH:mmZ').tz(timeZone).format('YYYY-MM-DD'),
);
}

export function getMonthValue(calendarCellDate: Moment, data: CourseEvent[], timeZone: string) {
return data.filter(
(event) => calendarCellDate.format('MM-YYYY') === moment(event.dateTime, 'YYYY-MM-DD HH:mmZ').tz(timeZone).format('MM-YYYY'),
).length;
}
Loading

0 comments on commit 46d337d

Please sign in to comment.