Skip to content

Commit

Permalink
feat(server-routes): add cookies tab (#338)
Browse files Browse the repository at this point in the history
  • Loading branch information
arashsheyda committed Jul 23, 2023
1 parent 934b1d4 commit 33e1417
Show file tree
Hide file tree
Showing 3 changed files with 69 additions and 2 deletions.
68 changes: 68 additions & 0 deletions packages/devtools/client/components/ServerRouteDetails.vue
Original file line number Diff line number Diff line change
Expand Up @@ -243,13 +243,45 @@ const tabs = computed(() => {
slug: 'headers',
length: routeInputs.headers.length,
})
items.push({
name: 'Cookies',
slug: 'cookies',
})
items.push({
name: 'Snippets',
slug: 'snippet',
})
return items
})
const cookies = ref(getCookies())
function getCookies() {
return document.cookie.split('; ').map((i) => {
const [key, value] = i.split('=')
return { key, value }
})
}
const newCookie = reactive({ key: '', value: '' })
function updateCookie(key: string, value: any) {
if (!key)
return
const exist = cookies.value.find(cookie => cookie.key === key)
const cookie = useCookie(key)
if (exist !== undefined) {
if (value === undefined)
cookies.value = cookies.value.filter(cookie => cookie.key !== key)
}
else {
cookies.value.push({ key, value })
newCookie.key = ''
newCookie.value = ''
}
cookie.value = value
}
watchEffect(() => {
if (selectedTabInput.value === 'json') {
if (typeof routeInputBodyJSON.value === 'string')
Expand Down Expand Up @@ -320,6 +352,42 @@ watchEffect(() => {
/>
</template>
</div>
<div
v-if="activeTab === 'cookies'"
border="b base" p4 flex="~ col gap-4" font-mono
>
<div v-for="cookie in cookies" :key="cookie.key" flex="~ gap-4 items-center">
<NTextInput
placeholder="Key..."
:model-value="cookie.key"
disabled op-70
/>
<NTextInput
placeholder="Value..."
:model-value="cookie.value"
flex-1 n="primary"
@input="updateCookie(cookie.key, $event.target?.value)"
/>
<NButton title="Delete" n="red" @click="updateCookie(cookie.key, undefined)">
<NIcon icon="i-carbon-delete" />
</NButton>
</div>
<div flex="~ gap-4">
<NTextInput
v-model="newCookie.key"
placeholder="Key"
n="primary" flex-1
/>
<NTextInput
v-model="newCookie.value"
placeholder="Value"
n="primary" flex-1
/>
<NButton title="Add" n="primary" @click="updateCookie(newCookie.key, newCookie.value)">
<NIcon icon="i-carbon-save" />
</NButton>
</div>
</div>
<DefineDefaultInputs>
<ServerRouteInputs v-model="currentParams" :default="{ type: 'string' }" max-h-xs of-auto>
<template v-if="inputDefaults[activeTab]?.length">
Expand Down
2 changes: 0 additions & 2 deletions packages/devtools/client/components/ServerRouteInputs.vue
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
<!-- eslint-disable no-console -->
<script setup lang="ts">
const props = withDefaults(defineProps<{
modelValue: any
Expand Down Expand Up @@ -53,7 +52,6 @@ watch(() => params, (items) => {
}
else if (item.type === 'date' && typeof item.value === 'string' && !item.value.match(/^\d{4}-\d{2}-\d{2}$/)) {
item.value = new Date().toISOString().slice(0, 10)
console.log('date', item.value)
}
else if (item.type === 'time' && typeof item.value === 'string' && !item.value.match(/^\d{2}:\d{2}$/)) {
item.value = new Date().toISOString().slice(11, 16)
Expand Down
1 change: 1 addition & 0 deletions packages/devtools/client/composables/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ export const ComposablesDocs = {
export const ServerRouteTabIcons: Record<string, string> = {
snippet: 'i-carbon-code',
headers: 'i-carbon-html-reference',
cookies: 'i-carbon-cookie',
params: 'i-carbon-text-selection',
query: 'i-carbon-help',
body: 'i-carbon-document',
Expand Down

0 comments on commit 33e1417

Please sign in to comment.