Skip to content

Commit

Permalink
Merge branch 'main' into about-fix
Browse files Browse the repository at this point in the history
  • Loading branch information
SansCaar authored Aug 16, 2024
2 parents c9687d4 + 0a57d26 commit 26d502e
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 16 deletions.
2 changes: 2 additions & 0 deletions nepalingo-web/src/hooks/Langauge.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ export const Languages = {
Newari: "newari",
Tajpuriya: "tajpuriya",
Maithili: "maithili",
Sanskrit: "sanskrit",
Nepali: "nepali",
} as const;

type LanguageContextProps = {
Expand Down
14 changes: 5 additions & 9 deletions nepalingo-web/src/hooks/useDictionary.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,22 +37,18 @@ async function getFetcherByLanguage(
if (!word) {
word = "hello";
}
let newariResult: DictionaryResponse;

switch (language) {
case "Newari":
newariResult = await getNewariWord(word);

if (newariResult.meanings.length === 0) {
console.log("Used Google Translate for newari");
return await getGTranslate("newari", word);
}
return newariResult;

return await getNewariWord(word);
case "Tajpuriya":
return await getTajpuriyaWord(word);
case "Maithili":
return await getGTranslate("maithili", word);
case "Sanskrit":
return await getGTranslate("sanskrit", word);
case "Nepali":
return await getGTranslate("nepali", word);

default:
throw new Error(`Language ${language} not supported`);
Expand Down
3 changes: 2 additions & 1 deletion nepalingo-web/src/lib/getGTranslate.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ const GOOGLE_TRANSLATE_API_KEY = import.meta.env.VITE_GOOGLE_TRANSLATE_API_KEY;

const languageCodes: { [key: string]: string } = {
maithili: "mai",
newari: "new",
sanskrit: "sa",
nepali: "ne",
};

export const getGTranslate = async (
Expand Down
8 changes: 6 additions & 2 deletions nepalingo-web/src/lib/getNextWord.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
export const newariWords = [
"hello",
"call",
"can",
"do",
"how",
"I",
Expand Down Expand Up @@ -59,7 +58,12 @@ export function* wordGenerator(words: string[]) {

export async function getNextWord(language: string) {
let words: string[] = [];
if (language === "Newari" || language === "Maithili") {
if (
language === "Newari" ||
language === "Maithili" ||
language === "Sanskrit" ||
language === "Nepali"
) {
words = newariWords;
} else if (language === "Tajpuriya") {
words = await getTajpuriyaWords();
Expand Down
30 changes: 26 additions & 4 deletions nepalingo-web/src/pages/ResetPassword.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { useState } from "react";
import React, { useState, useEffect } from "react";
import { useNavigate } from "react-router-dom";
import CustomTextInput from "@/components/CustomTextInput";
import Button from "@/components/Button";
Expand All @@ -24,21 +24,43 @@ const ResetPassword: React.FC = () => {

// Update the password using the Supabase client
const { error: updateError } = await supabaseClient.auth.updateUser({
password,
password: password,
});

if (updateError) {
setError(updateError.message);
} else {
navigate("/login", {
state: {
message:
"Password reset successful! Please log in with your new password.",
message: "Password reset successful!",
},
});
}
};

useEffect(() => {
const handleSessionFromURL = async () => {
// Extract session-related parameters from the URL
const urlParams = new URLSearchParams(window.location.search);
const accessToken = urlParams.get("access_token");
const refreshToken = urlParams.get("refresh_token");

if (accessToken && refreshToken) {
// Set the session in Supabase
const { error } = await supabaseClient.auth.setSession({
access_token: accessToken,
refresh_token: refreshToken,
});

if (error) {
setError("Failed to restore session. Please try again.");
}
}
};

handleSessionFromURL();
}, []);

return (
<div className="flex items-center justify-center min-h-screen bg-black">
<div className="bg-black p-8 rounded shadow-md w-full max-w-md">
Expand Down

0 comments on commit 26d502e

Please sign in to comment.