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

Fix(Webview): Suppression alerte et affichage directement lors du choix du service #570

Closed
wants to merge 12 commits into from
2 changes: 1 addition & 1 deletion src/components/Global/AnimatedNumber.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ const AnimatedNumber: React.FC<AnimatedNumberProps> = ({
}, contentContainerStyle]}
layout={animPapillon(LinearTransition)}
>
{value.toString().split("").map((n, i) => (
{value.toString().split("").map((n: string, i: number) => (
<Reanimated.View
key={i + "_" + n}
entering={animPapillon(FadeInDown).delay(i * 20 + 20).mass(1).damping(30).stiffness(700)}
Expand Down
48 changes: 36 additions & 12 deletions src/views/login/ServiceSelector.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,20 +9,18 @@ import PapillonShineBubble from "@/components/FirstInstallation/PapillonShineBub
import DuoListPressable from "@/components/FirstInstallation/DuoListPressable";
import ButtonCta from "@/components/FirstInstallation/ButtonCta";
import MaskStars from "@/components/FirstInstallation/MaskStars";
import { useAlert } from "@/providers/AlertProvider";
import { Audio } from "expo-av";
import { useTheme } from "@react-navigation/native";
import GetV6Data from "@/utils/login/GetV6Data";
import { School } from "lucide-react-native";
import { Info, School } from "lucide-react-native";
import { LinearGradient } from "expo-linear-gradient";
import { NativeText } from "@/components/Global/NativeComponents";

const ServiceSelector: Screen<"ServiceSelector"> = ({ navigation }) => {
const theme = useTheme();
const { colors } = theme;
const [sound, setSound] = useState<Audio.Sound | null>(null);

const { showAlert } = useAlert();

type Services = "pronote" | "ed" | "skolengo";
const [service, setService] = useState<Services | null>(null);

Expand Down Expand Up @@ -85,13 +83,6 @@ const ServiceSelector: Screen<"ServiceSelector"> = ({ navigation }) => {
},
];

const UnsupportedAlert = () => {
showAlert({
title: "Service non supporté",
message: "Désolé, ce service n'est pas encore supporté. Réessaye dans une prochaine version."
});
};

useEffect(() => {
const loadSound = async () => {
const { sound } = await Audio.Sound.createAsync(
Expand Down Expand Up @@ -182,7 +173,12 @@ const ServiceSelector: Screen<"ServiceSelector"> = ({ navigation }) => {
padding: 3,
}}
>
{React.cloneElement(srv.icon, { size: 26, strokeWidth: 2.5, color: srv.name === service ? colors.primary : colors.text })}
{React.cloneElement(srv.icon, {
size: 26,
strokeWidth: 2.5,
color:
srv.name === service ? colors.primary : colors.text,
})}
</View>
:
<Image
Expand All @@ -202,6 +198,34 @@ const ServiceSelector: Screen<"ServiceSelector"> = ({ navigation }) => {
</View>

<View style={styles.buttons}>
<View
style={{
flexDirection: "row",
gap: 12,
alignItems: "center",
marginBottom: 9,
marginHorizontal: 9,
}}
>
<Info
size={20}
strokeWidth={2.5}
color={theme.colors.text + "88"}
/>
<NativeText
style={{
flex: 1,
color: theme.colors.text,
opacity: 0.5,
fontSize: 13,
lineHeight: 16,
}}
>
Seuls les comptes élèves sont supportés pour le moment. Se connecter
avec un autre type de compte ne fonctionnera pas et
provoquera des bugs.
</NativeText>
</View>
<ButtonCta
primary
value="Confirmer"
Expand Down
76 changes: 20 additions & 56 deletions src/views/login/pronote/PronoteWebview.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import {
Dimensions,
KeyboardAvoidingView,
Platform,
Alert,
} from "react-native";

import { WebView } from "react-native-webview";
Expand Down Expand Up @@ -33,19 +32,13 @@ import defaultPersonalization from "@/services/pronote/default-personalization";
import extract_pronote_name from "@/utils/format/extract_pronote_name";
import PapillonSpinner from "@/components/Global/PapillonSpinner";
import { animPapillon } from "@/utils/ui/animations";
import { useAlert } from "@/providers/AlertProvider";

const PronoteWebview: Screen<"PronoteWebview"> = ({ route, navigation }) => {
const theme = useTheme();
const { showAlert } = useAlert();

const [, setLoading] = useState(true);
const [, setLoadProgress] = useState(0);
const [showWebView, setShowWebView] = useState(false);
const [loggingIn, setLoggingIn] = useState(false);

const [, setCurrentURL] = useState("");

const [deviceUUID] = useState(uuid());
const [sound, setSound] = useState<Audio.Sound | null>(null);
const [sound2, setSound2] = useState<Audio.Sound | null>(null);
Expand Down Expand Up @@ -268,17 +261,11 @@ const PronoteWebview: Screen<"PronoteWebview"> = ({ route, navigation }) => {
]}
source={{ uri: infoMobileURL }}
setSupportMultipleWindows={false}
onLoadProgress={({ nativeEvent }) => {
setLoadProgress(nativeEvent.progress);
}}
onError={(e) => {
console.error("Pronote webview error", e);
}}
onLoadStart={(e) => {
const { url } = e.nativeEvent;
setCurrentURL(url);

setLoading(true);

if (url.includes("mobile.eleve.html")) {
setLoginStep("En attente de ton établissement");
Expand Down Expand Up @@ -306,14 +293,18 @@ const PronoteWebview: Screen<"PronoteWebview"> = ({ route, navigation }) => {
kind: pronote.AccountKind.STUDENT,
username: message.data.login,
token: message.data.mdp,
deviceUUID
}
).catch((error) => {
if (error instanceof pronote.SecurityError && !error.handle.shouldCustomPassword && !error.handle.shouldCustomDoubleAuth) {
deviceUUID,
})
.catch((error) => {
if (
error instanceof pronote.SecurityError &&
!error.handle.shouldCustomPassword &&
!error.handle.shouldCustomDoubleAuth
) {
navigation.navigate("Pronote2FA_Auth", {
session,
error,
accountID: deviceUUID
accountID: deviceUUID,
});
} else {
throw error;
Expand Down Expand Up @@ -345,12 +336,11 @@ const PronoteWebview: Screen<"PronoteWebview"> = ({ route, navigation }) => {
authentication: { ...refresh, deviceUUID },
personalization: await defaultPersonalization(session),

identity: {}
identity: {},
};

pronote.startPresenceInterval(session);
createStoredAccount(account);
setLoading(false);
switchTo(account);

// We need to wait a tick to make sure the account is set before navigating.
Expand Down Expand Up @@ -379,42 +369,16 @@ const PronoteWebview: Screen<"PronoteWebview"> = ({ route, navigation }) => {
) {
webViewRef.current?.injectJavaScript(INJECT_PRONOTE_JSON);
} else {
setLoading(false);
if (url.includes("pronote/mobile.eleve.html")) {
if (!url.includes("identifiant")) {
if (Platform.OS === "ios") {
Alert.alert(
"Attention",
"Désolé, seuls les comptes élèves sont compatibles pour le moment.",
[
{
text: "OK",
onPress: () => navigation.goBack(),
},
]
);
} else {
showAlert({
title: "Attention",
message:
"Désolé, seuls les comptes élèves sont compatibles pour le moment.",
actions: [
{
title: "OK",
onPress: () => navigation.goBack(),
backgroundColor: theme.colors.card,
},
],
});
}
} else {
webViewRef.current?.injectJavaScript(
INJECT_PRONOTE_INITIAL_LOGIN_HOOK
);
webViewRef.current?.injectJavaScript(
INJECT_PRONOTE_CURRENT_LOGIN_STATE
);
}
if (
url.includes("pronote/mobile.eleve.html") &&
url.includes("identifiant")
) {
webViewRef.current?.injectJavaScript(
INJECT_PRONOTE_INITIAL_LOGIN_HOOK
);
webViewRef.current?.injectJavaScript(
INJECT_PRONOTE_CURRENT_LOGIN_STATE
);
}

if (url.split("?")[0].includes("mobile.eleve.html") == false) {
Expand Down
25 changes: 24 additions & 1 deletion src/views/welcome/DevMenu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,30 @@ const DevMenu: Screen<"DevMenu"> = ({ navigation }) => {
</NativeItem>

<NativeItem
onPress={() => navigation.navigate("NoteReaction")}
onPress={() => navigation.navigate("GradeReaction", {
grade: {
id: "mmmhm",
subjectName: "Éval TS",
description: "Note de test",
timestamp: 1735996215000,
average: {
value: 0.2
},
coefficient: 40,
min: {
value: 0
},
max: {
value: 20
},
student: {
value: 0
},
outOf: {
value: 20
}
}
})}
>
<NativeText>
NoteReaction
Expand Down
Loading