Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[MT-5280] Feature - Implement banner on preview newsrooms #93

Merged
merged 5 commits into from
Aug 10, 2022
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .nvmrc
Original file line number Diff line number Diff line change
@@ -1 +1 @@
v16.14.2
v16
3 changes: 3 additions & 0 deletions src/data-fetching/api/PrezlyApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import {
getDefaultLanguage,
getLanguageFromNextLocaleIsoCode,
getLanguageFromStory,
getNotifications,
LocaleObject,
} from '../../intl';
import type { PageProps, ServerSidePageProps } from '../../types';
Expand Down Expand Up @@ -273,6 +274,7 @@ export class PrezlyApi {
// TODO: if no information given for current language, show boilerplate from default language
const companyInformation = getCompanyInformation(languages, locale);

const notifications = getNotifications(languages, locale);
const algoliaSettings = getAlgoliaSettings(request);

return {
Expand All @@ -282,6 +284,7 @@ export class PrezlyApi {
categories,
languages,
localeCode,
notifications,
themePreset,
algoliaSettings,
},
Expand Down
12 changes: 11 additions & 1 deletion src/intl/languages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,17 @@ export function getCompanyInformation(languages: NewsroomLanguageSettings[], loc
}

/**
* Get shortest locale code possible from full locale code
* Get newsroom notifications for the selected locale
*/
export function getNotifications(languages: NewsroomLanguageSettings[], locale: LocaleObject) {
const currentLanguage =
getLanguageByExactLocaleCode(languages, locale) || getDefaultLanguage(languages);

return currentLanguage.notifications;
}

/**
* Get the shortest locale code possible from full locale code
* First: try shorting to neutral language code (there should be no locales with the same language code)
* Then: try shorting to region code (there should be no locales with the same region code)
* Finally: return the original locale code (shorting is not possible)
Expand Down
7 changes: 7 additions & 0 deletions src/newsroom-context/context.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import type {
NewsroomContact,
NewsroomLanguageSettings,
NewsroomThemePreset,
Notification,
} from '@prezly/sdk';
import type { PropsWithChildren } from 'react';
import { createContext, useMemo } from 'react';
Expand Down Expand Up @@ -47,6 +48,10 @@ export interface NewsroomContextType {
* Currently chosen locale
*/
locale: LocaleObject;
/**
* Newsroom user-facing notifications (usually displayed as top-edge banners)
*/
notifications: Notification[];
/**
* Theme settings as set in the Prezly app.
* You need to provide `PREZLY_THEME_UUID` in environment variables in order for the preset to be loaded.
Expand Down Expand Up @@ -78,6 +83,7 @@ export function NewsroomContextProvider({
companyInformation,
languages,
localeCode,
notifications,
themePreset,
algoliaSettings,
children,
Expand All @@ -98,6 +104,7 @@ export function NewsroomContextProvider({
companyInformation,
languages,
locale,
notifications,
themePreset,
algoliaSettings,
}}
Expand Down