2024-07-26 23:55:12 +02:00
import React , { useEffect , useState } from "react" ;
import { Collapse , Divider , Table , Typography } from "antd" ;
import { getTldList , Tld } from "../../utils/api" ;
2024-07-28 15:36:22 +02:00
import { t } from 'ttag'
2024-07-30 00:55:36 +02:00
import { regionNames } from "../../i18n" ;
2024-07-30 23:32:22 +02:00
import useBreakpoint from "../../hooks/useBreakpoint" ;
2024-07-31 12:37:43 +02:00
import { ColumnType } from "antd/es/table" ;
2024-07-31 22:40:51 +02:00
import punycode from "punycode/punycode" ;
2024-07-26 23:55:12 +02:00
const { Text , Paragraph } = Typography
type TldType = 'iTLD' | 'sTLD' | 'gTLD' | 'ccTLD'
type FiltersType = { type : TldType , contractTerminated? : boolean , specification13? : boolean }
2024-07-30 23:32:22 +02:00
const toEmoji = ( tld : string ) = > {
if ( tld . startsWith ( 'xn--' ) ) return '-'
2024-07-26 23:55:12 +02:00
2024-07-30 23:32:22 +02:00
return String . fromCodePoint (
. . . getCountryCode ( tld )
. toUpperCase ( )
. split ( '' )
. map ( ( char ) = > 127397 + char . charCodeAt ( 0 ) )
)
}
2024-07-26 23:55:12 +02:00
const getCountryCode = ( tld : string ) : string = > {
const exceptions = { uk : 'gb' , su : 'ru' , tp : 'tl' }
if ( tld in exceptions ) return exceptions [ tld as keyof typeof exceptions ]
2024-07-30 23:32:22 +02:00
return tld . toUpperCase ( )
2024-07-26 23:55:12 +02:00
}
function TldTable ( filters : FiltersType ) {
2024-07-30 23:32:22 +02:00
const sm = useBreakpoint ( 'sm' )
2024-07-26 23:55:12 +02:00
const [ dataTable , setDataTable ] = useState < Tld [ ] > ( [ ] )
const [ total , setTotal ] = useState ( 0 )
2024-07-30 23:32:22 +02:00
const fetchData = ( params : FiltersType & { page : number , itemsPerPage : number } ) = > {
2024-07-26 23:55:12 +02:00
getTldList ( params ) . then ( ( data ) = > {
setTotal ( data [ 'hydra:totalItems' ] )
setDataTable ( data [ 'hydra:member' ] . map ( ( tld : Tld ) = > {
switch ( filters . type ) {
case 'ccTLD' :
2024-07-30 23:32:22 +02:00
let countryName
try {
countryName = regionNames . of ( getCountryCode ( tld . tld ) )
2024-07-31 12:37:43 +02:00
} catch ( e ) {
2024-07-30 23:32:22 +02:00
countryName = '-'
}
2024-07-26 23:55:12 +02:00
return {
2024-07-30 23:32:22 +02:00
key : tld.tld ,
2024-07-31 22:45:34 +02:00
TLD : punycode.toUnicode ( tld . tld ) ,
2024-07-26 23:55:12 +02:00
Flag : toEmoji ( tld . tld ) ,
2024-07-30 23:32:22 +02:00
Country : countryName
2024-07-26 23:55:12 +02:00
}
case 'gTLD' :
return {
2024-07-30 23:32:22 +02:00
key : tld.tld ,
2024-07-31 22:45:34 +02:00
TLD : punycode.toUnicode ( tld . tld ) ,
2024-07-26 23:55:12 +02:00
Operator : tld.registryOperator
}
default :
return {
2024-07-30 23:32:22 +02:00
key : tld.tld ,
2024-07-31 22:45:34 +02:00
TLD : punycode.toUnicode ( tld . tld )
2024-07-26 23:55:12 +02:00
}
}
} ) )
} )
}
useEffect ( ( ) = > {
2024-07-30 23:32:22 +02:00
fetchData ( { . . . filters , page : 1 , itemsPerPage : 30 } )
2024-07-26 23:55:12 +02:00
} , [ ] )
2024-07-30 23:32:22 +02:00
let columns : ColumnType < any > [ ] = [
2024-07-26 23:55:12 +02:00
{
2024-07-28 15:36:22 +02:00
title : t ` TLD ` ,
2024-07-30 23:32:22 +02:00
dataIndex : "TLD"
2024-07-26 23:55:12 +02:00
}
]
if ( filters . type === 'ccTLD' ) columns = [ . . . columns , {
2024-07-28 15:36:22 +02:00
title : t ` Flag ` ,
2024-07-26 23:55:12 +02:00
dataIndex : "Flag" ,
} , {
2024-07-28 15:36:22 +02:00
title : t ` Country ` ,
2024-07-30 23:32:22 +02:00
dataIndex : "Country"
2024-07-26 23:55:12 +02:00
} ]
if ( filters . type === 'gTLD' ) columns = [ . . . columns , {
2024-07-28 15:36:22 +02:00
title : t ` Registry Operator ` ,
2024-07-30 23:32:22 +02:00
dataIndex : "Operator"
2024-07-26 23:55:12 +02:00
} ]
return < Table
columns = { columns }
dataSource = { dataTable }
pagination = { {
total ,
hideOnSinglePage : true ,
2024-07-30 23:32:22 +02:00
defaultPageSize : 30 ,
onChange : ( page , itemsPerPage ) = > {
fetchData ( { . . . filters , page , itemsPerPage } )
2024-07-26 23:55:12 +02:00
}
} }
2024-07-30 23:32:22 +02:00
2024-07-30 23:32:50 +02:00
{ . . . ( sm ? { scroll : { y : 'max-content' } } : { scroll : { y : 240 } } ) }
2024-07-26 23:55:12 +02:00
/ >
}
2024-07-26 16:45:10 +02:00
export default function TldPage() {
2024-07-30 23:32:22 +02:00
const sm = useBreakpoint ( 'sm' )
2024-07-26 23:55:12 +02:00
return < >
< Paragraph >
2024-07-28 15:36:22 +02:00
{ t ` This page presents all active TLDs in the root zone database. ` }
2024-07-26 23:55:12 +02:00
< / Paragraph >
< Paragraph >
2024-07-28 15:36:22 +02:00
{ t ` IANA provides the list of currently active TLDs, regardless of their type, and ICANN provides the list of gTLDs.
In most cases , the two - letter ccTLD assigned to a country is made in accordance with the ISO 3166 - 1 standard .
This data is updated every month . Three HTTP requests are needed for the complete update of TLDs in Domain Watchdog ( two requests to IANA and one to ICANN ) .
At the same time , the list of root RDAP servers is updated . ` }
2024-07-26 23:55:12 +02:00
< / Paragraph >
< Divider / >
< Collapse
2024-07-30 23:32:22 +02:00
size = { sm ? 'small' : 'large' }
2024-07-26 23:55:12 +02:00
items = { [
{
key : 'sTLD' ,
2024-07-28 15:36:22 +02:00
label : t ` Sponsored Top-Level-Domains ` ,
2024-07-26 23:55:12 +02:00
children : < >
2024-07-28 18:40:11 +02:00
< Text > { t ` Top-level domains sponsored by specific organizations that set rules for registration and use, often related to particular interest groups or industries. ` } < / Text >
2024-07-26 23:55:12 +02:00
< Divider / >
< TldTable type = 'sTLD' / >
< / >
} ,
{
key : 'gTLD' ,
2024-07-28 15:36:22 +02:00
label : t ` Generic Top-Level-Domains ` ,
2024-07-26 23:55:12 +02:00
children : < >
2024-07-28 15:36:22 +02:00
< Text > { t ` Generic top-level domains open to everyone, not restricted by specific criteria, representing various themes or industries. ` } < / Text >
2024-07-26 23:55:12 +02:00
< Divider / >
< TldTable type = 'gTLD' contractTerminated = { false } specification13 = { false } / >
< / >
} ,
{
key : 'ngTLD' ,
2024-07-28 15:36:22 +02:00
label : t ` Brand Generic Top-Level-Domains ` ,
2024-07-26 23:55:12 +02:00
children : < >
2024-07-28 15:36:22 +02:00
< Text > { t ` Generic top-level domains associated with specific brands, allowing companies to use their own brand names as domains. ` } < / Text >
2024-07-26 23:55:12 +02:00
< Divider / >
< TldTable type = 'gTLD' contractTerminated = { false } specification13 = { true } / >
< / >
} ,
{
key : 'ccTLD' ,
2024-07-28 15:36:22 +02:00
label : t ` Country-Code Top-Level-Domains ` ,
2024-07-26 23:55:12 +02:00
children : < >
2024-07-28 20:49:54 +02:00
< Text > { t ` Top-level domains based on country codes, identifying websites according to their country of origin. ` } < / Text >
2024-07-26 23:55:12 +02:00
< Divider / > < TldTable type = 'ccTLD' / >
< / >
}
] }
/ >
< / >
2024-07-26 16:45:10 +02:00
}