-
Notifications
You must be signed in to change notification settings - Fork 211
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1706 from ushachev/fix-language-icons
Replace library of programming language icons
- Loading branch information
Showing
17 changed files
with
864 additions
and
159 deletions.
There are no files selected for viewing
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
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
65 changes: 44 additions & 21 deletions
65
services/app/apps/codebattle/assets/js/widgets/components/LanguageIcon.jsx
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,28 +1,51 @@ | ||
import React from 'react'; | ||
|
||
import cn from 'classnames'; | ||
import ClojureOriginalIcon from 'react-devicons/clojure/original'; | ||
import CppOriginalIcon from 'react-devicons/cplusplus/original'; | ||
import CsharpOriginalIcon from 'react-devicons/csharp/original'; | ||
import DartOriginalIcon from 'react-devicons/dart/original'; | ||
import GolangOriginalIcon from 'react-devicons/go/original'; | ||
import HaskellOriginalIcon from 'react-devicons/haskell/original'; | ||
import JavaOriginalIcon from 'react-devicons/java/original'; | ||
import NodejsPlainIcon from 'react-devicons/nodejs/plain'; | ||
import TypescriptOriginalIcon from 'react-devicons/typescript/original'; | ||
|
||
const iconsToClass = { | ||
js: 'icon-nodejs', | ||
javascript: 'icon-nodejs', | ||
ts: 'icon-nodejs', | ||
typescript: 'icon-nodejs', | ||
dart: 'icon-ghost', | ||
golang: 'icon-go', | ||
cpp: 'icon-cplusplus', | ||
csharp: 'icon-csharp', | ||
java: 'icon-java', | ||
kotlin: 'icon-java-bold', | ||
ruby: 'icon-ruby', | ||
elixir: 'icon-elixir', | ||
haskell: 'icon-haskell', | ||
clojure: 'icon-clojure', | ||
python: 'icon-python', | ||
php: 'icon-php-alt', | ||
import ElixirOriginalIcon from './icons/ElixirOriginalIcon'; | ||
import KotlinOriginalIcon from './icons/KotlinOriginalIcon'; | ||
import PhpOriginalIcon from './icons/PhpOriginalIcon'; | ||
import PythonOriginalIcon from './icons/PythonOriginalIcon'; | ||
import RubyOriginalIcon from './icons/RubyOriginalIcon'; | ||
|
||
const iconRenderers = { | ||
js: className => <NodejsPlainIcon className={className} color="green" size="1.25em" />, | ||
javascript: className => <NodejsPlainIcon className={className} color="green" size="1.25em" />, | ||
ts: className => <TypescriptOriginalIcon className={className} size="1.125em" />, | ||
typescript: className => <TypescriptOriginalIcon className={className} size="1.125em" />, | ||
dart: className => <DartOriginalIcon className={className} size="1.125em" />, | ||
golang: className => <GolangOriginalIcon className={className} size="1.25em" />, | ||
cpp: className => <CppOriginalIcon className={className} size="1.25em" />, | ||
csharp: className => <CsharpOriginalIcon className={className} size="1.25em" />, | ||
java: className => ( | ||
<JavaOriginalIcon | ||
className={className} | ||
style={{ transform: 'translateY(-0.125em)' }} | ||
size="1.25em" | ||
/> | ||
), | ||
kotlin: className => <KotlinOriginalIcon className={className} />, | ||
ruby: className => <RubyOriginalIcon className={className} />, | ||
elixir: className => <ElixirOriginalIcon className={className} size="1.25em" />, | ||
haskell: className => <HaskellOriginalIcon className={className} size="1.125em" />, | ||
clojure: className => <ClojureOriginalIcon className={className} size="1.125em" />, | ||
python: className => <PythonOriginalIcon className={className} size="1.25em" />, | ||
php: className => <PhpOriginalIcon className={className} size="1.875em" />, | ||
default: () => null, | ||
}; | ||
|
||
const LanguageIcon = ({ lang }) => ( | ||
<span className={cn('d-inline-block', iconsToClass[lang])} style={{ marginTop: 2 }} /> | ||
); | ||
const LanguageIcon = ({ className = '', lang }) => { | ||
const renderIcon = iconRenderers[lang] || iconRenderers.default; | ||
|
||
return renderIcon(className); | ||
}; | ||
|
||
export default LanguageIcon; |
45 changes: 16 additions & 29 deletions
45
services/app/apps/codebattle/assets/js/widgets/components/ResultIcon.jsx
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
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
60 changes: 18 additions & 42 deletions
60
services/app/apps/codebattle/assets/js/widgets/components/UserName.jsx
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,58 +1,34 @@ | ||
import React from 'react'; | ||
|
||
import { faCircle, faRobot } from '@fortawesome/free-solid-svg-icons'; | ||
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome'; | ||
import cn from 'classnames'; | ||
|
||
import LanguageIcon from './LanguageIcon'; | ||
|
||
const renderUserName = ({ name, rank }) => { | ||
const displayRank = rank ? `(${rank})` : ''; | ||
|
||
return `${name}${displayRank}`; | ||
}; | ||
const renderOnlineIndicator = (user, isOnline) => { | ||
if (user.id <= 0) { | ||
return null; | ||
} | ||
|
||
const onlineIndicatorClassName = cn('mr-2', { | ||
const UserName = ({ | ||
className = '', user, truncate, isOnline, hideOnlineIndicator, | ||
}) => { | ||
const commonClassName = 'd-flex align-items-center'; | ||
const onlineIndicatorClassName = cn('mr-1', { | ||
'cb-user-online': isOnline, | ||
'cb-user-offline': !isOnline, | ||
}); | ||
const userLinkClassName = cn('text-truncate', { | ||
'text-danger': user.isAdmin, | ||
'x-username-truncated': truncate, | ||
}); | ||
|
||
const userName = user.rank ? `${user.name}(${user.rank})` : user.name; | ||
|
||
return ( | ||
<span> | ||
<FontAwesomeIcon | ||
icon={['fa', 'circle']} | ||
className={onlineIndicatorClassName} | ||
/> | ||
</span> | ||
<div className={cn(commonClassName, className)}> | ||
{(!hideOnlineIndicator && !user.isBot) && <FontAwesomeIcon icon={faCircle} className={onlineIndicatorClassName} />} | ||
<LanguageIcon className="mr-1" lang={user.lang} /> | ||
{user.isBot && <FontAwesomeIcon className="mr-1" icon={faRobot} transform="up-1" />} | ||
<a href={`/users/${user.id}`} className={userLinkClassName}>{userName}</a> | ||
</div> | ||
); | ||
}; | ||
|
||
const UserName = ({ | ||
user, truncate, isOnline, hideOnlineIndicator, | ||
}) => ( | ||
<div className="d-flex align-items-center"> | ||
{!hideOnlineIndicator && renderOnlineIndicator(user, isOnline)} | ||
<LanguageIcon lang={user.lang || 'js'} /> | ||
{user.id < 0 && <FontAwesomeIcon className="mx-1" icon="robot" transform="up-1" />} | ||
<a | ||
href={`/users/${user.id}`} | ||
key={user.id} | ||
className={cn('d-flex align-items-center', { | ||
'text-danger': user.isAdmin, | ||
})} | ||
> | ||
<p | ||
className={cn('text-truncate m-0', { | ||
'x-username-truncated': truncate, | ||
})} | ||
> | ||
<u className="text-decoration-none">{renderUserName(user)}</u> | ||
</p> | ||
</a> | ||
</div> | ||
); | ||
|
||
export default UserName; |
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
Oops, something went wrong.