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

SEO Localization behaviour overhaul #408

Merged
merged 3 commits into from
Aug 14, 2023
Merged
Show file tree
Hide file tree
Changes from all 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
3 changes: 2 additions & 1 deletion components/Atoms/GroupTypes.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { Text, Image, useTheme, mergeStyleSets } from '@fluentui/react';
import { Container } from "react-bootstrap";
import { semibold } from "services/Fonts";
import { CSSProperties } from 'react';
import GroupType from "models/GroupType";
import GroupTypesData from '../../data/GroupTypes.json';
import LocalizationService from 'services/LocalizationService';
Expand All @@ -17,7 +18,7 @@ const GroupTypes = (props: Props) => {

const groupTypes: Array<GroupType> = props.page === "courses" ? GroupTypesData.filter(g => g.name['it'] !== "Associazioni studentesche") : GroupTypesData;

const groupTypesStyle = {
const groupTypesStyle: CSSProperties = {
justifyContent: 'center',
gap: 12
};
Expand Down
7 changes: 4 additions & 3 deletions components/Atoms/ItemsGroup.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { mergeStyleSets, useTheme, Text, Icon } from "@fluentui/react";
import { CSSProperties } from "react";
import { semibold } from "services/Fonts";
import LocalizationService from "services/LocalizationService";

Expand Down Expand Up @@ -37,15 +38,15 @@ const ItemsGroup = (props: Props) => {
},
});

const itemsStyle = {
const itemsStyle: CSSProperties = {
justifyContent: 'center',
gap: 8
};

return (
<div className="d-flex flex-wrap flex-row" style={itemsStyle}>
{props.items.map((item: Item) => (
<a href={item.href} className="text-decoration-none">
{props.items.map((item: Item, i: number) => (
<a href={item.href} className="text-decoration-none" key={i}>
<div className={itemStyle.root + " text-center align-items-center justify-content-center"}>
<div className="d-flex align-items-center justify-content-center">
<Icon iconName={item.iconName} style={{ color: theme.palette.themeDark, fontSize: 24 }} />
Expand Down
88 changes: 88 additions & 0 deletions components/Atoms/LocalizationChangeDialog.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
import { Text, useTheme, DialogType, Dialog, DialogFooter, PrimaryButton, DefaultButton } from '@fluentui/react';
import { semibold } from '../../services/Fonts';
import { useState, useEffect, useContext } from 'react';
import { useCookies } from 'react-cookie';
import { addDays } from 'services/Utils';
import Lottie from 'react-lottie';
import * as lottieLocalization from './Lottie/PSa9MuR7v2.json';
import GlobalContext from 'services/GlobalContext';

const LocalizationChangeDialog = () => {
var theme = useTheme();
const [cookies, setCookie] = useCookies();
const date: Date = addDays(new Date(), 90);

const [isDialogOpen, setIsDialogOpen] = useState<boolean>(false);

/* Dialog properties */
const dialogContentProps = {
type: DialogType.largeHeader,
title: "You don't speak Italian?"
};
const modelProps = { isBlocking: false };

const localizationLottieOptions = {
loop: true,
autoplay: true,
animationData: lottieLocalization,
rendererSettings: {
preserveAspectRatio: 'xMidYMid slice'
}
};

const { changeLanguage } = useContext(GlobalContext);

const setEnglishLocale = () => {
changeLanguage("en");
setIsDialogOpen(false);
};

useEffect(() => {
const acceptLanguage = window.navigator.languages[0] ?? navigator.language;

if (cookies.isFirstVisit === undefined && acceptLanguage !== "it") {
setIsDialogOpen(true);
}

setCookie("isFirstVisit", false, { path: "/", expires: date });
}, []);

return (
<Dialog
hidden={!isDialogOpen}
onDismiss={() => setIsDialogOpen(false)}
dialogContentProps={dialogContentProps}
modalProps={modelProps}
>
<div className="d-flex flex-column" style={{ gap: 20 }}>

<Text variant="medium" styles={semibold}>
Looks like your browser is not set on italian. Would you like to switch to English language?
</Text>

<div style={{ display: 'flex', justifyContent: 'center' }}>
{/* @ts-ignore */}
<Lottie options={localizationLottieOptions}
height={130}
width={185}
isClickToPauseDisabled={true}
style={{ cursor: 'default' }}
/>
</div>

<div className="p-3 d-flex flex-column text-center" style={{ backgroundColor: theme.palette.neutralLighter, borderRadius: 8, gap: 10 }}>
<Text variant="medium">
We'll remember your choice 😎
</Text>
</div>
</div>

<DialogFooter>
<DefaultButton onClick={() => setIsDialogOpen(false)} text="Rimani in italiano" style={{ padding: 20 }} />
<PrimaryButton onClick={setEnglishLocale} text="Switch to english" style={{ padding: 20 }} />
</DialogFooter>
</Dialog>
)
};

export default LocalizationChangeDialog;
1 change: 1 addition & 0 deletions components/Atoms/Lottie/PSa9MuR7v2.json

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions components/Atoms/PrivacyPolicyDialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ const PrivacyPolicyDialog = () => {
<PrimaryButton onClick={acceptPrivacyPolicy} text={locale?.privacyPolicy.accept} disabled={!isChecked} style={{ padding: 20 }} />
</DialogFooter>
</Dialog>
)
}
);
};

export default PrivacyPolicyDialog;
4 changes: 2 additions & 2 deletions components/Courses/GroupItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { IContextualMenuProps, IIconProps } from '@fluentui/react';
import { DefaultButton, PrimaryButton } from '@fluentui/react/lib/Button';
import { buildProfessorName, preventDefault, preventVisibleHref, redirectToLink } from '../../services/Utils';
import { CourseDegree } from '../../models/Models';
import { useContext } from 'react';
import { CSSProperties, useContext } from 'react';
import Chip from '../Atoms/Chip';
import LocalizationService from "../../services/LocalizationService";
import JsxParser from 'react-jsx-parser';
Expand Down Expand Up @@ -117,7 +117,7 @@ const CourseItem = (props: Props) => {

/* Professor inizialization */
if (data.course.professor !== null) {
const style = { display: 'flex', gap: 5, alignItems: 'center' };
const style: CSSProperties = { display: 'flex', gap: 5, alignItems: 'center' };
let text = <div style={style}><Icon iconName="UserOptional" /> {buildProfessorName(data.course.professor.first_name, data.course.professor.last_name)}</div>;

if (data.course.professor.url === undefined || data.course.professor.url === null) {
Expand Down
Loading
Loading