Skip to content

Commit

Permalink
dep: remove tle.js
Browse files Browse the repository at this point in the history
  • Loading branch information
HoshinoSuzumi committed Apr 12, 2024
1 parent 3eebf06 commit 7bff33b
Show file tree
Hide file tree
Showing 6 changed files with 69 additions and 88 deletions.
26 changes: 13 additions & 13 deletions app/satellites/Main.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,10 @@ import { useRef, useState } from 'react'
import useSWR from 'swr'
import { Icon } from '@iconify-icon/react'
import { noto_sc, rubik } from '@/app/fonts'
import { Input } from '@douyinfe/semi-ui'
import { Banner, Input } from '@douyinfe/semi-ui'
import { IconSearch } from '@douyinfe/semi-icons'
import { BaseResponse, LatestTleSet, Satellite } from '@/app/api/types'
import { SatelliteTable } from '@/app/satellites/SatelliteTable'
import dayjs from '@/app/utils/dayjs'

export const Main = () => {
const compositionRef = useRef({ isComposition: false })
Expand All @@ -19,20 +18,10 @@ export const Main = () => {
pageSize: 10,
})

const tle_case = [
'ISS (ZARYA)',
'1 25544U 98067A 23006.23627037 .00014367 00000+0 25952-3 0 9997',
'2 25544 51.6447 50.7420 0004899 231.6381 243.6067 15.49962952376670',
]

const startMS = dayjs().unix() * 1000 // current time
const endMS = dayjs().add(1, 'day').unix() * 1000 // 1 day later

// console.log(getPasses(tle_case as TLE, startMS, endMS, 1000))

const {
data: satellitesData,
isLoading: isSatellitesLoading,
error: satellitesError,
} = useSWR<BaseResponse<Satellite[]>>('/api/satellite/satnogs/satellites', {
refreshWhenHidden: false,
refreshWhenOffline: false,
Expand Down Expand Up @@ -93,6 +82,17 @@ export const Main = () => {
/>
</div>
<div className={ 'w-full xl:w-[80%]' }>
{ satellitesData && satellitesData.code !== 0 && (
<Banner
className={ 'mb-4 mx-4 md:mx-0' }
fullMode={ false }
title="加载失败"
type="danger"
bordered
description="加载卫星数据时出现错误,请检查网络"
></Banner>
) }

<SatelliteTable
satellites={ (satellitesData?.data || []) }
tleList={ tleData?.data || [] }
Expand Down
63 changes: 48 additions & 15 deletions app/satellites/SatelliteTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { Icon } from '@iconify-icon/react'
import { noto_sc, rubik } from '@/app/fonts'
import { IconSpinner } from '@/components/Icon/IconSpinner'
import { Button } from '@douyinfe/semi-ui'
import useSWR, { SWRConfig } from 'swr'

const NationalFlag = ({ countries }: { countries: string }) => {
const countriesList = countries.split(',')
Expand Down Expand Up @@ -87,6 +88,31 @@ const SatelliteTableRow = ({
}) => {
const [expanded, setExpanded] = useState(false)

const {
data: sightingData,
isLoading: isSightingLoading,
} = useSWR(expanded && {
resource: 'https://ham-api.c5r.app/sat/sightings',
init: {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({
tle0: tle?.tle0,
tle1: tle?.tle1,
tle2: tle?.tle2,
hours: 24,
elevation_threshold: 20,
observer: {
lat: 0,
lon: 0,
alt: 0,
},
}),
},
})

return (
<>
<tr
Expand Down Expand Up @@ -132,7 +158,7 @@ const SatelliteTableRow = ({
colSpan={ 3 }
>
<div>
什么都没有
<pre>{ JSON.stringify(sightingData, null, 2) }</pre>
</div>
</TableCell>
</tr>
Expand Down Expand Up @@ -203,26 +229,33 @@ export const SatelliteTable = ({
<tbody>
{ satellites.length === 0 && (
<tr>
<TableCell className={ 'text-center' } colSpan={ 3 }>暂无数据</TableCell>
<TableCell className={ 'text-center' } colSpan={ 4 }>暂无数据</TableCell>
</tr>
) }
{ filteredSatellites.slice(
(pagination?.current || 1) * (pagination?.pageSize || 10) - (pagination?.pageSize || 10),
(pagination?.current || 1) * (pagination?.pageSize || 10),
).map((satellite, index) => (
<SatelliteTableRow
key={ index }
satellite={ satellite }
tle={ tleList.find(i => i.norad_cat_id === satellite.norad_cat_id) || null }
timestamp={ timestamp }
compact={ compact }
/>
)) }
<SWRConfig value={ {
fetcher: ({ resource, init }: {
resource: string | URL | Request,
init: RequestInit | undefined
}) => fetch(resource, init).then(res => res.json()),
} }>
{ filteredSatellites.slice(
(pagination?.current || 1) * (pagination?.pageSize || 10) - (pagination?.pageSize || 10),
(pagination?.current || 1) * (pagination?.pageSize || 10),
).map((satellite, index) => (
<SatelliteTableRow
key={ index }
satellite={ satellite }
tle={ tleList.find(i => i.norad_cat_id === satellite.norad_cat_id) || null }
timestamp={ timestamp }
compact={ compact }
/>
)) }
</SWRConfig>
</tbody>
<caption
className={ `text-xs pt-4 text-neutral-500 dark:text-neutral-400 caption-bottom ${ noto_sc.className }` }
>
数据来源于 SatNOGS
数据来源于 <a href={ 'https://db.satnogs.org/' } target={ '_blank' }>SatNOGS DB</a>
</caption>
</table>
</div>
Expand Down
8 changes: 5 additions & 3 deletions app/swr-provider.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'use client';
import {SWRConfig} from 'swr'
import {ReactNode} from 'react';
import { SWRConfig } from 'swr'
import { ReactNode } from 'react'

export const SWRProvider = ({
children,
Expand All @@ -9,5 +9,7 @@ export const SWRProvider = ({
}) => {
return <SWRConfig value={{
fetcher: (resource, init) => fetch(resource, init).then(res => res.json()),
}}>{children}</SWRConfig>
} }>
{ children }
</SWRConfig>
};
36 changes: 0 additions & 36 deletions app/utils/sat.ts

This file was deleted.

19 changes: 1 addition & 18 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 2 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"version": "0.2.0",
"private": true,
"scripts": {
"dev": "next dev -p 3000",
"dev": "next dev -p 4090",
"vercel-dev": "vercel dev --listen 3000",
"build": "next build",
"start": "next start",
Expand All @@ -28,8 +28,7 @@
"rehype-katex": "^7.0.0",
"remark-gfm": "^4.0.0",
"remark-math": "^6.0.0",
"swr": "^2.2.5",
"tle.js": "^4.9.0"
"swr": "^2.2.5"
},
"devDependencies": {
"@iconify-icon/react": "^2.0.1",
Expand Down

0 comments on commit 7bff33b

Please sign in to comment.