parent
80f35e031b
commit
d4d4c67672
7 changed files with 107 additions and 40 deletions
@ -0,0 +1,91 @@ |
||||
import React, { useEffect } from 'react'; |
||||
import { Box } from '@material-ui/core'; |
||||
import * as serverApi from '../../api'; |
||||
|
||||
export interface ArtistMetadata { |
||||
name: string, |
||||
} |
||||
|
||||
export interface ArtistWindowState { |
||||
artistId: number, |
||||
metadata: ArtistMetadata | null, |
||||
} |
||||
|
||||
export enum ArtistWindowStateActions { |
||||
SetMetadata = "SetMetadata", |
||||
} |
||||
|
||||
export function ArtistWindowReducer(state: ArtistWindowState, action: any) { |
||||
switch (action.type) { |
||||
case ArtistWindowStateActions.SetMetadata: |
||||
return { ...state, metadata: action.value } |
||||
default: |
||||
throw new Error("Unimplemented QueryWindow state update.") |
||||
} |
||||
} |
||||
|
||||
export interface IProps { |
||||
state: ArtistWindowState, |
||||
dispatch: (action: any) => void |
||||
} |
||||
|
||||
export async function getArtistMetadata(id: number) { |
||||
const query = { |
||||
prop: serverApi.QueryElemProperty.artistId, |
||||
propOperand: id, |
||||
propOperator: serverApi.QueryFilterOp.Eq, |
||||
}; |
||||
|
||||
var q: serverApi.QueryRequest = { |
||||
query: query, |
||||
offsetsLimits: { |
||||
artistOffset: 0, |
||||
artistLimit: 1, |
||||
}, |
||||
ordering: { |
||||
orderBy: { |
||||
type: serverApi.OrderByType.Name, |
||||
}, |
||||
ascending: true, |
||||
}, |
||||
}; |
||||
|
||||
const requestOpts = { |
||||
method: 'POST', |
||||
headers: { 'Content-Type': 'application/json' }, |
||||
body: JSON.stringify(q), |
||||
}; |
||||
|
||||
return (async () => { |
||||
const response = await fetch((process.env.REACT_APP_BACKEND || "") + serverApi.QueryEndpoint, requestOpts) |
||||
let json: any = await response.json(); |
||||
let artist = json.artists[0]; |
||||
return { |
||||
name: artist.name |
||||
} |
||||
})(); |
||||
} |
||||
|
||||
export default function ArtistWindow(props: IProps) { |
||||
let metadata = props.state.metadata; |
||||
|
||||
useEffect(() => { |
||||
getArtistMetadata(props.state.artistId) |
||||
.then((m: ArtistMetadata) => { |
||||
console.log("metadata", m); |
||||
props.dispatch({ |
||||
type: ArtistWindowStateActions.SetMetadata, |
||||
value: m |
||||
}); |
||||
}) |
||||
}, []); |
||||
|
||||
return <Box width="100%" justifyContent="center" display="flex" flexWrap="wrap"> |
||||
<Box |
||||
m={1} |
||||
width="80%" |
||||
> |
||||
{metadata && metadata.name} |
||||
</Box> |
||||
</Box> |
||||
} |
@ -1,29 +0,0 @@ |
||||
import React from 'react'; |
||||
import { Box } from '@material-ui/core'; |
||||
|
||||
export interface EditArtistWindowState { |
||||
|
||||
} |
||||
|
||||
export enum EditArtistWindowStateActions { |
||||
} |
||||
|
||||
export function EditArtistWindowReducer(state: EditArtistWindowState, action: any) { |
||||
return state; |
||||
} |
||||
|
||||
export interface IProps { |
||||
state: EditArtistWindowState, |
||||
dispatch: (action: any) => void |
||||
} |
||||
|
||||
export default function EditArtistWindow(props: IProps) { |
||||
return <Box width="100%" justifyContent="center" display="flex" flexWrap="wrap"> |
||||
<Box |
||||
m={1} |
||||
width="80%" |
||||
> |
||||
Hello! |
||||
</Box> |
||||
</Box> |
||||
} |
Loading…
Reference in new issue