import React, {useState} from 'react'
import Router from 'next/router'
import Link from 'next/link'
import axios from 'axios'
import {Button} from '@rmwc/button'
import ActionBar from '~/components/admin/actionBar'
import Table from '~/components/table'
Items.getInitialProps = async ({ctx}) => {
const {data: items} = await ctx.axios.get('/api/items?showUnpublished=true')
return {items}
}
export default function Items({items: _items}){
const [items, setItems] = useState(_items)
const updateItem = newItem => setItems(items=>items.map(i => {
if(i.uuid === newItem.uuid)
return newItem
return i
}))
const publish = item => async () => {
const {data: newItem} = await axios.post(`/api/items/${item.uuid}/publish`)
updateItem(newItem)
}
const unpublish = item => async () => {
const {data: newItem} = await axios.post(`/api/items/${item.uuid}/unpublish`)
updateItem(newItem)
}
return (
<>