]> git.localhorst.tv Git - alttp.git/blobdiff - resources/js/components/tournament/Scoreboard.js
lazy load some stuff
[alttp.git] / resources / js / components / tournament / Scoreboard.js
index 40ad82ff300724acda076a5f7038d1546b723c5e..f13adacb61bbaa7a4465f88fb8b549ea535cca40 100644 (file)
@@ -31,6 +31,33 @@ const getPlacementDisplay = participant => {
        return participant.placement;
 };
 
+const twitchReg = /^https?:\/\/(www\.)?twitch\.tv/;
+const youtubeReg = /^https?:\/\/(www\.)?youtu(\.be|be\.)/;
+
+const getStreamVariant = participant => {
+       if (!participant || !participant.user || !participant.user.stream_link) {
+               return 'outline-secondary';
+       }
+       if (twitchReg.test(participant.user.stream_link)) {
+               return 'outline-twitch';
+       }
+       if (youtubeReg.test(participant.user.stream_link)) {
+               return 'outline-youtube';
+       }
+       return 'outline-secondary';
+};
+
+const getStreamIcon = participant => {
+       const variant = getStreamVariant(participant);
+       if (variant === 'outline-twitch') {
+               return <Icon.TWITCH title="" />;
+       }
+       if (variant === 'outline-youtube') {
+               return <Icon.YOUTUBE title="" />;
+       }
+       return <Icon.VIDEO title="" />;
+};
+
 const Scoreboard = ({ tournament, user }) =>
 <Table striped className="scoreboard align-middle">
        <thead>
@@ -55,9 +82,9 @@ const Scoreboard = ({ tournament, user }) =>
                                                        size="sm"
                                                        target="_blank"
                                                        title={i18n.t('users.stream')}
-                                                       variant="outline-twitch"
+                                                       variant={getStreamVariant(participant)}
                                                >
-                                                       <Icon.STREAM title="" />
+                                                       {getStreamIcon(participant)}
                                                </Button>
                                        : null}
                                </div>