diff --git a/client/src/api.ts b/client/src/api.ts index b162fff..3ab437b 100644 --- a/client/src/api.ts +++ b/client/src/api.ts @@ -130,7 +130,7 @@ export function checkQueryElem(elem: any): boolean { }); } return (elem.childrenOperator && elem.children) || - (elem.prop && elem.propOperand && elem.propOperator) || + ("prop" in elem && "propOperand" in elem && "propOperator" in elem) || Object.keys(elem).length === 0; } export function checkQueryRequest(req: any): boolean { diff --git a/client/src/components/MainWindow.tsx b/client/src/components/MainWindow.tsx index d3c22cd..052a319 100644 --- a/client/src/components/MainWindow.tsx +++ b/client/src/components/MainWindow.tsx @@ -5,7 +5,7 @@ import AppBar from './appbar/AppBar'; import QueryWindow, { QueryWindowReducer, QueryWindowState } from './windows/QueryWindow'; import { NewTabProps } from './appbar/AddTabMenu'; import { newWindowState, newWindowReducer, WindowState, WindowType } from './windows/Windows'; -import EditArtistWindow from './windows/EditArtistWindow'; +import ArtistWindow from './windows/ArtistWindow'; var _ = require('lodash'); const darkTheme = createMuiTheme({ @@ -99,8 +99,8 @@ export default function MainWindow(props: any) { state={tabState} dispatch={tabDispatch} /> - case WindowType.EditArtist: - return diff --git a/client/src/components/appbar/AddTabMenu.tsx b/client/src/components/appbar/AddTabMenu.tsx index fb79682..f2ce996 100644 --- a/client/src/components/appbar/AddTabMenu.tsx +++ b/client/src/components/appbar/AddTabMenu.tsx @@ -23,7 +23,7 @@ export default function AddTabMenu(props: IProps) { New Tab {([ WindowType.Query, - WindowType.EditArtist + WindowType.Artist ]).map((v: WindowType) => { props.onClose(); diff --git a/client/src/components/windows/ArtistWindow.tsx b/client/src/components/windows/ArtistWindow.tsx new file mode 100644 index 0000000..5bb0825 --- /dev/null +++ b/client/src/components/windows/ArtistWindow.tsx @@ -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 + + {metadata && metadata.name} + + +} \ No newline at end of file diff --git a/client/src/components/windows/EditArtistWindow.tsx b/client/src/components/windows/EditArtistWindow.tsx deleted file mode 100644 index ba512a4..0000000 --- a/client/src/components/windows/EditArtistWindow.tsx +++ /dev/null @@ -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 - - Hello! - - -} \ No newline at end of file diff --git a/client/src/components/windows/Windows.tsx b/client/src/components/windows/Windows.tsx index d052ee3..a9a48c1 100644 --- a/client/src/components/windows/Windows.tsx +++ b/client/src/components/windows/Windows.tsx @@ -1,16 +1,16 @@ import { QueryWindowReducer, QueryWindowState } from "./QueryWindow"; -import { EditArtistWindowReducer, EditArtistWindowState } from "./EditArtistWindow"; +import { ArtistWindowReducer, ArtistWindowState } from "./ArtistWindow"; export enum WindowType { Query = "Query", - EditArtist = "EditArtist", + Artist = "Artist", } -export type WindowState = QueryWindowState | EditArtistWindowState; +export type WindowState = QueryWindowState | ArtistWindowState; export const newWindowReducer = { [WindowType.Query]: QueryWindowReducer, - [WindowType.EditArtist]: EditArtistWindowReducer, + [WindowType.Artist]: ArtistWindowReducer, } export const newWindowState = { @@ -21,7 +21,10 @@ export const newWindowState = { resultsForQuery: null, }; }, - [WindowType.EditArtist]: () => { - + [WindowType.Artist]: () => { + return { + artistId: 1, + metadata: null, + } } } \ No newline at end of file diff --git a/server/endpoints/QueryEndpointHandler.ts b/server/endpoints/QueryEndpointHandler.ts index 0aed145..e0ca7ec 100644 --- a/server/endpoints/QueryEndpointHandler.ts +++ b/server/endpoints/QueryEndpointHandler.ts @@ -377,6 +377,8 @@ export const QueryEndpointHandler: EndpointHandler = async (req: any, res: any, }), } + console.log("Query repsonse", response); + res.send(response); } catch (e) { catchUnhandledErrors(e);