Add create market form
This commit is contained in:
		
							parent
							
								
									cdeb088a13
								
							
						
					
					
						commit
						0230182ef5
					
				@ -3,26 +3,53 @@
 | 
				
			|||||||
    <li class="my-3" v-for="market in markets" :key="market.Id">
 | 
					    <li class="my-3" v-for="market in markets" :key="market.Id">
 | 
				
			||||||
      <router-link :to="'/market/' + market.Id">{{ market.Description }}</router-link>
 | 
					      <router-link :to="'/market/' + market.Id">{{ market.Description }}</router-link>
 | 
				
			||||||
    </li>
 | 
					    </li>
 | 
				
			||||||
    <button>+ create market</button>
 | 
					 | 
				
			||||||
  </ul>
 | 
					  </ul>
 | 
				
			||||||
 | 
					  <button v-if="!showForm" @click.prevent="toggleForm">+ create market</button>
 | 
				
			||||||
 | 
					  <div class="flex flex-col justify-center" v-else>
 | 
				
			||||||
 | 
					    <div class="my-1 text-center">+ create market</div>
 | 
				
			||||||
 | 
					    <form ref="form" class="mx-auto text-left" method="post" action="/api/market" @submit.prevent="submitForm">
 | 
				
			||||||
 | 
					      <label class="mx-1" for="desc">description</label>
 | 
				
			||||||
 | 
					      <input v-model="description" class="mx-1" id="desc" name="desc" type="text">
 | 
				
			||||||
 | 
					      <button class="mx-1" type="submit">submit</button>
 | 
				
			||||||
 | 
					    </form>
 | 
				
			||||||
 | 
					  </div>
 | 
				
			||||||
</template>
 | 
					</template>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
<script setup>
 | 
					<script setup>
 | 
				
			||||||
import { ref } from 'vue'
 | 
					import { ref } from 'vue'
 | 
				
			||||||
 | 
					
 | 
				
			||||||
const markets = ref([])
 | 
					const markets = ref([])
 | 
				
			||||||
 | 
					const form = ref(null)
 | 
				
			||||||
const url = window.origin + '/api/markets'
 | 
					const description = ref(null)
 | 
				
			||||||
 | 
					const showForm = ref(false)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// TODO only load markets once per session
 | 
					// TODO only load markets once per session
 | 
				
			||||||
 | 
					const url = window.origin + '/api/markets'
 | 
				
			||||||
await fetch(url).then(async r => {
 | 
					await fetch(url).then(async r => {
 | 
				
			||||||
  const body = await r.json()
 | 
					  const body = await r.json()
 | 
				
			||||||
  markets.value = body
 | 
					  markets.value = body
 | 
				
			||||||
})
 | 
					})
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					const toggleForm = () => {
 | 
				
			||||||
 | 
					  description.value = null
 | 
				
			||||||
 | 
					  showForm.value = !showForm.value
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					const submitForm = async () => {
 | 
				
			||||||
 | 
					  const url = window.origin + '/api/market'
 | 
				
			||||||
 | 
					  const body = JSON.stringify({ description: description.value })
 | 
				
			||||||
 | 
					  await fetch(url, { method: 'post', body })
 | 
				
			||||||
 | 
					  toggleForm()
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
</script>
 | 
					</script>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
<style scoped>
 | 
					<style scoped>
 | 
				
			||||||
 | 
					input {
 | 
				
			||||||
 | 
					  padding: 0 0.3em;
 | 
				
			||||||
 | 
					  color: #000;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
a {
 | 
					a {
 | 
				
			||||||
  padding: 0 1em;
 | 
					  padding: 0 1em;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user