Skip to content

Commit

Permalink
Merge pull request #76 from sqrl-planner/develop
Browse files Browse the repository at this point in the history
Bump version
  • Loading branch information
eamonma authored Jun 21, 2022
2 parents 1b7b8c7 + 6a8a4b0 commit 4a252cb
Show file tree
Hide file tree
Showing 9 changed files with 269 additions and 87 deletions.
97 changes: 67 additions & 30 deletions components/ShareCalendar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ import {
} from "@chakra-ui/react"
import React, { useRef } from "react"
// import ics from "ics"
// import ical, { ICalCalendar, ICalCategory } from "ical-generator"
import ical from "ical-generator"
import MeetingsFabricator from "../src/MeetingsFabricator"
import { minuteOffsetToIcalArray } from "../src/utils/time"
import icalFabricator, { dateToIcsString, SqrlIcsEvent } from "../src/utils/ics"
import { dateToIcsString, SqrlIcsEvent } from "../src/utils/ics"
import { Meeting } from "./timetable/Meeting"
import useSections from "../src/useSections"
import useCourses from "../src/useCourses"
Expand All @@ -26,7 +26,7 @@ const ShareCalendar = () => {

const downloadRef = useRef<HTMLAnchorElement | null>(null)

const shareCalendar = () => {
const shareCalendar = async () => {
const startTimes = {
first: { year: 2022, month: 9, day: 8 },
second: { year: 2023, month: 1, day: 9 },
Expand All @@ -42,40 +42,42 @@ const ShareCalendar = () => {
second: MeetingsFabricator(courses, userMeetings, "SECOND_SEMESTER"),
}

const calendar = ical({ name: "SqrlTimetable" })

// calendar.timezone({
// name: "America/Toronto",
// generator: getVtimezoneComponent,
// })

for (const [semester, meetings] of Object.entries(
segregatedMeetings
) as Array<["first" | "second", Meeting[]]>) {
const semesterStart = Object.values(startTimes[semester]).join("-")
const semesterEnd = Object.values(endTimes[semester]).join("-")
for (const meeting of meetings) {
const [startHour, startMinute] = minuteOffsetToIcalArray(
meeting.startTime
)
const [endHour, endMinute] = minuteOffsetToIcalArray(meeting.endTime)

events.push({
summary: meeting.title,
meeting,
firstStart: new Date(
Date.UTC(
startTimes[semester].year,
startTimes[semester].month - 1,
startTimes[semester].day,
startHour,
startMinute
)
),
firstEnd: new Date(
Date.UTC(
startTimes[semester].year,
startTimes[semester].month - 1,
startTimes[semester].day,
endHour,
endMinute
)
),
rruleBeforeDate: `FREQ=WEEKLY;BYDAY=${meeting.day
const start = new Date(semesterStart)
start.setHours(startHour)
start.setMinutes(startMinute)

// const end = new Date(semesterEnd)
// end.setHours(endHour)
// end.setMinutes(endMinute)
const end = new Date(semesterStart)
end.setHours(endHour)
end.setHours(endMinute)

calendar.createEvent({
start,
end,
summary: `${meeting.title} ${meeting.category} ${meeting.section}`,
repeating: `FREQ=WEEKLY;BYDAY=${meeting.day
.substring(0, 2)
.toUpperCase()};INTERVAL=1;`,
rruleUntil: `${dateToIcsString(
.toUpperCase()};INTERVAL=1;${dateToIcsString(
new Date(
Date.UTC(
endTimes[semester].year,
Expand All @@ -84,16 +86,51 @@ const ShareCalendar = () => {
)
)
)}`,
tzid: `America/Toronto`,
// timezone: "America/Toronto",
})

// events.push({
// summary: meeting.title,
// meeting,
// firstStart: new Date(
// Date.UTC(
// startTimes[semester].year,
// startTimes[semester].month - 1,
// startTimes[semester].day,
// startHour,
// startMinute
// )
// ),
// firstEnd: new Date(
// Date.UTC(
// startTimes[semester].year,
// startTimes[semester].month - 1,
// startTimes[semester].day,
// endHour,
// endMinute
// )
// ),
// rruleBeforeDate: `FREQ=WEEKLY;BYDAY=${meeting.day
// .substring(0, 2)
// .toUpperCase()};INTERVAL=1;`,
// rruleUntil: `${dateToIcsString(
// new Date(
// Date.UTC(
// endTimes[semester].year,
// endTimes[semester].month - 1,
// endTimes[semester].day + 1
// )
// )
// )}`,
// tzid: `America/Toronto`,
// })
}
}

// if (!value) return
if (!downloadRef.current) return

downloadRef.current.href =
"data:text/calendar;charset=utf8," + escape(icalFabricator(events))
"data:text/calendar;charset=utf8," + escape(calendar.toString())
downloadRef.current.download = "SqrlTimetable"
downloadRef.current.click()
}
Expand Down
2 changes: 1 addition & 1 deletion components/preferences/PreferencesMeeting.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ const PreferencesMeeting = () => {
iconProps={{
as: FaTruckMoving,
}}
helperText={t("deliver-method-suffix")}
helperText={t("delivery-method-suffix")}
>
{t("delivery-method")}
</PreferencesToggle>
Expand Down
18 changes: 8 additions & 10 deletions components/sidebar/MeetingPicker.tsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
import {
AddIcon,
CheckIcon,
QuestionIcon,
WarningIcon,
WarningTwoIcon,
} from "@chakra-ui/icons"
import {
Box,
Button,
chakra,
Flex,
Grid,
Expand Down Expand Up @@ -469,14 +467,14 @@ const MeetingPicker = ({
""
)}

<Button
variant="link"
onClick={(e: React.MouseEvent<HTMLButtonElement>) => {
e.stopPropagation()
}}
>
<QuestionIcon fontSize="lg" />
</Button>
{/* <Button */}
{/* variant="link" */}
{/* onClick={(e: React.MouseEvent<HTMLButtonElement>) => { */}
{/* e.stopPropagation() */}
{/* }} */}
{/* > */}
{/* <QuestionIcon fontSize="lg" /> */}
{/* </Button> */}
</Flex>
</Grid>
</ConditionalWrapper>
Expand Down
103 changes: 77 additions & 26 deletions components/sidebar/SearchView/SearchView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -43,19 +43,20 @@ const SearchView = ({
}) => {
const searchRef = useRef() as MutableRefObject<HTMLInputElement>
const [searchOffset, setSearchOffset] = useState<number>(0)
const [searchLimit, setSearchLimit] = useState<number>(7)
const [chosenCourse, setChosenCourse] = useState("")

const [search, { loading, data, error, fetchMore }] =
useLazyQuery(SEARCH_COURSES)

const debounced = useDebouncedCallback((query) => {
if (!query) return
search({ variables: { query, offset: searchOffset } })
search({ variables: { query, offset: searchOffset, limit: searchLimit } })
}, 300)

const debouncedZero = useDebouncedCallback((query) => {
if (!query) return
search({ variables: { query, offset: searchOffset } })
search({ variables: { query, offset: searchOffset, limit: searchLimit } })
}, 0)

useEffect(() => {
Expand All @@ -71,9 +72,22 @@ const SearchView = ({
}, [])

useEffect(() => {
setSearchOffset(0)
debounced(searchQuery)
}, [searchQuery])

useEffect(() => {
if (searchOffset === 0) return

search({
variables: {
query: searchQuery,
offset: searchOffset,
limit: searchLimit,
},
})
}, [searchQuery, searchLimit, searchOffset])

const { t } = useTranslation(["common", "sidebar"])

return (
Expand Down Expand Up @@ -166,13 +180,11 @@ const SearchView = ({
{'".'}
</Flex>
)}
{data.searchCourses.length > 6 ? (
<MotionButton
alignSelf="center"
<Flex pt={4} px={6} w="full" justifyContent="space-between">
{searchOffset > 0 && <MotionButton
p={2}
mt={4}
variant="link"
key="button"
key="previous"
variants={{
hidden: {
opacity: 0,
Expand All @@ -184,26 +196,65 @@ const SearchView = ({
initial="hidden"
animate="visible"
isLoading={loading}
onClick={() => {
setSearchOffset((prev) => {
const newSearchOffset = prev - searchLimit
if (newSearchOffset === 0) {
debouncedZero(searchQuery)
}
return newSearchOffset
})
}}
>
More results...
</MotionButton>
) : (
<Tooltip label="No more results.">
<Divider
style={{
marginTop: `calc(var(--chakra-space-4) * -1)`,
}}
_after={{
content: `""`,
height: 8,
width: "100%",
position: "absolute",
left: 0,
right: 0,
}}
/>
</Tooltip>
)}
&lt;- Previous
</MotionButton>}
{data.searchCourses.length > 6 ? (
<React.Fragment>
<MotionButton
p={2}
ml="auto"
variant="link"
key="next"
variants={{
hidden: {
opacity: 0,
},
visible: {
opacity: 1,
},
}}
initial="hidden"
animate="visible"
isLoading={loading}
onClick={() => {
setSearchOffset((prev) => prev + searchLimit)
}}
>
Next -&gt;
</MotionButton>
</React.Fragment>
) : (
<Tooltip label="No more results.">
<Divider
position="absolute"
w="full"
left={0}
right={0}
style={{
marginTop: `calc(var(--chakra-space-4) * -1)`,
}}
_after={{
content: `""`,
height: 8,
width: "100%",
position: "absolute",
left: 0,
right: 0,
}}
/>
</Tooltip>
)}
</Flex>
</VStack>
)}
</AnimatePresence>
Expand Down
12 changes: 12 additions & 0 deletions next.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,16 @@ module.exports = withBundleAnalyzer({
compiler: {
styledComponents: true,
},
webpack: (config) => {
return {
...config,
"resolve": {
...config.resolve,
"fallback": {
...config.resolve.fallback,
"fs": false
}
}
}
}
})
4 changes: 2 additions & 2 deletions operations/queries/searchCourses.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { gql } from "@apollo/client"

export const SEARCH_COURSES = gql`
query searchCourses($query: String!, $offset: Int) {
searchCourses(query: $query, limit: 7, offset: $offset) {
query searchCourses($query: String!, $limit: Int, $offset: Int) {
searchCourses(query: $query, limit: $limit, offset: $offset) {
id
code
title
Expand Down
Loading

0 comments on commit 4a252cb

Please sign in to comment.