Skip to content
Open
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
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,11 @@
"interval-tree-type": "^1.0.1",
"react": "^17.0.1",
"react-dom": "^17.0.1",
"react-icons": "^4.2.0",
"react-router-dom": "^5.2.0",
"rrule": "^2.6.8",
"styled-components": "^5.2.1"
"styled-components": "^5.2.1",
"typescript": "^4.3.2"
},
"devDependencies": {
"@babel/core": "^7.13.10",
Expand Down
7 changes: 7 additions & 0 deletions src/App.styles.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,14 @@ export const AppGlobalStyles = createGlobalStyle`
}

:root {
/* colors */
--colors-primary: #000;
--primary-purple: #3D2D6B;
--primary-purple-transparent: rgba(73,58,117,0.33);
--primary-blue: #2825A6;
--primary-blue-transparent: rgba(40,37,166,0.33);

--navbar-height: 70px;
}

html,
Expand Down
2 changes: 1 addition & 1 deletion src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ const App = () => {
<AppGlobalStyles />
<Switch>
<Route exact path="/" component={Home} />
<Route exact path="/fing2021" component={CalendarPage} />
<Route exact path="/:schoolShortName" component={CalendarPage} />
</Switch>
</>
)
Expand Down
9 changes: 2 additions & 7 deletions src/Home.tsx
Original file line number Diff line number Diff line change
@@ -1,19 +1,14 @@
import * as React from "react"
import styled from "styled-components"

import LOGO from "./assets/logo.svg"
import { Logo } from "./components/Logo"

class Home extends React.Component {
render() {
return (
<Main>
<h2>
<img
src={LOGO}
alt="ClassTimes Logo"
title="ClassTimes"
height={112}
/>
<Logo height={112} />
</h2>
<h3>Follow your school classes</h3>
</Main>
Expand Down
16 changes: 16 additions & 0 deletions src/components/Button.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import styled from "styled-components"

export const Button = styled.a`
border-radius: 5px;
color: var(--primary-blue);
cursor: pointer;
margin: 5px;
padding: 12px;
text-decoration: none;
transition: all 0.2s linear;

&:hover {
box-shadow: inset 0 0 0 2px var(--primary-blue),
0 1px 4px 0 var(--primary-blue-transparent);
}
`
103 changes: 19 additions & 84 deletions src/components/Calendar/Calendar.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React from "react"
import * as React from "react"
import styled, { createGlobalStyle } from "styled-components"
import dayjs, { Dayjs } from "dayjs"
import localeData from "dayjs/plugin/localeData"
Expand All @@ -7,7 +7,7 @@ import localizedFormat from "dayjs/plugin/localizedFormat"
import weekday from "dayjs/plugin/weekday"
import timezone from "dayjs/plugin/timezone"
import utc from "dayjs/plugin/utc"
import { useQuery, gql } from "@apollo/client"
import { useQuery } from "@apollo/client"
import IntervalTree from "interval-tree-type"
import {
RRule,
Expand All @@ -25,6 +25,15 @@ import {
} from "../../types"
import { WeekView } from "./WeekView"

// Hooks
import { useSchoolCalendar } from "../../pages/CalendarPage/SchoolCalendarContext"

// Queries
import LIST_CALENDAR_EVENTS_QUERY from "./graphql/listCalendarEventsQuery.graphql"

// Helpers
import { mapEdges } from "../../helpers/mapEdges"

dayjs.extend(duration)
dayjs.extend(localeData)
dayjs.extend(localizedFormat)
Expand All @@ -33,37 +42,9 @@ dayjs.extend(utc)
dayjs.extend(timezone)

//dayjs.locale('en')

const ALL_EVENTS = gql`
query getAllEvents {
listCalendarEvents(filters: null, first: 2) {
edges {
node {
_id
title
isAllDay
durationHours
startDateUtc
endDateUtc
rrule
exceptionsDatesUtc
subject {
name
}
}
cursor
}
pageInfo {
endCursor
hasNextPage
}
}
}
`

interface ICalendar {
startAtHour?: number
title?: React.ReactNode
showHoursCount?: number
eventTreeCallback: (range: [Dayjs, Dayjs]) => TEventTree
}

Expand All @@ -90,14 +71,11 @@ const generateWeekdays = (selectedDate: Dayjs) => {
const generateNow = () => {
const now = dayjs()
// dayjs.localeData/().weekdays()

// const week = dayjs.duration({ weeks: 1 }).days()
// const day =
return { now } //JSON.stringify(week)
return { now }
}

export const Calendar: React.FC<ICalendar> = (props) => {
const { eventTreeCallback, title, startAtHour } = props
const { eventTreeCallback, startAtHour } = props
const [timezone, setTimezone] = React.useState(() => dayjs.tz.guess())
const { now } = generateNow()
const [selectedDate, setSelectedDate] = React.useState(now)
Expand All @@ -117,7 +95,6 @@ export const Calendar: React.FC<ICalendar> = (props) => {
return (
<CalendarWrapper>
<GlobalStyles />
{title && <CalendarTitle className="title">{title}</CalendarTitle>}
<CalendarSubtitle className="subtitle">
{selectedDate.format("MMMM YYYY")}
</CalendarSubtitle>
Expand Down Expand Up @@ -228,15 +205,6 @@ export const eventTreeGenerator: TEventGeneratorTyped = (
value: clonedEventEnd.toISOString(),
},
})
console.log("clonedEvent", {
ruleDate,
clonedEvent,
// sd: clonedEvent.startDateUtc
})
// clonedEvent.endDateUtc = clonedEvent.startDateUtc.add(
// clonedEvent.durationHours,
// "hours"
// )
tree.insert(
clonedEvent._startDateUtc,
clonedEvent._endDateUtc,
Expand All @@ -245,33 +213,7 @@ export const eventTreeGenerator: TEventGeneratorTyped = (
// clonedEvent.startDateUtc = clonedEvent.startDateUtc
// clonedEvent.endDateUtc = clonedEvent.endDateUtc.format()
}

console.log({ rule, ruleQuery })

// .fromString(
// "DTSTART;TZID=America/Denver:20181101T190000;\n"
// + "RRULE:FREQ=WEEKLY;BYDAY=MO,WE,TH;INTERVAL=1;COUNT=3"
// )
// const rule = RRule.fromString(
// "DTSTART;TZID=America/Denver:20181101T190000;\n"
// + "RRULE:FREQ=WEEKLY;BYDAY=MO,WE,TH;INTERVAL=1;COUNT=3"
// )
// // Create a rule:
// const rule = new RRule({
// freq: RRule.WEEKLY,
// interval: 5,
// byweekday: [RRule.MO, RRule.FR],
// dtstart: new Date(Date.UTC(2012, 1, 1, 10, 30)),
// until: new Date(Date.UTC(2012, 12, 31))
// })
}
// start.valueOf()
// console.log("Adding event to tree", {
// start,
// end,
// startValueOf: start.valueOf(),
// endValueOf: end.valueOf()
// })
}

return {
Expand All @@ -284,21 +226,15 @@ export const eventTreeGenerator: TEventGeneratorTyped = (
}

export const CalendarWithData = () => {
// TODO: Handle unauthorized?
const { loading, error, data } = useQuery<GetAllEvents>(ALL_EVENTS)

const calendarEventEdges = data?.listCalendarEvents?.edges

const title = calendarEventEdges?.[0]?.node?.subject?.name // Placeholder!
const events = calendarEventEdges?.map((edge) => edge.node)
const { calendarEvents } = useSchoolCalendar()

const eventTreeCallback = React.useCallback(
(range: [Dayjs, Dayjs]) => {
const result = eventTreeGenerator(events, range)
const result = eventTreeGenerator(calendarEvents, range)
console.log("save eventTree", result)
return result
},
[data, events]
[calendarEvents]
)

// if (eventTree) {
Expand All @@ -315,7 +251,7 @@ export const CalendarWithData = () => {
<Calendar
startAtHour={5.8}
showHoursCount={10}
{...{ title, eventTreeCallback }}
{...{ eventTreeCallback }}
/>
{/* <Pre>
loading: {loading ? "loading..." : "loaded"} <br />
Expand All @@ -327,14 +263,13 @@ export const CalendarWithData = () => {
}

const CalendarWrapper = styled.div`
border: 1px solid black;
height: 100%;
`

const Pre = styled.pre`
text-align: left;
`

const CalendarTitle = styled.h2``
const CalendarSubtitle = styled.div``
const CalendarTimezone = styled.div``

Expand Down
6 changes: 4 additions & 2 deletions src/components/Calendar/WeekView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,6 @@ const WeekViewBody: React.FC<IWeekViewBody> = (props) => {
const colCount = group.length
return Array.from(col).map((ev, eventIndex) => {
const { data: event, startDate } = ev

let topPosition =
startDate.hour() + startDate.minute() / 60
topPosition *= 100
Expand All @@ -267,6 +266,7 @@ const WeekViewBody: React.FC<IWeekViewBody> = (props) => {

const duration = (event.durationHours * 100) / 24
const isRecurrent = !!event.rrule
const toggled = event.toggled
// console.log("[WeekViewEventItem]", {
// event,
// startDate,
Expand All @@ -278,6 +278,7 @@ const WeekViewBody: React.FC<IWeekViewBody> = (props) => {
return (
<WeekViewEventWrapper
{...{
toggled,
isRecurrent,
colIndex,
colCount,
Expand Down Expand Up @@ -570,10 +571,11 @@ interface IWeekViewEventWrapper {
colIndex: number
colCount: number
isRecurrent: boolean
toggled: boolean
}

const WeekViewEventWrapper = styled.div<IWeekViewEventWrapper>`
display: flex;
display: ${(props) => (props.toggled ? "flex" : "none")};
line-height: 1;
position: absolute;
top: ${(p) => (p.topPosition ? `${p.topPosition}%` : 0)};
Expand Down
34 changes: 34 additions & 0 deletions src/components/Calendar/graphql/listCalendarEventsQuery.graphql
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
query listCalendarEventsQuery(
$filters: ListCalendarEventsInput
$first: Float
$after: String
$before: String
) {
listCalendarEvents(
filters: $filters
first: $first
after: $after
before: $before
) {
edges {
node {
_id
title
isAllDay
durationHours
startDateUtc
endDateUtc
rrule
exceptionsDatesUtc
subject {
name
}
}
cursor
}
pageInfo {
endCursor
hasNextPage
}
}
}
25 changes: 25 additions & 0 deletions src/components/Calendar/graphql/listSubjectsQuery.graphql
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
query listSubjectsQuery(
$filters: ListSubjectInput
$first: Float
$after: String
$before: String
) {
listSubjects(
filters: $filters
first: $first
after: $after
before: $before
) {
edges {
node {
_id
name
}
cursor
}
pageInfo {
endCursor
hasNextPage
}
}
}
Loading