-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(space): work on space section rework
- Loading branch information
Xenepix38
committed
Oct 21, 2023
1 parent
90e2395
commit 9d48244
Showing
10 changed files
with
133 additions
and
57 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
export interface Fleet{ | ||
name: string | ||
uuid: string | ||
value: number | ||
bot_count: number | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,27 +1,54 @@ | ||
import { Fleet } from 'api/fleets/fleets' | ||
import { request } from 'api/request' | ||
import { Wallet } from 'api/wallets/wallets' | ||
import { AxiosResponse } from 'axios' | ||
import { useSearchParams } from 'next/navigation' | ||
|
||
export interface NapseSpace { | ||
export interface BaseNapseSpace{ | ||
name: string | ||
description: string | ||
exchange_account: string | ||
} | ||
|
||
export interface NapseSpace extends BaseNapseSpace{ | ||
uuid: string | ||
value: number | ||
fleet_count: number | ||
} | ||
|
||
interface Statistics { | ||
[Key: string]: number | ||
} | ||
|
||
interface History{ | ||
// TODO: Improve this | ||
[Key: string]: number | ||
} | ||
|
||
export interface RetrievedNapseSpace extends BaseNapseSpace { | ||
uuid: string | ||
exchange_account: string | ||
delta?: number | ||
created_at: string | ||
statistics: Statistics | ||
wallet: Wallet | ||
// history: | ||
fleets: Fleet[] | ||
} | ||
|
||
|
||
|
||
|
||
export async function listSpace( | ||
searchParams: ReturnType<typeof useSearchParams> | ||
): Promise<AxiosResponse<NapseSpace[]>> { | ||
const response = await request(searchParams, 'GET', '/api/space/') | ||
return response as AxiosResponse<NapseSpace[]> | ||
} | ||
|
||
export async function getSpace( | ||
export async function retrieveSpace( | ||
searchParams: ReturnType<typeof useSearchParams>, | ||
id: string | ||
): Promise<AxiosResponse<NapseSpace>> { | ||
): Promise<AxiosResponse<RetrievedNapseSpace>> { | ||
const response = await request(searchParams, 'GET', `/api/space/${id}/`) | ||
return response as AxiosResponse<NapseSpace> | ||
return response as AxiosResponse<RetrievedNapseSpace> | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
export interface Currency{ | ||
ticker: string | ||
mbp: number | ||
amount: number | ||
} | ||
|
||
export interface Operation{ | ||
amount: number | ||
ticker: string | ||
operation_type: string | ||
created_at: string | ||
} | ||
|
||
export interface Wallet{ | ||
title: string | ||
value: string | ||
created_at: string | ||
currencies: Currency[] | ||
operations: Operation[] | ||
} |
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,64 +1,23 @@ | ||
import ValuePanelCard from '@/components/custom/panel/valuePanelCard' | ||
import ContextHeader from '@/components/layout/contextHeader' | ||
|
||
import { NapseSpace, listSpace } from '@/api/spaces/spaces' | ||
import { standardUrlPartial } from '@/lib/queryParams' | ||
import { AxiosResponse } from 'axios' | ||
import DefaultPageLayout from '@/components/layout/defaultPageLayout' | ||
import { useSearchParams } from 'next/navigation' | ||
import { useRouter } from 'next/router' | ||
import { useEffect, useState } from 'react' | ||
|
||
export default function Spaces(): JSX.Element { | ||
const [spaces, setSpaces] = useState<NapseSpace[]>([]) | ||
const searchParams = useSearchParams() | ||
useEffect(() => { | ||
const fetchServers = async () => { | ||
try { | ||
const response: AxiosResponse<NapseSpace[]> = | ||
await listSpace(searchParams) | ||
setSpaces(response.data) | ||
} catch (error) { | ||
console.error(error) | ||
setSpaces([]) | ||
} | ||
} | ||
if (searchParams.get('server')) { | ||
fetchServers() | ||
} | ||
}, [searchParams]) | ||
|
||
const router = useRouter() | ||
// const [Spaces, setSpaces] = useState<> | ||
|
||
return ( | ||
<ContextHeader isBot> | ||
<div className="mx-auto my-10 grid max-w-screen-xl gap-6 px-24 lg:grid-cols-3"> | ||
{spaces.map((space, index) => ( | ||
<ValuePanelCard | ||
key={index} | ||
title={space.name} | ||
value={space.value} | ||
delta={space.delta} | ||
// tooltip={space.tooltip} | ||
onClick={() => { | ||
router | ||
.push( | ||
standardUrlPartial( | ||
'/spaces/', | ||
space.uuid, | ||
{ | ||
exchangeAccount: space.exchange_account, | ||
space: space.uuid | ||
}, | ||
searchParams | ||
) | ||
) | ||
.catch((err) => { | ||
console.error(err) | ||
}) | ||
}} | ||
badge={String(space.fleet_count) + ' fleets'} | ||
/> | ||
))} | ||
</div> | ||
<DefaultPageLayout | ||
header={'Your spaces'} | ||
description={ | ||
'Here is an overview of all your spaces. A space make it easy to manage your money.' | ||
} | ||
> | ||
<></> | ||
</DefaultPageLayout> | ||
</ContextHeader> | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
import ValuePanelCard from '@/components/custom/panel/valuePanelCard' | ||
import ContextHeader from '@/components/layout/contextHeader' | ||
|
||
import { NapseSpace, listSpace } from '@/api/spaces/spaces' | ||
import { standardUrlPartial } from '@/lib/queryParams' | ||
import { AxiosResponse } from 'axios' | ||
import { useSearchParams } from 'next/navigation' | ||
import { useRouter } from 'next/router' | ||
import { useEffect, useState } from 'react' | ||
|
||
export default function Spaces(): JSX.Element { | ||
const [spaces, setSpaces] = useState<NapseSpace[]>([]) | ||
const searchParams = useSearchParams() | ||
useEffect(() => { | ||
const fetchServers = async () => { | ||
try { | ||
const response: AxiosResponse<NapseSpace[]> = | ||
await listSpace(searchParams) | ||
setSpaces(response.data) | ||
} catch (error) { | ||
console.error(error) | ||
setSpaces([]) | ||
} | ||
} | ||
if (searchParams.get('server')) { | ||
fetchServers() | ||
} | ||
}, [searchParams]) | ||
|
||
const router = useRouter() | ||
return ( | ||
<ContextHeader isBot> | ||
<div className="mx-auto my-10 grid max-w-screen-xl gap-6 px-24 lg:grid-cols-3"> | ||
{spaces.map((space, index) => ( | ||
<ValuePanelCard | ||
key={index} | ||
title={space.name} | ||
value={space.value} | ||
delta={space.delta} | ||
// tooltip={space.tooltip} | ||
onClick={() => { | ||
router | ||
.push( | ||
standardUrlPartial( | ||
'/spaces/', | ||
space.uuid, | ||
{ | ||
exchangeAccount: space.exchange_account, | ||
space: space.uuid | ||
}, | ||
searchParams | ||
) | ||
) | ||
.catch((err) => { | ||
console.error(err) | ||
}) | ||
}} | ||
badge={String(space.fleet_count) + ' fleets'} | ||
/> | ||
))} | ||
</div> | ||
</ContextHeader> | ||
) | ||
} |