render.js 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. import { Label } from 'semantic-ui-react';
  2. export function renderText(text, limit) {
  3. if (text.length > limit) {
  4. return text.slice(0, limit - 3) + '...';
  5. }
  6. return text;
  7. }
  8. export function renderGroup(group) {
  9. if (group === '') {
  10. return <Label>default</Label>;
  11. }
  12. let groups = group.split(',');
  13. groups.sort();
  14. return <>
  15. {groups.map((group) => {
  16. if (group === 'vip' || group === 'pro') {
  17. return <Label color='yellow'>{group}</Label>;
  18. } else if (group === 'svip' || group === 'premium') {
  19. return <Label color='red'>{group}</Label>;
  20. }
  21. return <Label>{group}</Label>;
  22. })}
  23. </>;
  24. }
  25. export function renderNumber(num) {
  26. if (num >= 1000000000) {
  27. return (num / 1000000000).toFixed(1) + 'B';
  28. } else if (num >= 1000000) {
  29. return (num / 1000000).toFixed(1) + 'M';
  30. } else if (num >= 10000) {
  31. return (num / 1000).toFixed(1) + 'k';
  32. } else {
  33. return num;
  34. }
  35. }
  36. export function renderQuota(quota, digits = 2) {
  37. let quotaPerUnit = localStorage.getItem('quota_per_unit');
  38. let displayInCurrency = localStorage.getItem('display_in_currency');
  39. quotaPerUnit = parseFloat(quotaPerUnit);
  40. displayInCurrency = displayInCurrency === 'true';
  41. if (displayInCurrency) {
  42. return '$' + (quota / quotaPerUnit).toFixed(digits);
  43. }
  44. return renderNumber(quota);
  45. }