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,
TagBaseWithRefs,
TagWithRefs,
Track,
TrackBaseWithRefs,
TrackWithDetails,
TrackWithRefs
@ -47,7 +48,7 @@ import {
// Get track details (GET).
export const GetTrackEndpoint = '/track/:id';
export type GetTrackResponse = TrackWithDetails;
export type GetTrackResponse = Track;
// Get artist details (GET).
export const GetArtistEndpoint = '/artist/:id';

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

@ -14,12 +14,11 @@ import { useParams } from 'react-router';
import EditTrackDialog from './EditTrackDialog';
import EditIcon from '@material-ui/icons/Edit';
import { modifyTrack } from '../../../lib/saveChanges';
export type TrackMetadata = serverApi.TrackWithDetails;
import { getTrack } from '../../../lib/backend/tracks';
export interface TrackWindowState extends WindowState {
id: number,
metadata: TrackMetadata | null,
metadata: serverApi.Track | null,
}
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: {}) {
const { id } = useParams<{ id: string }>();
const [state, dispatch] = useReducer(TrackWindowReducer, {
@ -69,8 +57,8 @@ export function TrackWindowControlled(props: {
useEffect(() => {
if (metadata === null) {
getTrackMetadata(trackId)
.then((m: TrackMetadata) => {
getTrack(trackId)
.then((m: serverApi.Track) => {
dispatch({
type: TrackWindowStateActions.SetMetadata,
value: m

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

@ -3,6 +3,7 @@ import { EndpointError, EndpointHandler, handleErrorsInEndpoint } from './types'
import Knex from 'knex';
import asJson from '../lib/asJson';
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) => {
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);
try {
let track = await getTrack(id, userId, knex);
let track: Track = await getTrack(id, userId, knex);
await res.status(200).send(track);
} catch (e) {
handleErrorsInEndpoint(e)

Loading…
Cancel
Save