Don't remember what I was doing here

editsong
Sander Vocke 4 years ago
parent d1ad2a0bdf
commit c19fcbf9d6
  1. 3
      client/src/api/endpoints/resources.ts
  2. 5
      client/src/api/types/resources.ts
  3. 20
      client/src/components/windows/track/TrackWindow.tsx
  4. 4
      server/db/Track.ts
  5. 3
      server/endpoints/Track.ts

@ -22,6 +22,7 @@ import {
Tag, Tag,
TagBaseWithRefs, TagBaseWithRefs,
TagWithRefs, TagWithRefs,
Track,
TrackBaseWithRefs, TrackBaseWithRefs,
TrackWithDetails, TrackWithDetails,
TrackWithRefs TrackWithRefs
@ -47,7 +48,7 @@ import {
// Get track details (GET). // Get track details (GET).
export const GetTrackEndpoint = '/track/:id'; export const GetTrackEndpoint = '/track/:id';
export type GetTrackResponse = TrackWithDetails; export type GetTrackResponse = Track;
// Get artist details (GET). // Get artist details (GET).
export const GetArtistEndpoint = '/artist/:id'; export const GetArtistEndpoint = '/artist/:id';

@ -35,6 +35,8 @@ export interface TrackWithRefs extends TrackBaseWithRefs {
export interface Track extends TrackBase { export interface Track extends TrackBase {
name: string, name: string,
album: AlbumWithId | null, album: AlbumWithId | null,
artists: ArtistWithId[],
tags: TagWithId[],
} }
export interface TrackWithRefsWithId extends TrackWithRefs { export interface TrackWithRefsWithId extends TrackWithRefs {
id: number, id: number,
@ -131,6 +133,7 @@ export interface AlbumWithRefs extends AlbumBaseWithRefs {
} }
export interface Album extends AlbumBase { export interface Album extends AlbumBase {
name: string, name: string,
artists: ArtistWithId[],
} }
export interface AlbumWithRefsWithId extends AlbumWithRefs { export interface AlbumWithRefsWithId extends AlbumWithRefs {
id: number, id: number,
@ -170,7 +173,7 @@ export interface TagWithRefs extends TagBaseWithRefs {
name: string, name: string,
parentId: number | null, parentId: number | null,
} }
export interface Tag extends TagBase { export interface Tag extends TagBaseWithDetails {
name: string, name: string,
} }
export interface TagWithRefsWithId extends TagWithRefs { export interface TagWithRefsWithId extends TagWithRefs {

@ -14,12 +14,11 @@ import { useParams } from 'react-router';
import EditTrackDialog from './EditTrackDialog'; import EditTrackDialog from './EditTrackDialog';
import EditIcon from '@material-ui/icons/Edit'; import EditIcon from '@material-ui/icons/Edit';
import { modifyTrack } from '../../../lib/saveChanges'; import { modifyTrack } from '../../../lib/saveChanges';
import { getTrack } from '../../../lib/backend/tracks';
export type TrackMetadata = serverApi.TrackWithDetails;
export interface TrackWindowState extends WindowState { export interface TrackWindowState extends WindowState {
id: number, id: number,
metadata: TrackMetadata | null, metadata: serverApi.Track | null,
} }
export enum TrackWindowStateActions { export enum TrackWindowStateActions {
@ -38,17 +37,6 @@ export function TrackWindowReducer(state: TrackWindowState, action: any) {
} }
} }
export async function getTrackMetadata(id: number) {
let response: any = await queryTracks(
{
a: QueryLeafBy.TrackId,
b: id,
leafOp: QueryLeafOp.Equals,
}, 0, 1, serverApi.QueryResponseType.Details
);
return response[0];
}
export default function TrackWindow(props: {}) { export default function TrackWindow(props: {}) {
const { id } = useParams<{ id: string }>(); const { id } = useParams<{ id: string }>();
const [state, dispatch] = useReducer(TrackWindowReducer, { const [state, dispatch] = useReducer(TrackWindowReducer, {
@ -69,8 +57,8 @@ export function TrackWindowControlled(props: {
useEffect(() => { useEffect(() => {
if (metadata === null) { if (metadata === null) {
getTrackMetadata(trackId) getTrack(trackId)
.then((m: TrackMetadata) => { .then((m: serverApi.Track) => {
dispatch({ dispatch({
type: TrackWindowStateActions.SetMetadata, type: TrackWindowStateActions.SetMetadata,
value: m value: m

@ -1,5 +1,5 @@
import Knex from "knex"; import Knex from "knex";
import { TrackBaseWithRefs, TrackWithDetails, TrackWithRefs } from "../../client/src/api/api"; import { Track, TrackBaseWithRefs, TrackWithDetails, TrackWithRefs } from "../../client/src/api/api";
import * as api from '../../client/src/api/api'; import * as api from '../../client/src/api/api';
import asJson from "../lib/asJson"; import asJson from "../lib/asJson";
import { DBError, DBErrorKind } from "../endpoints/types"; import { DBError, DBErrorKind } from "../endpoints/types";
@ -8,7 +8,7 @@ var _ = require('lodash')
// Returns an track with details, or null if not found. // Returns an track with details, or null if not found.
export async function getTrack(id: number, userId: number, knex: Knex): export async function getTrack(id: number, userId: number, knex: Knex):
Promise<TrackWithDetails> { Promise<Track> {
// Start transfers for tracks, tags and artists. // Start transfers for tracks, tags and artists.
// Also request the track itself. // Also request the track itself.
const tagsPromise: Promise<api.TagWithId[]> = const tagsPromise: Promise<api.TagWithId[]> =

@ -3,6 +3,7 @@ import { EndpointError, EndpointHandler, handleErrorsInEndpoint } from './types'
import Knex from 'knex'; import Knex from 'knex';
import asJson from '../lib/asJson'; import asJson from '../lib/asJson';
import { createTrack, deleteTrack, getTrack, modifyTrack } from '../db/Track'; import { createTrack, deleteTrack, getTrack, modifyTrack } from '../db/Track';
import { Track } from '../../client/src/api/api';
export const PostTrack: EndpointHandler = async (req: any, res: any, knex: Knex) => { export const PostTrack: EndpointHandler = async (req: any, res: any, knex: Knex) => {
if (!api.checkPostTrackRequest(req.body)) { if (!api.checkPostTrackRequest(req.body)) {
@ -34,7 +35,7 @@ export const GetTrack: EndpointHandler = async (req: any, res: any, knex: Knex)
let id = parseInt(req.params.id); let id = parseInt(req.params.id);
try { try {
let track = await getTrack(id, userId, knex); let track: Track = await getTrack(id, userId, knex);
await res.status(200).send(track); await res.status(200).send(track);
} catch (e) { } catch (e) {
handleErrorsInEndpoint(e) handleErrorsInEndpoint(e)

Loading…
Cancel
Save