Skip to content

Commit 042da8c

Browse files
committed
Prettier
1 parent a7ef5ea commit 042da8c

10 files changed

+240
-176
lines changed

src/app/models/accounts-model.ts

Lines changed: 29 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ export type SfUserModel = {
3838
is_verified: boolean;
3939
is_guessed_preferred: boolean;
4040
}[];
41-
}
41+
};
4242

4343
export default {
4444
load: cached(() => {
@@ -82,35 +82,34 @@ export default {
8282
// ]
8383
// });
8484
// eslint-disable-next-line no-unreachable
85-
return fetch(accountsUrl, {credentials: 'include'})
86-
.then(
87-
(response) => {
88-
if (response.status === 403) {
89-
return {};
90-
}
91-
return response.json().then(
92-
(result) => {
93-
if (
94-
'dataLayer' in window &&
95-
window.dataLayer instanceof Array
96-
) {
97-
window.dataLayer.push({
98-
// eslint-disable-next-line camelcase
99-
faculty_status: result.faculty_status
100-
});
101-
}
102-
return result as SfUserModel;
103-
},
104-
(err: unknown) => {
105-
console.warn('No JSON in Accounts response');
106-
return {err};
107-
}
108-
);
109-
},
110-
(err: unknown) => {
111-
console.warn('"Error fetching user info"');
112-
return {err};
85+
return fetch(accountsUrl, {credentials: 'include'}).then(
86+
(response) => {
87+
if (response.status === 403) {
88+
return {};
11389
}
114-
);
90+
return response.json().then(
91+
(result) => {
92+
if (
93+
'dataLayer' in window &&
94+
window.dataLayer instanceof Array
95+
) {
96+
window.dataLayer.push({
97+
// eslint-disable-next-line camelcase
98+
faculty_status: result.faculty_status
99+
});
100+
}
101+
return result as SfUserModel;
102+
},
103+
(err: unknown) => {
104+
console.warn('No JSON in Accounts response');
105+
return {err};
106+
}
107+
);
108+
},
109+
(err: unknown) => {
110+
console.warn('"Error fetching user info"');
111+
return {err};
112+
}
113+
);
115114
})
116115
};

src/app/models/blog-entries.ts

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,28 @@ import {useDataFromSlug, camelCaseKeys} from '~/helpers/page-data-utils';
22
import {ArticleSummary} from '~pages/blog/blog-context';
33

44
const fields = [
5-
'title', 'id', 'article_image', 'featured_image_alt_text', 'heading',
6-
'subheading', 'body_blurb', 'date', 'author', 'article_subjects', 'collections'
5+
'title',
6+
'id',
7+
'article_image',
8+
'featured_image_alt_text',
9+
'heading',
10+
'subheading',
11+
'body_blurb',
12+
'date',
13+
'author',
14+
'article_subjects',
15+
'collections'
716
].join(',');
817

918
export default function useLatestBlogEntries(limit: number) {
1019
const lsData = useDataFromSlug<{
1120
items: ArticleSummary[];
1221
meta: {
1322
total_count: number;
14-
}
23+
};
1524
}>(
1625
`pages?type=news.newsArticle&fields=${fields}` +
17-
`&order=-date&pin_to_top=false&limit=${limit}`
26+
`&order=-date&pin_to_top=false&limit=${limit}`
1827
);
1928

2029
if (!lsData) {

src/app/models/myopenstax-user.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,15 +20,18 @@ type OSUser = {
2020
createdAt: string;
2121
salesforceId: string;
2222
};
23-
}
23+
};
2424

2525
async function fetchUser() {
2626
const user = await sfApiFetch('users');
2727

2828
return camelCaseKeys({...INITIAL_STATE, ...user}) as OSUser;
2929
}
3030

31-
export default function useMyOpenStaxUser(isVerified: boolean, fetchTime: number) {
31+
export default function useMyOpenStaxUser(
32+
isVerified: boolean,
33+
fetchTime: number
34+
) {
3235
const [user, setUser] = React.useState<OSUser>({error: 'not loaded'});
3336
const {flags} = useSharedDataContext();
3437

src/app/models/partner-info.ts

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,19 +5,16 @@ import {camelCaseKeys} from '~/helpers/page-data-utils';
55
type Data = {
66
id: number;
77
partnerName: string;
8-
}
8+
};
99

1010
function usePartnerData(id: string) {
1111
const [data, setData] = useState<Data>();
1212

13-
useLayoutEffect(
14-
() => {
15-
cmsFetch(`salesforce/partners/${id}`)
16-
.then((d) => camelCaseKeys(d) as Data)
17-
.then(setData);
18-
},
19-
[id]
20-
);
13+
useLayoutEffect(() => {
14+
cmsFetch(`salesforce/partners/${id}`)
15+
.then((d) => camelCaseKeys(d) as Data)
16+
.then(setData);
17+
}, [id]);
2118

2219
return data;
2320
}

src/app/models/renewals.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,9 @@ export default function useAdoptions(uuid: string) {
66

77
useEffect(() => {
88
if (uuid) {
9-
fetchFromCMS(`salesforce/renewal?account_uuid=${uuid}`).then(setAdoptions);
9+
fetchFromCMS(`salesforce/renewal?account_uuid=${uuid}`).then(
10+
setAdoptions
11+
);
1012
}
1113
}, [uuid]);
1214

src/app/models/rex-release.ts

Lines changed: 25 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -2,42 +2,49 @@ import memoize from 'lodash/memoize';
22
import retry from '~/helpers/retry';
33

44
function rexOriginFromWebview(url: string) {
5-
return (new window.URL(url)).origin;
5+
return new window.URL(url).origin;
66
}
77

88
// CAUTION: Lodash memoize only distinguishes the first parameter
99
const fetchRexInfo = memoize((rexOrigin) => {
1010
return retry(() => fetch(`${rexOrigin}/rex/environment.json`))
1111
.then((response) => response.json())
12-
.then((environment) => Promise.all([
13-
fetch(`${rexOrigin}/rex/releases/${environment.release_id}/rex/release.json`)
14-
.then((response) => response.json()),
15-
fetch(`${rexOrigin}/rex/releases/${environment.release_id}/rex/config.json`)
16-
.then((response) => response.json())
17-
]))
12+
.then((environment) =>
13+
Promise.all([
14+
fetch(
15+
`${rexOrigin}/rex/releases/${environment.release_id}/rex/release.json`
16+
).then((response) => response.json()),
17+
fetch(
18+
`${rexOrigin}/rex/releases/${environment.release_id}/rex/config.json`
19+
).then((response) => response.json())
20+
])
21+
)
1822
.then(([release, config]) => ({release, config}))
19-
.catch((err) => {throw new Error(`Fetching Rex info: ${err}`);})
20-
;
23+
.catch((err) => {
24+
throw new Error(`Fetching Rex info: ${err}`);
25+
});
2126
});
2227

2328
// REMEMBER: The first parameter is the memo key
2429
const fetchContents = memoize((cnxId, rexOrigin) => {
2530
return fetchRexInfo(rexOrigin)
2631
.then((rexInfo) => {
27-
const archiveOverride = rexInfo.release.books[cnxId].archiveOverride;
28-
const archiveVersion = archiveOverride ?
29-
archiveOverride.replace(/^\/apps\/archive\//, '') :
30-
rexInfo.config.REACT_APP_ARCHIVE
31-
;
32-
32+
const archiveOverride =
33+
rexInfo.release.books[cnxId].archiveOverride;
34+
const archiveVersion = archiveOverride
35+
? archiveOverride.replace(/^\/apps\/archive\//, '')
36+
: rexInfo.config.REACT_APP_ARCHIVE;
3337
const bookVersion = rexInfo.release.books[cnxId].defaultVersion;
3438
const archivePath = `apps/archive/${archiveVersion}`;
3539

36-
return fetch(`${process.env.API_ORIGIN}/${archivePath}/contents/${cnxId}@${bookVersion}.json`);
40+
return fetch(
41+
`${process.env.API_ORIGIN}/${archivePath}/contents/${cnxId}@${bookVersion}.json`
42+
);
3743
})
3844
.then((response) => response.json())
39-
.catch((err) => {throw new Error(`Fetching Rex contents: ${err}`);})
40-
;
45+
.catch((err) => {
46+
throw new Error(`Fetching Rex contents: ${err}`);
47+
});
4148
});
4249

4350
export default function fetchRexRelease(webviewLink: string, cnxId: string) {

src/app/models/sfapi.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,15 @@
11
import settings from '~/helpers/window-settings';
22

33
const subdomains = ['dev.', 'qa.', 'staging.'];
4-
const subdomain = subdomains.find((sd) => settings().accountHref?.includes(sd)) || '';
4+
const subdomain =
5+
subdomains.find((sd) => settings().accountHref?.includes(sd)) || '';
56
const server = `https://${subdomain}salesforce.openstax.org`;
67

7-
export async function sfApiPost(objectType: string, data: object, method = 'POST') {
8+
export async function sfApiPost(
9+
objectType: string,
10+
data: object,
11+
method = 'POST'
12+
) {
813
try {
914
const options = {
1015
credentials: 'include',

src/app/models/use-school-suggestion-list.ts

Lines changed: 33 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -6,19 +6,20 @@ import debounce from 'lodash/debounce';
66
import type {SchoolInfo} from './query-schools';
77

88
type SFSchoolInfo = SchoolInfo & {school_type?: string};
9-
type SchoolFetchFunction = (value: string) => Promise<(SFSchoolInfo)[]>;
9+
type SchoolFetchFunction = (value: string) => Promise<SFSchoolInfo[]>;
1010

1111
const debouncedFetch = debounce(
1212
(schoolFetch: SchoolFetchFunction, value, setSchools) => {
1313
if (value?.length > 1) {
14-
schoolFetch(value).then((list) => list.map(
15-
(entry) => ({
16-
name: entry.name,
17-
type: entry.school_type || entry.type, // different names in sfapi and old cms?
18-
location: entry.location,
19-
total_school_enrollment: entry.total_school_enrollment // eslint-disable-line camelcase
20-
})
21-
))
14+
schoolFetch(value)
15+
.then((list) =>
16+
list.map((entry) => ({
17+
name: entry.name,
18+
type: entry.school_type || entry.type, // different names in sfapi and old cms?
19+
location: entry.location,
20+
total_school_enrollment: entry.total_school_enrollment // eslint-disable-line camelcase
21+
}))
22+
)
2223
.then(setSchools);
2324
} else {
2425
setSchools([]);
@@ -31,10 +32,14 @@ function useSchoolFetchFunction() {
3132
const {flags} = useSharedDataContext();
3233
const {my_openstax: isEnabled} = flags || {};
3334
const fn = useMemo(
34-
() => (isEnabled ?
35-
(value: string) => sfApiFetch('schools', `/search?name=${value}`) :
36-
(value: string) => cmsFetch(`salesforce/schools?search=${value}`)) as SchoolFetchFunction
37-
,
35+
() =>
36+
(isEnabled
37+
? (value: string) =>
38+
sfApiFetch('schools', `/search?name=${value}`)
39+
: (value: string) =>
40+
cmsFetch(
41+
`salesforce/schools?search=${value}`
42+
)) as SchoolFetchFunction,
3843
[isEnabled]
3944
);
4045

@@ -44,11 +49,22 @@ function useSchoolFetchFunction() {
4449
export default function useMatchingSchools(value: string) {
4550
const schoolFetch = useSchoolFetchFunction();
4651
const [schools, setSchools] = useState<SchoolInfo[]>([]);
47-
const schoolNames = useMemo(() => schools.map((s) => s.name).sort(), [schools]);
48-
const schoolSet = useMemo(() => new window.Set(schoolNames.map((s) => s.toLowerCase())), [schoolNames]);
52+
const schoolNames = useMemo(
53+
() => schools.map((s) => s.name).sort(),
54+
[schools]
55+
);
56+
const schoolSet = useMemo(
57+
() => new window.Set(schoolNames.map((s) => s.toLowerCase())),
58+
[schoolNames]
59+
);
4960
const schoolIsOk = schoolSet.has(value?.toLowerCase());
50-
const selectedSchool = schoolIsOk && schools.find((s) => s.name.toLowerCase() === value.toLowerCase());
51-
const schoolOptions = useMemo(() => schoolNames.map((n) => ({label: n, value: n})), [schoolNames]);
61+
const selectedSchool =
62+
schoolIsOk &&
63+
schools.find((s) => s.name.toLowerCase() === value.toLowerCase());
64+
const schoolOptions = useMemo(
65+
() => schoolNames.map((n) => ({label: n, value: n})),
66+
[schoolNames]
67+
);
5268

5369
React.useEffect(
5470
() => debouncedFetch(schoolFetch, value, setSchools),

src/app/models/usermodel.ts

Lines changed: 30 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -30,17 +30,27 @@ function oldUserModel(sfUserModel: SfUserModel) {
3030
if (!('id' in sfUserModel)) {
3131
return {};
3232
}
33-
const findPreferredEmail = (contacts: UserModelType['accountsModel']['contact_infos']) => (contacts
34-
.filter((obj) => obj.type === 'EmailAddress')
35-
.reduce((a, b) => {
36-
if (b.is_guessed_preferred || (b.is_verified && !a.is_verified)) {
37-
return b;
38-
}
39-
return a;
40-
})).value;
41-
const isStudent = ['student', 'unknown_role'].includes(sfUserModel.self_reported_role);
42-
const isVerificationStale = !isStudent && sfUserModel.is_instructor_verification_stale;
43-
const isVerificationPending = !isStudent &&
33+
const findPreferredEmail = (
34+
contacts: UserModelType['accountsModel']['contact_infos']
35+
) =>
36+
contacts
37+
.filter((obj) => obj.type === 'EmailAddress')
38+
.reduce((a, b) => {
39+
if (
40+
b.is_guessed_preferred ||
41+
(b.is_verified && !a.is_verified)
42+
) {
43+
return b;
44+
}
45+
return a;
46+
}).value;
47+
const isStudent = ['student', 'unknown_role'].includes(
48+
sfUserModel.self_reported_role
49+
);
50+
const isVerificationStale =
51+
!isStudent && sfUserModel.is_instructor_verification_stale;
52+
const isVerificationPending =
53+
!isStudent &&
4454
['pending_faculty'].includes(sfUserModel.faculty_status) &&
4555
!isVerificationStale;
4656
const groups = (function () {
@@ -61,15 +71,19 @@ function oldUserModel(sfUserModel: SfUserModel) {
6171
'pending_faculty'
6272
].includes(sfUserModel.faculty_status);
6373
const incompleteSignup = sfUserModel.faculty_status === 'incomplete_signup';
64-
const emailUnverified = !sfUserModel.contact_infos.some((i) => i.is_verified);
74+
const emailUnverified = !sfUserModel.contact_infos.some(
75+
(i) => i.is_verified
76+
);
6577
const instructorEligible = sfUserModel.faculty_status === 'no_faculty_info';
6678

6779
/* eslint camelcase: 0 */
6880
return {
6981
id: sfUserModel.id,
7082
accounts_id: sfUserModel.id,
7183
uuid: sfUserModel.uuid,
72-
email: (sfUserModel.contact_infos).length ? findPreferredEmail(sfUserModel.contact_infos) : undefined,
84+
email: sfUserModel.contact_infos.length
85+
? findPreferredEmail(sfUserModel.contact_infos)
86+
: undefined,
7387
first_name: sfUserModel.first_name,
7488
groups,
7589
last_name: sfUserModel.last_name,
@@ -90,7 +104,9 @@ function oldUserModel(sfUserModel: SfUserModel) {
90104

91105
const userModel = {
92106
load() {
93-
return accountsModel.load()?.then((sfModel) => oldUserModel(sfModel as SfUserModel));
107+
return accountsModel
108+
.load()
109+
?.then((sfModel) => oldUserModel(sfModel as SfUserModel));
94110
}
95111
};
96112

0 commit comments

Comments
 (0)