-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
e019d60
commit 66e1eb6
Showing
6 changed files
with
58 additions
and
8 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
5 changes: 5 additions & 0 deletions
5
src/components/StreakView/User/CountryFlag/CountryFlag.module.less
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
.country-flag { | ||
background-size: contain; | ||
background-position: 50%; | ||
background-repeat: no-repeat; | ||
} |
34 changes: 34 additions & 0 deletions
34
src/components/StreakView/User/CountryFlag/CountryFlag.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import { useMemo } from "react"; | ||
import styles from "./CountryFlag.module.less"; | ||
import "/node_modules/flag-icons/css/flag-icons.min.css"; | ||
|
||
type CountryFlagProps = { | ||
countryCode?: string; | ||
}; | ||
/** | ||
* Country flags implemented using the flag-icons library. | ||
*/ | ||
export const CountryFlag = (props: CountryFlagProps) => { | ||
const countryCode = useMemo( | ||
() => manuallyCorrectCountryCode(props.countryCode), | ||
[props.countryCode], | ||
); | ||
|
||
if (!countryCode) { | ||
return null; | ||
} | ||
|
||
return <div className={`${styles.countryFlag} fi fi-${countryCode}`}></div>; | ||
}; | ||
|
||
/** | ||
* The language code returned by the DuoLingo API is not always the same as the one used by the flag-icons library. | ||
*/ | ||
const manuallyCorrectCountryCode = (languageCode?: string) => { | ||
switch (languageCode) { | ||
case "ja": | ||
return "jp"; | ||
default: | ||
return languageCode; | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
.user { | ||
.container { | ||
display: flex; | ||
flex-direction: column; | ||
align-items: center; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters