Skip to content

Commit

Permalink
Merge pull request #35 from Li357/3.0.1-b4-new-schedule
Browse files Browse the repository at this point in the history
Add Wednesday schedule for non-Wednesdays
  • Loading branch information
Li357 authored Nov 15, 2019
2 parents a1d034f + 2a6896a commit 8a552a4
Show file tree
Hide file tree
Showing 15 changed files with 47 additions and 22 deletions.
4 changes: 4 additions & 0 deletions packages/app/__tests__/schedule/query-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -321,6 +321,7 @@ describe('schedule querying', () => {
noSchool: [new Date(2019, 11, 23), new Date(2019, 11, 24)],
earlyDismissal: [new Date(2019, 8, 4), new Date(2019, 10, 11)],
lateStart: [new Date(2019, 8, 25), new Date(2019, 10, 1)],
wednesday: [new Date(2019, 10, 15)],
semesterOneStart: new Date(2019, 7, 14),
semesterOneEnd: new Date(2019, 11, 22),
semesterTwoStart: new Date(2020, 0, 5),
Expand Down Expand Up @@ -393,6 +394,9 @@ describe('schedule querying', () => {
it('returns WEDNESDAY for wednesdays', () => {
const schedule = getSchedule(new Date(2019, 8, 18));
expect(schedule).toBe(SCHEDULES.WEDNESDAY);

const setWednesday = getSchedule(new Date(2019, 10, 15));
expect(setWednesday).toBe(SCHEDULES.WEDNESDAY);
});

it('returns REGULAR schedule otherwise', () => {
Expand Down
1 change: 1 addition & 0 deletions packages/app/__tests__/store/async-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ describe('async actions', () => {
noSchool: [],
earlyDismissal: [],
lateStart: [],
wednesday: [],
semesterOneStart: null,
semesterOneEnd: new Date(datesArray[1].date),
semesterTwoStart: null,
Expand Down
8 changes: 4 additions & 4 deletions packages/app/ios/Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ PODS:
- DoubleConversion
- glog
- glog (0.3.5)
- JWT (3.0.0-beta.11):
- JWT (3.0.0-beta.12):
- Base64 (~> 1.1.2)
- React (0.60.4):
- React-Core (= 0.60.4)
Expand Down Expand Up @@ -154,7 +154,7 @@ DEPENDENCIES:
- yoga (from `../node_modules/react-native/ReactCommon/yoga`)

SPEC REPOS:
https://github.com/cocoapods/specs.git:
trunk:
- Base64
- boost-for-react-native
- JWT
Expand Down Expand Up @@ -238,7 +238,7 @@ SPEC CHECKSUMS:
DoubleConversion: 5805e889d232975c086db112ece9ed034df7a0b2
Folly: 30e7936e1c45c08d884aa59369ed951a8e68cf51
glog: 1f3da668190260b06b429bb211bfbee5cd790c28
JWT: 05028b9624591bba9681bb57df2c5f95fa258bad
JWT: 9b5c05abbcc1a0e69c3c91e1655b3387fc7e581d
React: ff7ee2ae5ee1c1d9ae2183b4111045b25294bb01
React-ART: 87b6e9d975551e6177c660dd212529f73ed03681
React-Core: 8e0ea421cae5609d2562850f98421b15030476fa
Expand Down Expand Up @@ -272,4 +272,4 @@ SPEC CHECKSUMS:

PODFILE CHECKSUM: e6847c2c400140e9f10a719f1e854aeb193e1495

COCOAPODS: 1.7.5
COCOAPODS: 1.8.4
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,6 @@
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
shouldUseLaunchSchemeArgsEnv = "YES">
<Testables>
</Testables>
<MacroExpansion>
<BuildableReference
BuildableIdentifier = "primary"
Expand All @@ -80,8 +78,8 @@
ReferencedContainer = "container:WHS.xcodeproj">
</BuildableReference>
</MacroExpansion>
<AdditionalOptions>
</AdditionalOptions>
<Testables>
</Testables>
</TestAction>
<LaunchAction
buildConfiguration = "Debug"
Expand All @@ -103,8 +101,6 @@
ReferencedContainer = "container:WHS.xcodeproj">
</BuildableReference>
</BuildableProductRunnable>
<AdditionalOptions>
</AdditionalOptions>
</LaunchAction>
<ProfileAction
buildConfiguration = "Release"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict/>
<dict>
<key>BuildSystemType</key>
<string>Original</string>
<key>PreviewsEnabled</key>
<false/>
</dict>
</plist>
3 changes: 2 additions & 1 deletion packages/app/src/actions/async.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ export function fetchDates(year?: number) {
}

const [
assembly, noSchool, earlyDismissal, lateStart,
assembly, noSchool, earlyDismissal, lateStart, wednesday,
] = await Promise.all(DATE_TYPES.map(async (type) => {
const dates = await getDates(type, year!);
return dates.map((dateObj) => {
Expand All @@ -131,6 +131,7 @@ export function fetchDates(year?: number) {
noSchool,
earlyDismissal,
lateStart,
wednesday,
semesterOneStart,
semesterOneEnd,
semesterTwoStart,
Expand Down
6 changes: 3 additions & 3 deletions packages/app/src/components/schedule/ScheduleCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import { ClassItem, CrossSectionedItem, ScheduleItem, DaySchedule, ModNumber } f
import { AppState } from '../../types/store';
import { getScheduleTypeOnDate, getModAtTime, isHalfMod, convertTimeToDate } from '../../utils/query-schedule';
import * as SCHEDULES from '../../constants/schedules';
import { interpolateAssembly, getFinalsSchedule, createClassItem, injectAssemblyOrFinalsIfNeeded } from '../../utils/process-schedule';
import { createClassItem, injectAssemblyOrFinalsIfNeeded } from '../../utils/process-schedule';
import ClassCardItem from './ClassCardItem';
import CrossSectionedCardItem from './CrossSectionedCardItem';
import Subtext from '../common/Subtext';
Expand Down Expand Up @@ -118,8 +118,8 @@ const makeCardDayScheduleSelector = () => createSelector(
const isFinals = scheduleType === 'FINALS';

const revisedUserDaySchedule = injectAssemblyOrFinalsIfNeeded(schedule, scheduleType, day);
const userDaySchedule = revisedUserDaySchedule
.filter((scheduleItem) => (scheduleItem as ClassItem).title !== 'No Homeroom');
// Remove homeroom/no homeroom item on wednesday schedules
const userDaySchedule = revisedUserDaySchedule.slice(scheduleType === 'WEDNESDAY' ? 1 : 0);

const cardDaySchedule = daySchedule.map(([start, end, modNumber]) => {
const startTime = formatTime(start);
Expand Down
2 changes: 1 addition & 1 deletion packages/app/src/constants/fetch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ export const SERVER_URL = process.env.NODE_ENV === 'development'
export const DATES_URL = `${SERVER_URL}/api/${API_VERSION}/dates`;
export const FETCH_TIMEOUT = 5000;

export const DATE_TYPES: DateListType[] = ['assembly', 'no-school', 'early-dismissal', 'late-start'];
export const DATE_TYPES: DateListType[] = ['assembly', 'no-school', 'early-dismissal', 'late-start', 'wednesday'];
export const SETTING_TYPES: YearSettingType[] = [
'semester-one-start', 'semester-one-end', 'semester-two-start', 'semester-two-end',
];
Expand Down
1 change: 1 addition & 0 deletions packages/app/src/constants/store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ export const initialDatesState: DatesState = {
noSchool: [],
earlyDismissal: [],
lateStart: [],
wednesday: [],
semesterOneStart: null,
semesterOneEnd: null,
semesterTwoStart: null,
Expand Down
2 changes: 2 additions & 0 deletions packages/app/src/types/store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ export interface DatesState {
noSchool: Date[];
earlyDismissal: Date[];
lateStart: Date[];
wednesday: Date[];
semesterOneStart: Date | null;
semesterOneEnd: Date | null;
semesterTwoStart: Date | null;
Expand All @@ -96,6 +97,7 @@ export interface SerializedDatesState {
noSchool: string[];
earlyDismissal: string[];
lateStart: string[];
wednesday: string[];
semesterOneStart: string | null;
semesterOneEnd: string | null;
semesterTwoStart: string | null;
Expand Down
2 changes: 1 addition & 1 deletion packages/app/src/utils/bugsnag.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ function serializeState(state: AppState): IMetadata {
}

const config = new Configuration();
config.codeBundleId = '3.0.1-b3';
config.codeBundleId = '3.0.1-b4';
config.notifyReleaseStages = ['production'];
config.registerBeforeSendCallback((report) => {
const state = store.getState();
Expand Down
7 changes: 4 additions & 3 deletions packages/app/src/utils/process-info.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { load } from 'react-native-cheerio';
import { DateType, DateSchema } from '@whs/server';

import { fetch } from './utils';
import { fetch, isResponseOk } from './utils';
import { processSchedule } from './process-schedule';
import {
HEADER_SELECTOR, STUDENT_OVERVIEW_SELECTOR, STUDENT_ID_SELECTOR,
Expand All @@ -23,7 +23,8 @@ export async function parseHTMLFromURL(url: string, options?: RequestInit) {
timeout: FETCH_TIMEOUT,
...options,
});
if (!response.ok) {
// includes both ok and redirected
if (!isResponseOk(response)) {
throw new NetworkError();
}
const html = await response.text();
Expand Down Expand Up @@ -119,7 +120,7 @@ export async function fetchTeachersFromQuery(query: string, username: string, pa
timeout: FETCH_TIMEOUT,
signal,
});
if (!response.ok) {
if (!isResponseOk(response)) {
throw new NetworkError();
}
return response.json();
Expand Down
2 changes: 1 addition & 1 deletion packages/app/src/utils/query-schedule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ export function getScheduleTypeOnDate(queryDate: Date, dates: DatesState, omitBr
return 'WEEKEND';
}

if (day === 3) {
if (day === 3 || containsDate(queryDate, dates.wednesday)) {
return 'WEDNESDAY';
}
return 'REGULAR';
Expand Down
6 changes: 6 additions & 0 deletions packages/app/src/utils/store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import {
} from '../types/store';
import rootReducer from '../reducers/root';
import { reportNotEnoughSpace } from './utils';
import datesReducer from '../reducers/dates';

// Do not persist the profile-photo, it will be manually rehydrated
const profilePhotoTransform = createTransform<UserState, UserState>(
Expand Down Expand Up @@ -67,6 +68,11 @@ const dateTransform = createTransform<DatesState, SerializedDatesState>(
const migrations = {
// v-1 (WHS v1 and v2) --> v3
3: () => rootReducer(undefined, { type: MiscellaneousActions.OTHER }),
// add wednesday option to DatesState
4: (state: AppState) => ({
...state,
dates: datesReducer(undefined, { type: MiscellaneousActions.OTHER }),
}),
};

const persistConfig = {
Expand Down
10 changes: 9 additions & 1 deletion packages/app/src/utils/utils.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Alert } from 'react-native';
import { subDays, format } from 'date-fns';
import fetchPolyfill from 'react-native-fetch-polyfill';
import fetchPolyfill, { Timeout } from 'react-native-fetch-polyfill';
import debounce from 'lodash.debounce';

import client from './bugsnag';
Expand Down Expand Up @@ -89,6 +89,14 @@ export function last<T>(arr: T[]) {
return arr.slice(-1)[0];
}

/**
* Returns true if status between 200 and 308 inclusive
* @param response to check
*/
export function isResponseOk(response: Response) {
return response.status >= 200 && response.status <= 308;
}

/**
* Same signature as WHATWG fetch but rethrows TypeError as NetworkError for catching
*/
Expand Down

0 comments on commit 8a552a4

Please sign in to comment.