|
| 1 | +/* eslint-disable @typescript-eslint/explicit-function-return-type */ |
| 2 | +import banner from '../assets/banner.png'; |
| 3 | +import '../index.scss'; |
| 4 | +import { Box, Button, HStack, Icon, Image, Link, Spacer, Text, VStack, Alert, AlertIcon } from '@chakra-ui/react'; |
| 5 | +import { IGithubRelease, IReleaseAsset } from '../types/githubTypes'; |
| 6 | +import { OS, isSupportedOS } from '../utils'; |
| 7 | +import { BsWindows, BsApple, BsFillQuestionDiamondFill } from 'react-icons/bs/index.js'; |
| 8 | +import { FaLinux } from 'react-icons/fa/index.js'; |
| 9 | +import { MdDownload } from 'react-icons/md/index.js'; |
| 10 | +import ReactMarkdown from 'react-markdown'; |
| 11 | +import { GitHubButton } from '../components/buttons/GitHubButton'; |
| 12 | +import { DiscordButton } from '../components/buttons/DiscordButton'; |
| 13 | +import { KofiButton } from '../components/buttons/KofiButton'; |
| 14 | +import { ShellWrapper } from '../components/PageShell/PageShell'; |
| 15 | +import ChakraUIRenderer from '../utils/chakra-ui-markdown-renderer'; |
| 16 | + |
| 17 | +function Page(pageProps: { |
| 18 | + latestVersion: IGithubRelease | undefined; |
| 19 | + dmgBuild: IReleaseAsset | undefined; |
| 20 | + exeBuild: IReleaseAsset | undefined; |
| 21 | + debBuild: IReleaseAsset | undefined; |
| 22 | + rpmBuild: IReleaseAsset | undefined; |
| 23 | + winZip: IReleaseAsset | undefined; |
| 24 | + macZip: IReleaseAsset | undefined; |
| 25 | + linuxZip: IReleaseAsset | undefined; |
| 26 | + releaseDate: string | undefined; |
| 27 | + computedChangelog: string; |
| 28 | +}) { |
| 29 | + const { latestVersion, dmgBuild, exeBuild, debBuild, rpmBuild, winZip, macZip, linuxZip, releaseDate, computedChangelog } = pageProps; |
| 30 | + |
| 31 | + let currentBuild: IReleaseAsset | undefined; |
| 32 | + let zipBuild: IReleaseAsset | undefined; |
| 33 | + let icon; |
| 34 | + switch (OS.name) { |
| 35 | + case 'Windows': |
| 36 | + currentBuild = exeBuild; |
| 37 | + zipBuild = winZip; |
| 38 | + icon = BsWindows; |
| 39 | + break; |
| 40 | + case 'Mac OS': |
| 41 | + currentBuild = dmgBuild; |
| 42 | + zipBuild = macZip; |
| 43 | + icon = BsApple; |
| 44 | + break; |
| 45 | + case 'Debian': |
| 46 | + currentBuild = debBuild; |
| 47 | + zipBuild = linuxZip; |
| 48 | + icon = FaLinux; |
| 49 | + break; |
| 50 | + case 'RedHat': |
| 51 | + currentBuild = rpmBuild; |
| 52 | + zipBuild = linuxZip; |
| 53 | + icon = FaLinux; |
| 54 | + break; |
| 55 | + case 'Linux': |
| 56 | + currentBuild = debBuild; |
| 57 | + zipBuild = linuxZip; |
| 58 | + icon = FaLinux; |
| 59 | + break; |
| 60 | + default: |
| 61 | + icon = BsFillQuestionDiamondFill; |
| 62 | + break; |
| 63 | + } |
| 64 | + |
| 65 | + return ( |
| 66 | + <ShellWrapper> |
| 67 | + <VStack |
| 68 | + spacing={8} |
| 69 | + mb="auto" |
| 70 | + > |
| 71 | + <HStack w="full"> |
| 72 | + <Spacer display={{ base: 'block', sm: 'none' }} /> |
| 73 | + <Image |
| 74 | + src={banner} |
| 75 | + w={{ |
| 76 | + base: '240px', |
| 77 | + md: '360px', |
| 78 | + }} |
| 79 | + /> |
| 80 | + <Spacer /> |
| 81 | + <HStack |
| 82 | + spacing={{ base: 2, lg: 6 }} |
| 83 | + display={{ base: 'none', sm: 'flex' }} |
| 84 | + > |
| 85 | + <GitHubButton /> |
| 86 | + <DiscordButton /> |
| 87 | + <KofiButton /> |
| 88 | + </HStack> |
| 89 | + </HStack> |
| 90 | + |
| 91 | + <Alert |
| 92 | + status="warning" |
| 93 | + borderRadius="md" |
| 94 | + w="full" |
| 95 | + bgColor="yellow.700" |
| 96 | + color="white" |
| 97 | + > |
| 98 | + <AlertIcon /> |
| 99 | + Nightly builds are experimental and may be unstable. |
| 100 | + </Alert> |
| 101 | + |
| 102 | + <VStack> |
| 103 | + <Button |
| 104 | + colorScheme="green" |
| 105 | + borderRadius="2xl" |
| 106 | + onClick={() => { |
| 107 | + if (currentBuild != null && isSupportedOS) { |
| 108 | + window.location.href = currentBuild?.browser_download_url; |
| 109 | + } |
| 110 | + }} |
| 111 | + height="auto" |
| 112 | + px={8} |
| 113 | + py={7} |
| 114 | + disabled={!isSupportedOS || currentBuild == null} |
| 115 | + > |
| 116 | + <VStack> |
| 117 | + <HStack> |
| 118 | + <Icon |
| 119 | + boxSize={8} |
| 120 | + as={MdDownload} |
| 121 | + ></Icon> |
| 122 | + <Text |
| 123 | + fontSize={{ |
| 124 | + base: 20, |
| 125 | + sm: 26, |
| 126 | + md: 36, |
| 127 | + }} |
| 128 | + fontWeight="bold" |
| 129 | + > |
| 130 | + {latestVersion != null ? `Download Nightly${releaseDate != null ? ` (${releaseDate})` : ''}` : 'No nightly release found'} |
| 131 | + </Text> |
| 132 | + </HStack> |
| 133 | + <HStack> |
| 134 | + <Icon as={icon}></Icon> |
| 135 | + <Text fontSize={18}>{isSupportedOS ? OS.name : 'Unsupported OS'}</Text> |
| 136 | + </HStack> |
| 137 | + </VStack> |
| 138 | + </Button> |
| 139 | + {zipBuild != null && isSupportedOS && ( |
| 140 | + <Text color="white"> |
| 141 | + Or download the{' '} |
| 142 | + <Link |
| 143 | + color="blue.300" |
| 144 | + href={zipBuild?.browser_download_url} |
| 145 | + > |
| 146 | + portable nightly (zip) |
| 147 | + </Link> |
| 148 | + </Text> |
| 149 | + )} |
| 150 | + <Text color="white"> |
| 151 | + Prefer stability?{' '} |
| 152 | + <Link |
| 153 | + color="blue.300" |
| 154 | + href="/download" |
| 155 | + > |
| 156 | + Go to stable downloads |
| 157 | + </Link> |
| 158 | + </Text> |
| 159 | + </VStack> |
| 160 | + <Box |
| 161 | + color="white" |
| 162 | + w="full" |
| 163 | + bgColor="gray.700" |
| 164 | + borderRadius="lg" |
| 165 | + > |
| 166 | + <Box |
| 167 | + mx={2} |
| 168 | + p={4} |
| 169 | + h="49rem" |
| 170 | + w="full" |
| 171 | + overflowY="scroll" |
| 172 | + > |
| 173 | + <ReactMarkdown |
| 174 | + components={ChakraUIRenderer()} |
| 175 | + skipHtml |
| 176 | + > |
| 177 | + {computedChangelog} |
| 178 | + </ReactMarkdown> |
| 179 | + </Box> |
| 180 | + </Box> |
| 181 | + </VStack> |
| 182 | + </ShellWrapper> |
| 183 | + ); |
| 184 | +} |
| 185 | + |
| 186 | +export { Page }; |
0 commit comments