Merge pull request #17 from Klectr/7-bug-broke_delete_button
fix: fix issue with delete button not working
This commit is contained in:
commit
908a8bc3bf
@ -1,4 +1,3 @@
|
|||||||
import { writeTextFile } from "@tauri-apps/api/fs"
|
|
||||||
import { createStore } from "kaioken"
|
import { createStore } from "kaioken"
|
||||||
|
|
||||||
export const useStationsStore = createStore(
|
export const useStationsStore = createStore(
|
||||||
@ -13,10 +12,15 @@ export const useStationsStore = createStore(
|
|||||||
//@ts-ignore
|
//@ts-ignore
|
||||||
return newState
|
return newState
|
||||||
},
|
},
|
||||||
delete: (stationId) =>
|
rmStation: (stationId): Station[] => {
|
||||||
set(
|
let newState: Station[] | null = null
|
||||||
(state) => state?.filter((station) => station.id !== stationId) ?? []
|
set((state) => {
|
||||||
),
|
newState = state?.filter((station) => station.id !== stationId) ?? []
|
||||||
|
return newState
|
||||||
|
})
|
||||||
|
//@ts-ignore
|
||||||
|
return newState
|
||||||
|
},
|
||||||
override: (stationsList: Station[]) => {
|
override: (stationsList: Station[]) => {
|
||||||
set((_state) => stationsList)
|
set((_state) => stationsList)
|
||||||
},
|
},
|
||||||
|
@ -1,14 +1,30 @@
|
|||||||
import { navigate } from "kaioken"
|
import { navigate } from "kaioken"
|
||||||
import { Station, useSelectStationStore } from "../hooks/stationStores"
|
import { Station, useSelectStationStore } from "../hooks/stationStores"
|
||||||
import { useStationsStore } from "../hooks/stationStores"
|
import { useStationsStore } from "../hooks/stationStores"
|
||||||
|
import { writeFile } from "@tauri-apps/api/fs"
|
||||||
|
import { useStorageStore } from "../hooks/storageStores"
|
||||||
|
|
||||||
export default function Main() {
|
export default function Main() {
|
||||||
const { make } = useSelectStationStore()
|
const { make } = useSelectStationStore()
|
||||||
const stations = useStationsStore.getState()
|
const { value, rmStation } = useStationsStore()
|
||||||
|
const { value: storageFile } = useStorageStore()
|
||||||
|
const stations = value
|
||||||
|
|
||||||
function _handleStationClick(station: Station) {
|
function _handleStationClick(station: Station) {
|
||||||
make(station)
|
return function() {
|
||||||
navigate('/player')
|
make(station)
|
||||||
|
navigate('/player')
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function _handleDeleteClick(s: Station) {
|
||||||
|
return function(ev: MouseEvent) {
|
||||||
|
ev.preventDefault()
|
||||||
|
ev.stopPropagation()
|
||||||
|
const newStations = rmStation(s.id)
|
||||||
|
if (!storageFile) return
|
||||||
|
writeFile(storageFile, JSON.stringify(newStations))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!stations?.length) {
|
if (!stations?.length) {
|
||||||
@ -33,11 +49,11 @@ export default function Main() {
|
|||||||
|
|
||||||
<div className="p-4 flex flex-col align-between h-full gap-2">
|
<div className="p-4 flex flex-col align-between h-full gap-2">
|
||||||
{stations.map((s) => (
|
{stations.map((s) => (
|
||||||
<button onclick={() => _handleStationClick(s)} className="paper p-2 flex flex-row border gap-4">
|
<button onclick={_handleStationClick(s)} className="paper p-2 flex flex-row border gap-4">
|
||||||
<img src={s.avatar} width={40} height={40} className="w-20 rounded-xl" />
|
<img src={s.avatar} width={40} height={40} className="w-20 rounded-xl" />
|
||||||
<div className="flex flex-col gap-2 w-full">
|
<div className="flex flex-col gap-2 w-full">
|
||||||
<h2 className="text-xl">{s.title}</h2>
|
<h2 className="text-xl">{s.title}</h2>
|
||||||
<button className="border border-red-500 rounded w-full text-red-500 px-4">Delete</button>
|
<button onclick={_handleDeleteClick(s)} className="border border-red-500 rounded w-full text-red-500 px-4 hover:bg-red-500 hover:text-white">Delete</button>
|
||||||
</div>
|
</div>
|
||||||
</button>
|
</button>
|
||||||
))}
|
))}
|
||||||
|
Loading…
Reference in New Issue
Block a user