@codecademy/brand 0.13.43 → 0.13.44-alpha.4b0248856c.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,75 +0,0 @@
1
- import { ContentItemType } from '../ScoreSummary/helpers';
2
- export interface StudyPlanInputValues {
3
- sessionLength: number;
4
- sessionsPerWeek: number;
5
- targetTimeFrame: number;
6
- }
7
- export interface StudyPlanInputErrorMessageValues {
8
- sessionLength?: string;
9
- sessionsPerWeek?: string;
10
- }
11
- export type StudyPlanContainerType = 'Track' | 'Path' | 'Journey';
12
- export type SessionContentItem = {
13
- contentItemId: string;
14
- moduleSlug: string;
15
- pathSlug?: string | null;
16
- trackSlug: string;
17
- };
18
- export type StudyPlanContentItemType = {
19
- slug: string;
20
- type?: string | null;
21
- title?: string | null;
22
- metrics: {
23
- medianTimeToCompleteMinutes?: number | null;
24
- };
25
- experience: number;
26
- skillIds?: string[] | null;
27
- id: string;
28
- progressV2?: {
29
- completed: boolean;
30
- } | null;
31
- };
32
- export declare const maxContentItemsToShow = 5;
33
- export declare const studyPlanDefaultInputValues: {
34
- sessionLength: number;
35
- sessionsPerWeek: number;
36
- targetTimeFrame: number;
37
- };
38
- export declare const studyPlanIncrementValues: {
39
- sessionLength: number;
40
- sessionsPerWeek: number;
41
- targetTimeFrame: number;
42
- };
43
- export declare const calculateTimeLeftToComplete: (containerTimeToComplete?: number | null, containerPercentComplete?: number | null) => number;
44
- export declare const calculateTargetTimeFrame: (sessionsPerWeek: number, sessionLength: number, containerPercentComplete?: number | null, containerTimeToComplete?: number | null) => number;
45
- export declare const formatTargetTimeFrameText: (targetTimeFrameInWeeks: number) => string;
46
- export declare const formatContentItemTypeTitle: (type?: string) => string;
47
- export declare const formatContainerTimeToCompleteText: (containerTimeToComplete?: number | null, containerTitle?: string | null) => string;
48
- export declare const formatContainerType: (containerType: string) => string;
49
- export declare const getContentItemsToShow: (contentItems: StudyPlanContentItemType[], showMoreContentItems: boolean) => StudyPlanContentItemType[];
50
- export declare const validateStudyPlanFormInput: (name: string, value: string) => {
51
- isAboveMaxValue: boolean;
52
- isBelowMinValue: boolean;
53
- isValidIncrement: boolean;
54
- isValidFormInputValue: boolean;
55
- };
56
- export declare const formatFormErrorMessage: (name: string, value: string) => string;
57
- export declare const calculateTotalContentItemProgress: (contentItems?: StudyPlanContentItemType[] | null) => number;
58
- export declare const getSessionContainerSlugs: (contentItemId: string, sessionContentItems?: SessionContentItem[] | null) => {
59
- moduleSlug: string;
60
- trackSlug: string;
61
- pathSlug: string | null | undefined;
62
- };
63
- export declare const contentItemResumePath: (courseSlug: string, contentItem?: {
64
- slug?: string;
65
- type?: ContentItemType | null;
66
- }, redirectSlug?: string | undefined, anon?: boolean) => string;
67
- export declare const createContentItemHref: (containerType: string, contentItem: {
68
- type?: string | null;
69
- slug?: string;
70
- }, contentItemSlug?: string, pathSlug?: string | null, trackSlug?: string, moduleSlug?: string) => string | undefined;
71
- export declare const formatContentItemTimeToComplete: (timeToCompleteInMinutes: number, isContentItemTimeToComplete?: boolean) => string;
72
- export declare const formatStudyPlanSummaryText: (sessionLength: number, sessionsPerWeek: number, targetTimeFrameText: string) => string;
73
- export declare const formatStudyPlanText: (sessionLength: number, sessionsPerWeek: number) => string;
74
- export declare const hoverBackgroundTransition: string;
75
- export declare const getShouldDisplayNewBadge: () => boolean;
@@ -1,165 +0,0 @@
1
- import { transitionConcat } from '@codecademy/gamut-styles';
2
- import { formatDuration, minutesInHour } from 'date-fns';
3
- import { capitalize } from 'lodash/fp';
4
- import pluralize from 'pluralize';
5
- import { createResumeUrlPath, getContentItemTypeRoutePart } from '../ScoreSummary/helpers';
6
- export const maxContentItemsToShow = 5;
7
- export const studyPlanDefaultInputValues = {
8
- sessionLength: 1,
9
- sessionsPerWeek: 3,
10
- targetTimeFrame: 1
11
- };
12
- export const studyPlanIncrementValues = {
13
- sessionLength: 0.25,
14
- sessionsPerWeek: 1,
15
- targetTimeFrame: 1
16
- };
17
- export const calculateTimeLeftToComplete = (containerTimeToComplete, containerPercentComplete) => {
18
- return (containerTimeToComplete || 1) * (1 - (containerPercentComplete || 1) / 100);
19
- };
20
- export const calculateTargetTimeFrame = (sessionsPerWeek, sessionLength, containerPercentComplete, containerTimeToComplete) => {
21
- const containerTimeLeftToComplete = calculateTimeLeftToComplete(containerTimeToComplete, containerPercentComplete);
22
-
23
- // returns the target number of weeks to complete the container based on users progress
24
- return Number((containerTimeLeftToComplete / (sessionsPerWeek * sessionLength)).toFixed(2));
25
- };
26
- export const formatTargetTimeFrameText = targetTimeFrameInWeeks => {
27
- return targetTimeFrameInWeeks < 1 ? '< 1 week' : `${Math.ceil(targetTimeFrameInWeeks)} ${pluralize('week', targetTimeFrameInWeeks)}`;
28
- };
29
- export const formatContentItemTypeTitle = type => {
30
- return type === 'kanban_project' ? 'Kanban project' : type === 'external_resource' ? 'External resource' : capitalize(type || '');
31
- };
32
- export const formatContainerTimeToCompleteText = (containerTimeToComplete, containerTitle) => {
33
- const containerTime = containerTimeToComplete || 1;
34
- const timeToComplete = Math.ceil(containerTime);
35
- const containerTimeDuration = containerTime <= 1 ? 'hour' : 'hours';
36
- const formattedTime = containerTime < 1 ? `< ${timeToComplete}` : timeToComplete;
37
- return `Time remaining for ${containerTitle || 'Course'}: ${formattedTime} ${containerTimeDuration}`;
38
- };
39
- export const formatContainerType = containerType => {
40
- return containerType === 'Track' ? 'Course' : containerType;
41
- };
42
- export const getContentItemsToShow = (contentItems, showMoreContentItems) => {
43
- const maxDefaultContentItemsToShow = contentItems.slice(0, maxContentItemsToShow);
44
- return showMoreContentItems ? contentItems : maxDefaultContentItemsToShow;
45
- };
46
- const getFormInputRangeValues = isSessionLengthInput => {
47
- const {
48
- sessionLength,
49
- sessionsPerWeek
50
- } = studyPlanIncrementValues;
51
- const maxInputValue = isSessionLengthInput ? 8 : 7;
52
- const minAndStepInputValue = isSessionLengthInput ? sessionLength : sessionsPerWeek;
53
- return {
54
- maxInputValue,
55
- minAndStepInputValue
56
- };
57
- };
58
- export const validateStudyPlanFormInput = (name, value) => {
59
- const parsedValue = parseFloat(value);
60
- const isSessionLengthInput = name === 'sessionLength';
61
- const {
62
- maxInputValue,
63
- minAndStepInputValue
64
- } = getFormInputRangeValues(isSessionLengthInput);
65
- const isValidIncrement = isSessionLengthInput ? parsedValue * 100 % 25 === 0 : parsedValue % 1 === 0;
66
- return {
67
- isAboveMaxValue: parsedValue > maxInputValue,
68
- isBelowMinValue: parsedValue < minAndStepInputValue,
69
- isValidIncrement,
70
- isValidFormInputValue: !(!isValidIncrement || parsedValue > maxInputValue || parsedValue < minAndStepInputValue)
71
- };
72
- };
73
- export const formatFormErrorMessage = (name, value) => {
74
- const isSessionLengthInput = name === 'sessionLength';
75
- const {
76
- isAboveMaxValue,
77
- isBelowMinValue
78
- } = validateStudyPlanFormInput(name, value);
79
- const {
80
- maxInputValue,
81
- minAndStepInputValue
82
- } = getFormInputRangeValues(isSessionLengthInput);
83
- const minOrMaxErrorMessage = isSessionLengthInput ? `Enter minimum ${minAndStepInputValue} to maximum ${maxInputValue} hours` : `Enter minimum ${minAndStepInputValue} day, maximum ${maxInputValue} days`;
84
- const isMinOrMaxError = isAboveMaxValue || isBelowMinValue;
85
- return !isSessionLengthInput ? minOrMaxErrorMessage : isMinOrMaxError ? minOrMaxErrorMessage : `Adjust time in spans of ${minAndStepInputValue} hours (15 minutes).`;
86
- };
87
- export const calculateTotalContentItemProgress = contentItems => {
88
- if (!contentItems || contentItems?.length === 0) return 0;
89
- const completedContentItems = contentItems?.filter(contentItem => contentItem?.progressV2?.completed) || [];
90
- const completionPercentage = completedContentItems.length / contentItems.length * 100;
91
- return Math.floor(completionPercentage);
92
- };
93
- const defaultSessionSlugs = {
94
- moduleSlug: '',
95
- trackSlug: '',
96
- pathSlug: ''
97
- };
98
- export const getSessionContainerSlugs = (contentItemId, sessionContentItems) => {
99
- if (!sessionContentItems) return defaultSessionSlugs;
100
- const contentItemContainerData = sessionContentItems.find(item => item.contentItemId === contentItemId);
101
- return contentItemContainerData ? {
102
- moduleSlug: contentItemContainerData?.moduleSlug,
103
- trackSlug: contentItemContainerData?.trackSlug,
104
- pathSlug: contentItemContainerData?.pathSlug
105
- } : defaultSessionSlugs;
106
- };
107
- const withLECourseRedirect = (path, redirectSlug) => {
108
- if (!redirectSlug) return path;
109
- return `${path}?course_redirect=${redirectSlug}`;
110
- };
111
- export const contentItemResumePath = function (courseSlug, contentItem, redirectSlug) {
112
- let anon = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : false;
113
- if (!contentItem || !contentItem.slug || !contentItem.type) return `/courses/${courseSlug}`;
114
- const resumePath = anon ? '' : '/resume';
115
- if (contentItem.type === 'lesson') {
116
- return withLECourseRedirect(`/courses/${courseSlug}/lessons/${contentItem.slug}${resumePath}`, redirectSlug);
117
- }
118
- return withLECourseRedirect(`/courses/${courseSlug}/${getContentItemTypeRoutePart(contentItem.type)}/${contentItem.slug}`, redirectSlug);
119
- };
120
- export const createContentItemHref = (containerType, contentItem, contentItemSlug, pathSlug, trackSlug, moduleSlug) => {
121
- const isCourse = containerType === 'track';
122
- if (!isCourse && pathSlug) {
123
- return createResumeUrlPath({
124
- pathSlug,
125
- trackSlug,
126
- moduleSlug,
127
- contentItemType: contentItem?.type,
128
- contentItemSlug
129
- });
130
- }
131
- if (isCourse && trackSlug) {
132
- return contentItemResumePath(trackSlug, contentItem);
133
- }
134
- return undefined;
135
- };
136
- export const formatContentItemTimeToComplete = (timeToCompleteInMinutes, isContentItemTimeToComplete) => {
137
- const moduleTTCHours = timeToCompleteInMinutes / minutesInHour;
138
- const moduleTTCMinutes = timeToCompleteInMinutes % minutesInHour;
139
- if (moduleTTCHours < 1 && moduleTTCMinutes < 1) {
140
- return '<1 min';
141
- }
142
- const formatedTime = formatDuration({
143
- hours: Math.trunc(moduleTTCHours),
144
- minutes: Math.trunc(moduleTTCMinutes)
145
- });
146
- return isContentItemTimeToComplete ? formatedTime.replace(/([minute]+?)(s\b|\b)/, 'min').replace(/([hour]+?)(s\b|\b)/, 'h') : formatedTime;
147
- };
148
- export const formatStudyPlanSummaryText = (sessionLength, sessionsPerWeek, targetTimeFrameText) => {
149
- const sessionsPerWeekText = `Study ${sessionsPerWeek} ${pluralize('day', sessionsPerWeek)} a week `;
150
- const formattedTimeToComplete = formatContentItemTimeToComplete(sessionLength * 60);
151
- const sessionLengthText = `for ${formattedTimeToComplete} each time `;
152
- const targetFinishTime = `- finish in ${targetTimeFrameText}!`;
153
- return `${sessionsPerWeekText}${sessionLengthText}${targetFinishTime}`;
154
- };
155
- export const formatStudyPlanText = (sessionLength, sessionsPerWeek) => {
156
- const daysPerWeekText = `${sessionsPerWeek} ${pluralize('day', sessionsPerWeek)} per week`;
157
- const formattedTimeToComplete = formatContentItemTimeToComplete(sessionLength);
158
- const timesPerDayText = `${formattedTimeToComplete} per day`;
159
- return `${daysPerWeekText}, ${timesPerDayText}`;
160
- };
161
- export const hoverBackgroundTransition = transitionConcat(['background-color', 'box-shadow'], 'fast', 'ease-in');
162
- export const getShouldDisplayNewBadge = () => {
163
- const newBadgeExpireDate = Date.parse('2025-01-14');
164
- return Date.now() - newBadgeExpireDate <= 0;
165
- };
@@ -1,8 +0,0 @@
1
- export * from './helpers';
2
- export * from './StudyPlanModal';
3
- export * from './StudyPlanDeleteDialog';
4
- export * from './SuggestedContentItemsSectionHeader';
5
- export * from './ContentItemDetail';
6
- export * from './ShowMoreContentItemsButton';
7
- export * from './CreateStudyPlanSectionContent';
8
- export * from './StudyPlanDescription';
@@ -1,8 +0,0 @@
1
- export * from './helpers';
2
- export * from './StudyPlanModal';
3
- export * from './StudyPlanDeleteDialog';
4
- export * from './SuggestedContentItemsSectionHeader';
5
- export * from './ContentItemDetail';
6
- export * from './ShowMoreContentItemsButton';
7
- export * from './CreateStudyPlanSectionContent';
8
- export * from './StudyPlanDescription';