@openedx/frontend-base 2.0.0-alpha.1 → 2.0.0-alpha.3
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.
- package/dist/runtime/config/index.js +2 -0
- package/dist/runtime/config/index.js.map +1 -1
- package/dist/runtime/i18n/index.d.ts +6 -8
- package/dist/runtime/i18n/index.js +6 -8
- package/dist/runtime/i18n/index.js.map +1 -1
- package/dist/runtime/i18n/lib.d.ts +38 -8
- package/dist/runtime/i18n/lib.js +88 -22
- package/dist/runtime/i18n/lib.js.map +1 -1
- package/dist/runtime/i18n/updateSiteLanguage.d.ts +17 -0
- package/dist/runtime/i18n/updateSiteLanguage.js +91 -0
- package/dist/runtime/i18n/updateSiteLanguage.js.map +1 -0
- package/dist/runtime/index.d.ts +1 -1
- package/dist/runtime/index.js +1 -1
- package/dist/runtime/index.js.map +1 -1
- package/dist/runtime/logging/types.js.map +1 -1
- package/dist/runtime/react/CombinedAppProvider.js.map +1 -1
- package/dist/runtime/react/CurrentAppContext.js.map +1 -1
- package/dist/runtime/react/CurrentAppProvider.js.map +1 -1
- package/dist/runtime/react/SiteContext.js.map +1 -1
- package/dist/runtime/react/SiteProvider.js.map +1 -1
- package/dist/runtime/react/hooks/theme/useThemeVariants.js.map +1 -1
- package/dist/runtime/slots/Slot.js.map +1 -1
- package/dist/runtime/slots/SlotContext.js.map +1 -1
- package/dist/runtime/slots/layout/types.js.map +1 -1
- package/dist/runtime/slots/types.js.map +1 -1
- package/dist/runtime/slots/widget/WidgetContext.js.map +1 -1
- package/dist/runtime/slots/widget/WidgetProvider.js.map +1 -1
- package/dist/runtime/slots/widget/iframe/IFrameContentWrapper.js.map +1 -1
- package/dist/runtime/slots/widget/iframe/IFrameWidget.js.map +1 -1
- package/dist/runtime/slots/widget/iframe/hooks.js.map +1 -1
- package/dist/runtime/slots/widget/iframe/types.js.map +1 -1
- package/dist/runtime/slots/widget/types.js.map +1 -1
- package/dist/runtime/testing/initializeMockApp.js.map +1 -1
- package/dist/shell/Logo.js.map +1 -1
- package/dist/shell/dev/devHeader/BarContext.js.map +1 -1
- package/dist/shell/dev/devHeader/BarProvider.js.map +1 -1
- package/dist/shell/dev/devHeader/FooContext.js.map +1 -1
- package/dist/shell/dev/devHeader/FooProvider.js.map +1 -1
- package/dist/shell/dev/slotShowcase/SlotShowcasePage.js.map +1 -1
- package/dist/shell/dev/slotShowcase/app.js.map +1 -1
- package/dist/shell/footer/CopyrightNotice.js.map +1 -1
- package/dist/shell/footer/LanguageMenu.js +36 -6
- package/dist/shell/footer/LanguageMenu.js.map +1 -1
- package/dist/shell/footer/LanguageMenuItem.d.ts +4 -1
- package/dist/shell/footer/LanguageMenuItem.js +4 -5
- package/dist/shell/footer/LanguageMenuItem.js.map +1 -1
- package/dist/shell/footer/messages.d.ts +8 -0
- package/dist/shell/footer/messages.js +10 -0
- package/dist/shell/footer/messages.js.map +1 -0
- package/dist/shell/header/AuthenticatedMenu.js.map +1 -1
- package/dist/shell/header/HelpButton.js.map +1 -1
- package/dist/shell/header/anonymous-menu/AnonymousMenu.js.map +1 -1
- package/dist/shell/header/course-bar/data/service.js.map +1 -1
- package/dist/shell/header/course-bar/masquerade/StudioLink.js.map +1 -1
- package/dist/shell/header/course-bar/masquerade/data/api.js.map +1 -1
- package/dist/shell/header/course-bar/masquerade/hooks.js.map +1 -1
- package/dist/shell/header/course-bar/masquerade/masquerade-widget/MasqueradeUserNameInput.js.map +1 -1
- package/dist/shell/header/course-bar/masquerade/masquerade-widget/MasqueradeWidgetOption.js.map +1 -1
- package/dist/shell/header/course-bar/navigation/CourseTabsNavigation.js.map +1 -1
- package/dist/shell/header/helpButtonSlotOperation.js.map +1 -1
- package/dist/shell/menus/LinkMenuItem.js.map +1 -1
- package/dist/shell/menus/NavDropdownMenuSlot.js.map +1 -1
- package/dist/shell/menus/ProfileLinkMenuItem.js.map +1 -1
- package/dist/tools/eslint/base.eslint.config.js +2 -2
- package/dist/types.d.ts +2 -0
- package/dist/types.js.map +1 -1
- package/package.json +1 -1
- package/dist/shell/footer/data/api.d.ts +0 -1
- package/dist/shell/footer/data/api.js +0 -45
- package/dist/shell/footer/data/api.js.map +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"NavDropdownMenuSlot.js","sourceRoot":"","sources":["../../../shell/menus/NavDropdownMenuSlot.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAC/C,OAAO,EAAE,OAAO,EAAE,MAAM,YAAY,CAAC;AAErC,OAAO,EAAE,qBAAqB,EAAE,eAAe,EAAE,MAAM,eAAe,CAAC;AAIvE,OAAO,EACL,YAAY,EACb,MAAM,cAAc,CAAC;AAOtB,MAAM,CAAC,OAAO,UAAU,gBAAgB,CAAC,EAAE,EAAE,EAAE,KAAK,EAAyB;;IAC3E,MAAM,IAAI,GAAG,OAAO,EAAE,CAAC;IACvB,MAAM,OAAO,GAAG,qBAAqB,CAAC,EAAE,CAAC,CAAC;IAC1C,MAAM,OAAO,GAAG,eAAe,CAAC,EAAE,CAAC,CAAC;IAEpC,MAAM,UAAU,GAAG,YAAY,CAAC,MAAA,OAAO,CAAC,KAAK,mCAAI,KAAK,EAAE,IAAI,CAAC,CAAC;IAE9D,OAAO,CACL,KAAC,WAAW,IAAU,KAAK,EAAE,UAAU,EAAE,EAAE,EAAE,GAAG,EAAE,WAAW,YAC1D,OAAO,IADQ,EAAE,CAEN,CACf,CAAC;AACJ,CAAC","sourcesContent":["import { NavDropdown } from '@openedx/paragon';\nimport { useIntl } from 'react-intl';\n\nimport { useLayoutOptionsForId, useWidgetsForId } from '../../runtime';\nimport {\n MenuItemName\n} from '../../types';\nimport {\n getItemLabel\n} from './data/utils';\n\ninterface DropdownMenuSlotProps {\n id: string
|
|
1
|
+
{"version":3,"file":"NavDropdownMenuSlot.js","sourceRoot":"","sources":["../../../shell/menus/NavDropdownMenuSlot.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAC/C,OAAO,EAAE,OAAO,EAAE,MAAM,YAAY,CAAC;AAErC,OAAO,EAAE,qBAAqB,EAAE,eAAe,EAAE,MAAM,eAAe,CAAC;AAIvE,OAAO,EACL,YAAY,EACb,MAAM,cAAc,CAAC;AAOtB,MAAM,CAAC,OAAO,UAAU,gBAAgB,CAAC,EAAE,EAAE,EAAE,KAAK,EAAyB;;IAC3E,MAAM,IAAI,GAAG,OAAO,EAAE,CAAC;IACvB,MAAM,OAAO,GAAG,qBAAqB,CAAC,EAAE,CAAC,CAAC;IAC1C,MAAM,OAAO,GAAG,eAAe,CAAC,EAAE,CAAC,CAAC;IAEpC,MAAM,UAAU,GAAG,YAAY,CAAC,MAAA,OAAO,CAAC,KAAK,mCAAI,KAAK,EAAE,IAAI,CAAC,CAAC;IAE9D,OAAO,CACL,KAAC,WAAW,IAAU,KAAK,EAAE,UAAU,EAAE,EAAE,EAAE,GAAG,EAAE,WAAW,YAC1D,OAAO,IADQ,EAAE,CAEN,CACf,CAAC;AACJ,CAAC","sourcesContent":["import { NavDropdown } from '@openedx/paragon';\nimport { useIntl } from 'react-intl';\n\nimport { useLayoutOptionsForId, useWidgetsForId } from '../../runtime';\nimport {\n MenuItemName\n} from '../../types';\nimport {\n getItemLabel\n} from './data/utils';\n\ninterface DropdownMenuSlotProps {\n id: string;\n label: MenuItemName;\n}\n\nexport default function DropdownMenuSlot({ id, label }: DropdownMenuSlotProps) {\n const intl = useIntl();\n const options = useLayoutOptionsForId(id);\n const widgets = useWidgetsForId(id);\n\n const finalLabel = getItemLabel(options.label ?? label, intl);\n\n return (\n <NavDropdown key={id} title={finalLabel} id={`${id}-dropdown`}>\n {widgets}\n </NavDropdown>\n );\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ProfileLinkMenuItem.js","sourceRoot":"","sources":["../../../shell/menus/ProfileLinkMenuItem.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAE,oBAAoB,EAAE,MAAM,eAAe,CAAC;AACrD,OAAO,EAAE,iBAAiB,EAAE,MAAM,uBAAuB,CAAC;AAG1D,OAAO,YAAY,MAAM,gBAAgB,CAAC;AAQ1C,MAAM,CAAC,OAAO,UAAU,mBAAmB,CAAC,EAAE,KAAK,EAAE,IAAI,EAAE,OAAO,GAAG,WAAW,EAA4B;IAC1G,MAAM,iBAAiB,GAAG,oBAAoB,EAAE,CAAC;IACjD,IAAI,OAAO,GAAG,iBAAiB,CAAC,IAAI,CAAC,CAAC;IAEtC,IAAI,CAAC,OAAO;QACV,OAAO,IAAI,CAAC;IAEd,IAAI,OAAO,CAAC,QAAQ,CAAC,GAAG,CAAC,EAAE,CAAC;QAC1B,OAAO,GAAG,OAAO,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC;IACjC,CAAC;IAED,MAAM,GAAG,GAAG,GAAG,OAAO,MAAM,iBAAiB,aAAjB,iBAAiB,uBAAjB,iBAAiB,CAAE,QAAQ,EAAE,CAAC;IAE1D,OAAO,CACL,KAAC,YAAY,IACX,KAAK,EAAE,KAAK,EACZ,GAAG,EAAE,GAAG,EACR,OAAO,EAAE,OAAO,GAChB,CACH,CAAC;AACJ,CAAC","sourcesContent":["import { useAuthenticatedUser } from '../../runtime';\nimport { getUrlByRouteRole } from '../../runtime/routing';\nimport { MenuItemName } from '../../types';\n\nimport LinkMenuItem from './LinkMenuItem';\n\ninterface ProfileLinkMenuItemProps {\n label: MenuItemName
|
|
1
|
+
{"version":3,"file":"ProfileLinkMenuItem.js","sourceRoot":"","sources":["../../../shell/menus/ProfileLinkMenuItem.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAE,oBAAoB,EAAE,MAAM,eAAe,CAAC;AACrD,OAAO,EAAE,iBAAiB,EAAE,MAAM,uBAAuB,CAAC;AAG1D,OAAO,YAAY,MAAM,gBAAgB,CAAC;AAQ1C,MAAM,CAAC,OAAO,UAAU,mBAAmB,CAAC,EAAE,KAAK,EAAE,IAAI,EAAE,OAAO,GAAG,WAAW,EAA4B;IAC1G,MAAM,iBAAiB,GAAG,oBAAoB,EAAE,CAAC;IACjD,IAAI,OAAO,GAAG,iBAAiB,CAAC,IAAI,CAAC,CAAC;IAEtC,IAAI,CAAC,OAAO;QACV,OAAO,IAAI,CAAC;IAEd,IAAI,OAAO,CAAC,QAAQ,CAAC,GAAG,CAAC,EAAE,CAAC;QAC1B,OAAO,GAAG,OAAO,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC;IACjC,CAAC;IAED,MAAM,GAAG,GAAG,GAAG,OAAO,MAAM,iBAAiB,aAAjB,iBAAiB,uBAAjB,iBAAiB,CAAE,QAAQ,EAAE,CAAC;IAE1D,OAAO,CACL,KAAC,YAAY,IACX,KAAK,EAAE,KAAK,EACZ,GAAG,EAAE,GAAG,EACR,OAAO,EAAE,OAAO,GAChB,CACH,CAAC;AACJ,CAAC","sourcesContent":["import { useAuthenticatedUser } from '../../runtime';\nimport { getUrlByRouteRole } from '../../runtime/routing';\nimport { MenuItemName } from '../../types';\n\nimport LinkMenuItem from './LinkMenuItem';\n\ninterface ProfileLinkMenuItemProps {\n label: MenuItemName;\n role: string;\n variant?: 'hyperlink' | 'navLink' | 'navDropdownItem' | 'dropdownItem';\n}\n\nexport default function ProfileLinkMenuItem({ label, role, variant = 'hyperlink' }: ProfileLinkMenuItemProps) {\n const authenticatedUser = useAuthenticatedUser();\n let baseUrl = getUrlByRouteRole(role);\n\n if (!baseUrl)\n return null;\n\n if (baseUrl.endsWith('/')) {\n baseUrl = baseUrl.slice(0, -1);\n }\n\n const url = `${baseUrl}/u/${authenticatedUser?.username}`;\n\n return (\n <LinkMenuItem\n label={label}\n url={url}\n variant={variant}\n />\n );\n}\n"]}
|
|
@@ -93,11 +93,11 @@ module.exports = tseslint.config(eslint.configs.recommended, ...tseslint.configs
|
|
|
93
93
|
'@stylistic/brace-style': ['error', '1tbs'],
|
|
94
94
|
'@stylistic/member-delimiter-style': ['error', {
|
|
95
95
|
multiline: {
|
|
96
|
-
delimiter: '
|
|
96
|
+
delimiter: 'semi',
|
|
97
97
|
requireLast: true,
|
|
98
98
|
},
|
|
99
99
|
singleline: {
|
|
100
|
-
delimiter: '
|
|
100
|
+
delimiter: 'semi',
|
|
101
101
|
requireLast: false,
|
|
102
102
|
}
|
|
103
103
|
}],
|
package/dist/types.d.ts
CHANGED
|
@@ -54,6 +54,8 @@ export interface OptionalSiteConfig {
|
|
|
54
54
|
commonAppConfig: AppConfig;
|
|
55
55
|
headerLogoImageUrl: string;
|
|
56
56
|
theme: Theme;
|
|
57
|
+
defaultLanguage: string;
|
|
58
|
+
supportedLanguages: string[];
|
|
57
59
|
accessTokenCookieName: string;
|
|
58
60
|
languagePreferenceCookieName: string;
|
|
59
61
|
userInfoCookieName: string;
|
package/dist/types.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.js","sourceRoot":"","sources":["../types.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../types.ts"],"names":[],"mappings":"AAiIA,MAAM,CAAN,IAAY,gBAIX;AAJD,WAAY,gBAAgB;IAC1B,6CAAyB,CAAA;IACzB,+CAA2B,CAAA;IAC3B,iCAAa,CAAA;AACf,CAAC,EAJW,gBAAgB,KAAhB,gBAAgB,QAI3B","sourcesContent":["import { FC, ReactElement, ReactNode } from 'react';\nimport { MessageDescriptor } from 'react-intl';\nimport { RouteObject } from 'react-router';\nimport { SlotOperation } from './runtime/slots/types';\n\n// Apps\n\nexport interface ExternalRoute {\n role: string;\n url: string;\n}\n\nexport type RoleRouteObject = RouteObject & {\n handle?: {\n /**\n * Route roles identify the purpose(s) a route fulfills in the site.\n */\n roles?: string[];\n };\n};\n\nexport type AppConfig = Record<string, unknown>;\n\nexport type AppProvider = FC<{ children?: ReactNode }>;\n\nexport interface App {\n appId: string;\n routes?: RoleRouteObject[];\n providers?: AppProvider[];\n slots?: SlotOperation[];\n externalScripts?: ExternalScriptLoaderClass[];\n config?: AppConfig;\n provides?: Record<string, unknown>;\n}\n\n// External Scripts\n\nexport interface ExternalScriptLoader {\n loadScript(): void;\n}\n\nexport type ExternalScriptLoaderClass = new (data: { config: AppConfig }) => ExternalScriptLoader;\n\n// Site Config\n\nexport interface RequiredSiteConfig {\n siteId: string;\n siteName: string;\n baseUrl: string;\n\n // Backends\n lmsBaseUrl: string;\n\n // Frontends\n loginUrl: string;\n logoutUrl: string;\n}\n\nexport type LocalizedMessages = Record<string, Record<string, string>>;\nexport type SiteMessages = LocalizedMessages[];\n\nexport interface OptionalSiteConfig {\n // Site environment\n environment: EnvironmentTypes;\n\n // Backends\n cmsBaseUrl: string;\n\n // Apps, routes, and URLs\n apps: App[];\n basename: string;\n externalRoutes: ExternalRoute[];\n externalLinkUrlOverrides: string[];\n runtimeConfigJsonUrl: string | null;\n commonAppConfig: AppConfig;\n headerLogoImageUrl: string;\n\n // Theme\n theme: Theme;\n\n // i18n\n defaultLanguage: string;\n supportedLanguages: string[];\n\n // Cookies\n accessTokenCookieName: string;\n languagePreferenceCookieName: string;\n userInfoCookieName: string;\n\n // Paths\n csrfTokenApiPath: string;\n refreshAccessTokenApiPath: string;\n\n // Logging\n ignoredErrorRegex: RegExp | null;\n\n // Analytics\n segmentKey: string | null;\n}\n\nexport type SiteConfig = RequiredSiteConfig & Partial<OptionalSiteConfig>;\n\nexport interface ThemeVariant {\n url: string;\n}\n\nexport interface ThemeDefaults {\n light?: string;\n dark?: string;\n}\n\nexport type ThemeVariants = Record<string, ThemeVariant>;\n\nexport interface Theme {\n core?: ThemeVariant;\n defaults?: ThemeDefaults;\n variants?: ThemeVariants;\n}\n\nexport interface User {\n administrator: boolean;\n email: string;\n name: string;\n roles: string[];\n userId: number;\n username: string;\n avatar: string;\n}\n\nexport enum EnvironmentTypes {\n PRODUCTION = 'production',\n DEVELOPMENT = 'development',\n TEST = 'test',\n}\n\n// Menu Items\n\nexport type MenuItemName = string | MessageDescriptor | ReactElement;\n"]}
|
package/package.json
CHANGED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare function updateSiteLanguage(locale: string): Promise<void>;
|
|
@@ -1,45 +0,0 @@
|
|
|
1
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
-
});
|
|
9
|
-
};
|
|
10
|
-
import { getAuthenticatedHttpClient, getAuthenticatedUser, getSiteConfig, updateLocale } from '../../../runtime';
|
|
11
|
-
export function updateSiteLanguage(locale) {
|
|
12
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
13
|
-
const user = getAuthenticatedUser();
|
|
14
|
-
if (user !== null) {
|
|
15
|
-
const { username } = getAuthenticatedUser();
|
|
16
|
-
yield patchUserPreferences(username, locale);
|
|
17
|
-
}
|
|
18
|
-
yield postSetlang(locale);
|
|
19
|
-
updateLocale();
|
|
20
|
-
});
|
|
21
|
-
}
|
|
22
|
-
function patchUserPreferences(username, locale) {
|
|
23
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
24
|
-
yield getAuthenticatedHttpClient().patch(`${getSiteConfig().lmsBaseUrl}/api/user/v1/preferences/${username}`, {
|
|
25
|
-
'pref-lang': locale
|
|
26
|
-
}, {
|
|
27
|
-
headers: {
|
|
28
|
-
'Content-Type': 'application/merge-patch+json'
|
|
29
|
-
},
|
|
30
|
-
});
|
|
31
|
-
});
|
|
32
|
-
}
|
|
33
|
-
function postSetlang(locale) {
|
|
34
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
35
|
-
const formData = new FormData();
|
|
36
|
-
formData.append('language', locale);
|
|
37
|
-
yield getAuthenticatedHttpClient().post(`${getSiteConfig().lmsBaseUrl}/i18n/setlang/`, formData, {
|
|
38
|
-
headers: {
|
|
39
|
-
Accept: 'application/json',
|
|
40
|
-
'X-Requested-With': 'XMLHttpRequest',
|
|
41
|
-
},
|
|
42
|
-
});
|
|
43
|
-
});
|
|
44
|
-
}
|
|
45
|
-
//# sourceMappingURL=api.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"api.js","sourceRoot":"","sources":["../../../../shell/footer/data/api.ts"],"names":[],"mappings":";;;;;;;;;AAAA,OAAO,EACL,0BAA0B,EAC1B,oBAAoB,EACpB,aAAa,EACb,YAAY,EACb,MAAM,kBAAkB,CAAC;AAE1B,MAAM,UAAgB,kBAAkB,CAAC,MAAc;;QACrD,MAAM,IAAI,GAAG,oBAAoB,EAAE,CAAC;QAEpC,IAAI,IAAI,KAAK,IAAI,EAAE,CAAC;YAClB,MAAM,EAAE,QAAQ,EAAE,GAAG,oBAAoB,EAAE,CAAC;YAC5C,MAAM,oBAAoB,CAAC,QAAQ,EAAE,MAAM,CAAC,CAAC;QAC/C,CAAC;QACD,MAAM,WAAW,CAAC,MAAM,CAAC,CAAC;QAE1B,YAAY,EAAE,CAAC;IACjB,CAAC;CAAA;AAED,SAAe,oBAAoB,CAAC,QAAgB,EAAE,MAAc;;QAClE,MAAM,0BAA0B,EAAE,CAAC,KAAK,CACtC,GAAG,aAAa,EAAE,CAAC,UAAU,4BAA4B,QAAQ,EAAE,EACnE;YACE,WAAW,EAAE,MAAM;SACpB,EACD;YACE,OAAO,EAAE;gBACP,cAAc,EAAE,8BAA8B;aAC/C;SACF,CACF,CAAC;IACJ,CAAC;CAAA;AAED,SAAe,WAAW,CAAC,MAAc;;QACvC,MAAM,QAAQ,GAAG,IAAI,QAAQ,EAAE,CAAC;QAChC,QAAQ,CAAC,MAAM,CAAC,UAAU,EAAE,MAAM,CAAC,CAAC;QAEpC,MAAM,0BAA0B,EAAE,CAAC,IAAI,CACrC,GAAG,aAAa,EAAE,CAAC,UAAU,gBAAgB,EAC7C,QAAQ,EACR;YACE,OAAO,EAAE;gBACP,MAAM,EAAE,kBAAkB;gBAC1B,kBAAkB,EAAE,gBAAgB;aACrC;SACF,CACF,CAAC;IACJ,CAAC;CAAA","sourcesContent":["import {\n getAuthenticatedHttpClient,\n getAuthenticatedUser,\n getSiteConfig,\n updateLocale\n} from '../../../runtime';\n\nexport async function updateSiteLanguage(locale: string) {\n const user = getAuthenticatedUser();\n\n if (user !== null) {\n const { username } = getAuthenticatedUser();\n await patchUserPreferences(username, locale);\n }\n await postSetlang(locale);\n\n updateLocale();\n}\n\nasync function patchUserPreferences(username: string, locale: string) {\n await getAuthenticatedHttpClient().patch(\n `${getSiteConfig().lmsBaseUrl}/api/user/v1/preferences/${username}`,\n {\n 'pref-lang': locale\n },\n {\n headers: {\n 'Content-Type': 'application/merge-patch+json'\n },\n }\n );\n}\n\nasync function postSetlang(locale: string) {\n const formData = new FormData();\n formData.append('language', locale);\n\n await getAuthenticatedHttpClient().post(\n `${getSiteConfig().lmsBaseUrl}/i18n/setlang/`,\n formData,\n {\n headers: {\n Accept: 'application/json',\n 'X-Requested-With': 'XMLHttpRequest',\n },\n }\n );\n}\n"]}
|