mirror of
https://github.com/Myxelium/Bridge-Multi.git
synced 2026-04-23 02:45:09 +00:00
[Library] Add Infinite Scrolling
Add infinite scrolling and fix selecting rows
This commit is contained in:
@@ -1,7 +1,8 @@
|
||||
import { ChartData } from 'src-shared/interfaces/search.interface.js'
|
||||
import { ChartData, LibrarySearch } from 'src-shared/interfaces/search.interface.js'
|
||||
import { Like } from 'typeorm'
|
||||
|
||||
import { dataSource } from './dataSource.js'
|
||||
import { Chart } from './entities/Chart.js'
|
||||
import { Like } from 'typeorm'
|
||||
|
||||
export class DatabaseService {
|
||||
async insertChart(chartData: ChartData): Promise<ChartData> {
|
||||
@@ -12,7 +13,6 @@ export class DatabaseService {
|
||||
|
||||
const chartRepository = dataSource.getRepository(Chart)
|
||||
|
||||
// if one already exist dont create
|
||||
const existingChart = await chartRepository.findOneBy({ md5: chartData.md5 })
|
||||
|
||||
if (existingChart) {
|
||||
@@ -61,7 +61,6 @@ export class DatabaseService {
|
||||
|
||||
const chartRepository = dataSource.getRepository(Chart)
|
||||
|
||||
// delete the array of charts provided using querybulilder
|
||||
charts.forEach(async chart => {
|
||||
console.log('removing chart:', chart.name)
|
||||
await chartRepository.delete({ md5: chart.md5 })
|
||||
@@ -72,7 +71,7 @@ export class DatabaseService {
|
||||
}
|
||||
}
|
||||
|
||||
async getChartsBySearchTerm(searchTerm?: string): Promise<ChartData[]> {
|
||||
async getChartsBySearchTerm(search: LibrarySearch): Promise<ChartData[]> {
|
||||
try {
|
||||
if (!dataSource.isInitialized) {
|
||||
await dataSource.initialize()
|
||||
@@ -82,22 +81,27 @@ export class DatabaseService {
|
||||
|
||||
let charts: Chart[]
|
||||
|
||||
if (searchTerm) {
|
||||
const likeSearchTerm = `%${searchTerm}%`
|
||||
if (search.searchTerm?.trim()) {
|
||||
const likeSearchTerm = Like(`%${search.searchTerm}%`)
|
||||
|
||||
charts = await chartRepository.find({
|
||||
where: [
|
||||
{ name: Like(likeSearchTerm) },
|
||||
{ album: Like(likeSearchTerm) },
|
||||
{ artist: Like(likeSearchTerm) },
|
||||
{ genre: Like(likeSearchTerm) },
|
||||
{ year: Like(likeSearchTerm) },
|
||||
{ charter: Like(likeSearchTerm) },
|
||||
{ name: likeSearchTerm },
|
||||
{ album: likeSearchTerm },
|
||||
{ artist: likeSearchTerm },
|
||||
{ genre: likeSearchTerm },
|
||||
{ year: likeSearchTerm },
|
||||
{ charter: likeSearchTerm },
|
||||
],
|
||||
skip: (search.page - 1) * search.pageSize,
|
||||
take: search.pageSize,
|
||||
})
|
||||
} else {
|
||||
charts = await chartRepository.find()
|
||||
charts = await chartRepository.find({
|
||||
skip: (search.page - 1) * search.pageSize,
|
||||
take: search.pageSize,
|
||||
})
|
||||
}
|
||||
|
||||
return charts as unknown as ChartData[]
|
||||
} catch (error) {
|
||||
console.error('Error fetching charts by search term:', error)
|
||||
@@ -119,7 +123,6 @@ export class DatabaseService {
|
||||
throw error
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
export const databaseService = new DatabaseService()
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import { ChartData, LibrarySearch } from 'src-shared/interfaces/search.interface.js'
|
||||
|
||||
import { databaseService } from '../database/databaseService.js'
|
||||
import { ChartData } from 'src-shared/interfaces/search.interface.js'
|
||||
|
||||
export async function addChart(chartData: ChartData): Promise<ChartData> {
|
||||
try {
|
||||
@@ -37,9 +38,9 @@ export async function removeAllCharts(): Promise<void> {
|
||||
}
|
||||
}
|
||||
|
||||
export async function getChartsBySearchTerm(searchTerm?: string): Promise<ChartData[]> {
|
||||
export async function getChartsBySearchTerm(search: LibrarySearch): Promise<ChartData[]> {
|
||||
try {
|
||||
return await databaseService.getChartsBySearchTerm(searchTerm)
|
||||
return await databaseService.getChartsBySearchTerm(search)
|
||||
} catch (error) {
|
||||
console.error('Error in getChartsHandler:', error)
|
||||
throw error
|
||||
|
||||
Reference in New Issue
Block a user