Skip to content

Commit

Permalink
Merge branch 'main' into more-languages
Browse files Browse the repository at this point in the history
  • Loading branch information
NancyAanchal authored Aug 15, 2024
2 parents 3e3e0c7 + 0022665 commit e1453a9
Show file tree
Hide file tree
Showing 8 changed files with 78 additions and 52 deletions.
1 change: 1 addition & 0 deletions nepalingo-web/.env
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ VITE_GOOGLE_ANALYTICS_TRACKING_ID = "G-DR5RGQ8NZ1"
VITE_SUPABASE_URL=https://iupkdpieqxplryytuerr.supabase.co
VITE_SUPABASE_KEY=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJzdXBhYmFzZSIsInJlZiI6Iml1cGtkcGllcXhwbHJ5eXR1ZXJyIiwicm9sZSI6ImFub24iLCJpYXQiOjE3MTk1NDY4MTEsImV4cCI6MjAzNTEyMjgxMX0.FcvSaML1Z0KLzXWAfXI-xL4b9aGc179uI8Bo2Q_glPI
VITE_GOOGLE_TRANSLATE_API_KEY=AIzaSyCi239eredIAEEJkI8xzvGwW1GPS7B1vxQ
VITE_OPEN_API=sk-svcacct-Kq44sWC6ATfg5VM5Ygm_gA0G-Hk1hpzikg61PxZcKnRWcK2OT3BlbkFJuegR4TMZCDUiBzHGIfSBVqra2eE6FFxpVWO9ASR9qCB8OdEA
3 changes: 2 additions & 1 deletion nepalingo-web/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
"build": "tsc -b && vite build",
"lint": "eslint . --ext ts,tsx --report-unused-disable-directives --max-warnings 0",
"format-check": "prettier . --check",
"preview": "vite preview"
"preview": "vite preview",
"format": "prettier . --write"
},
"dependencies": {
"@fortawesome/fontawesome-svg-core": "^6.5.2",
Expand Down
6 changes: 4 additions & 2 deletions nepalingo-web/src/hooks/Auth.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ const AuthContext = createContext<AuthContextProps>({
signIn: (data) => supabaseClient.auth.signInWithPassword(data),
resetPasswordEmail: (email) =>
supabaseClient.auth.resetPasswordForEmail(email, {
redirectTo: "https://www.nepalingo.com/reset-password",
//redirectTo: "https://www.nepalingo.com/reset-password",
redirectTo: "http://localhost:5173/reset-password",
}),
});

Expand Down Expand Up @@ -71,7 +72,8 @@ export const AuthProvider = ({ children }: { children: React.ReactNode }) => {
signIn: (data) => supabaseClient.auth.signInWithPassword(data),
resetPasswordEmail: (email) =>
supabaseClient.auth.resetPasswordForEmail(email, {
redirectTo: "https://www.nepalingo.com/reset-password",
//redirectTo: "https://www.nepalingo.com/reset-password",
redirectTo: "http://localhost:5173/reset-password",
}),
};

Expand Down
10 changes: 1 addition & 9 deletions nepalingo-web/src/hooks/useDictionary.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,18 +37,10 @@ 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":
Expand Down
2 changes: 1 addition & 1 deletion nepalingo-web/src/lib/getGTranslate.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ 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
77 changes: 43 additions & 34 deletions nepalingo-web/src/lib/getNewariWord.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,43 +15,52 @@ export async function getNewariWord(word: string): Promise<DictionaryResponse> {
const response: DictionaryResponse = {
language: "newari",
word: word,
//Mapping the meanings from the api to create a custom response based on DictionaryResponse
meanings:
data?.meanings.length == 0
data?.meanings.length === 0
? []
: data?.meanings?.map(
(meaning: {
audio?: { file: string; directory: string };
image?: { file: string; directory: string };
meaning_np?: string;
meaning_nb?: string;
meaning_en?: string;
pos?: string;
dialect?: string;
transliterations?: {
deva: string;
latn: string;
newa: string;
};
}) => ({
audio: meaning?.audio && {
uri: `${import.meta.env.VITE_NEPALBHASA_API_URL}/dict/${meaning.audio.directory}/${meaning.audio.file}`,
},
image: meaning?.image && {
uri: `${import.meta.env.VITE_NEPALBHASA_API_URL}/dict/${meaning.image.directory}/w800h800b1sh1/${meaning.image.file}`,
},
meaningOriginal: meaning?.meaning_nb,
meaningNp: meaning?.meaning_np,
meaningEn: meaning?.meaning_en,
dialect: meaning.dialect,
partsOfSpeech: meaning.pos,
transliterations: {
latn: meaning.transliterations?.latn,
deva: meaning.transliterations?.deva,
original: meaning.transliterations?.newa,
: (data?.meanings
?.map(
(meaning: {
audio?: { file: string; directory: string };
image?: { file: string; directory: string };
meaning_np?: string;
meaning_nb?: string;
meaning_en?: string;
pos?: string;
dialect?: string;
transliterations?: {
deva: string;
latn: string;
newa: string;
};
}) => {
// Skip the 'dolakha' dialect
if (meaning.dialect === "dolakha") {
return null;
}

return {
audio: meaning?.audio && {
uri: `${import.meta.env.VITE_NEPALBHASA_API_URL}/dict/${meaning.audio.directory}/${meaning.audio.file}`,
},
image: meaning?.image && {
// TODO: Revert this back to 400x400, Currently set to 400x401 to avoid API error
uri: `${import.meta.env.VITE_NEPALBHASA_API_URL}/dict/${meaning.image.directory}/w400h401b1sh1/${meaning.image.file}`,
},
meaningOriginal: meaning?.meaning_nb,
meaningNp: meaning?.meaning_np,
meaningEn: meaning?.meaning_en,
dialect: meaning.dialect,
partsOfSpeech: meaning.pos,
transliterations: {
latn: meaning.transliterations?.latn,
deva: meaning.transliterations?.deva,
original: meaning.transliterations?.newa,
},
};
},
}),
),
)
.filter(Boolean) as DictionaryResponse["meanings"]), // Filter out any null entries
};
return response;
}
1 change: 0 additions & 1 deletion 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
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 e1453a9

Please sign in to comment.