2024-03-03 17:09:29 -08:00
import type { HostingProvider , ProviderType } from "@site/src/types/providers" ;
2023-11-07 21:13:48 -06:00
import ReactMarkdown from "react-markdown" ;
2024-01-25 22:38:57 -08:00
import Admonition from '@theme/Admonition' ;
import React , { useState } from 'react' ;
2024-09-09 10:41:58 +01:00
import Translate , { translate } from "@docusaurus/Translate" ;
2024-03-03 17:09:29 -08:00
import { providersData } from "../data/providers" ;
2023-11-07 21:13:48 -06:00
export const noP = ( props : { children : any ; }) => {
2024-01-25 22:38:57 -08:00
const { children } = props ;
return children ;
2023-11-07 21:13:48 -06:00
}
2024-01-25 22:38:57 -08:00
export const Provider = ({ type }) => {
2024-03-03 17:09:29 -08:00
const hostingProviders : HostingProvider [] = providersData [ type as ProviderType ]
2024-01-25 22:38:57 -08:00
return (
< div >
2024-03-03 17:09:29 -08:00
< ul >{ hostingProviders . map (( provider : HostingProvider ) => (
2024-01-25 22:38:57 -08:00
< li >
< a href = { provider . url }>{ provider . name }</ a >
2024-03-03 17:09:29 -08:00
{ provider . description != null ? (
< ReactMarkdown children = { ` ‐ ${ provider . description } ` } components = {{ p : noP }} />
2024-01-25 22:38:57 -08:00
) : (
''
)}
</ li >
))}</ ul >
</ div >
)
}
export const ProviderSelector = () => {
const providers : HostingProvider [] = [
2024-03-03 17:09:29 -08:00
... Object . values ( providersData . built_in ),
... Object . values ( providersData . support ),
... Object . values ( providersData . no_support )
2024-01-27 23:04:06 -08:00
]. flat (). sort (( a , b ) => a . name . localeCompare ( b . name ));
2024-09-09 10:41:58 +01:00
providers . unshift ({
name : 'Not listed' ,
description : translate ({
id : 'providers.provider.not_listed.description' ,
message : "If your hosting provider is not listed, try enabling the `clone-remote-port` option in the config. Then, restart the server, and try connecting with the same IP and port as on Java Edition. <br> If this does not work, ask your server hosting provider for a UDP port, and use that. For VPS/KVM servers please follow the self-hosting steps."
})
} as HostingProvider );
2024-01-25 22:38:57 -08:00
const [ selectedProvider , setSelectedProvider ] = useState ( null );
const handleSelectionChange = ( event ) => {
const selectedName = event . target . value ;
const provider = providers . find ( p => p . name === selectedName );
setSelectedProvider ( provider );
}
return (
2024-01-27 23:04:06 -08:00
< div className = "host-select" >
2024-01-25 22:38:57 -08:00
< select onChange = { handleSelectionChange }>
< option value = "none" > Select a provider </ option >
{ providers . map (( provider ) => (
< option key = { provider . name } value = { provider . name }>
{ provider . name }
</ option >
))}
</ select >
2024-03-03 21:09:13 -08:00
< Admonition type = "tip" title = {< Translate id = 'components.provider.instructions' > Provider Instructions </ Translate >}>
2024-01-25 22:38:57 -08:00
{ selectedProvider ? (
< ReactMarkdown >{ selectedProvider . description }</ ReactMarkdown >
) : (
2024-03-03 14:46:48 -08:00
< p >
2024-03-03 21:09:13 -08:00
< Translate id = 'components.provider.select' > Select a provider to see specific installation instructions </ Translate >
2024-03-03 14:46:48 -08:00
</ p >
2024-01-25 22:38:57 -08:00
)}
</ Admonition >
</ div >
);
2023-11-07 21:13:48 -06:00
}