chore: improve cookie modal ui (#3495)
This commit is contained in:
@@ -59,15 +59,17 @@
|
|||||||
"modal": {
|
"modal": {
|
||||||
"new_domain_name": "New domain name",
|
"new_domain_name": "New domain name",
|
||||||
"set": "Set a cookie",
|
"set": "Set a cookie",
|
||||||
"cookie_string": "Set-Cookie string",
|
"cookie_string": "Cookie string",
|
||||||
|
"enter_cookie_string": "Enter cookie string",
|
||||||
"cookie_name": "Name",
|
"cookie_name": "Name",
|
||||||
"cookie_value": "Value",
|
"cookie_value": "Value",
|
||||||
"cookie_path": "Path",
|
"cookie_path": "Path",
|
||||||
"cookie_expires": "Expires",
|
"cookie_expires": "Expires",
|
||||||
"managed_tab": "Managed",
|
"managed_tab": "Managed",
|
||||||
"raw_tab": "Raw",
|
"raw_tab": "Raw",
|
||||||
"interceptor_no_support": "Your currently selected interceptor does not support cookies.",
|
"interceptor_no_support": "Your currently selected interceptor does not support cookies. Select a different Interceptor and try again.",
|
||||||
"no_domains": "No domains defined",
|
"empty_domains": "Domain list is empty",
|
||||||
|
"empty_domain": "Domain is empty",
|
||||||
"no_cookies_in_domain": "No cookies set for this domain"
|
"no_cookies_in_domain": "No cookies set for this domain"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -7,91 +7,105 @@
|
|||||||
@close="hideModal"
|
@close="hideModal"
|
||||||
>
|
>
|
||||||
<template #body>
|
<template #body>
|
||||||
<div
|
<HoppSmartPlaceholder
|
||||||
v-if="!currentInterceptorSupportsCookies"
|
v-if="!currentInterceptorSupportsCookies"
|
||||||
class="flex flex-col gap-2 p-5 items-center"
|
:text="t('cookies.modal.interceptor_no_support')"
|
||||||
>
|
>
|
||||||
<icon-lucide-info />
|
<AppInterceptor class="p-2 border rounded border-dividerLight" />
|
||||||
{{ t("cookies.modal.interceptor_no_support") }}
|
</HoppSmartPlaceholder>
|
||||||
</div>
|
<div v-else class="flex flex-col">
|
||||||
|
|
||||||
<div class="flex gap-x-2 border-b border-dividerLight pb-3">
|
|
||||||
<HoppSmartInput
|
|
||||||
v-model="newDomainText"
|
|
||||||
class="flex-grow"
|
|
||||||
:placeholder="t('cookies.modal.new_domain_name')"
|
|
||||||
/>
|
|
||||||
<HoppButtonSecondary
|
|
||||||
outline
|
|
||||||
filled
|
|
||||||
:label="t('action.add')"
|
|
||||||
@click="addNewDomain"
|
|
||||||
/>
|
|
||||||
</div>
|
|
||||||
<div class="pt-3 flex flex-col gap-y-6">
|
|
||||||
<div
|
<div
|
||||||
v-if="workingCookieJar.size === 0"
|
class="flex bg-primary space-x-2 border-b sticky border-dividerLight -mx-4 px-4 py-4 -mt-4"
|
||||||
class="flex flex-col items-center p-5 gap-2"
|
style="top: calc(-1 * var(--line-height-body))"
|
||||||
>
|
>
|
||||||
<icon-lucide-info />
|
<HoppSmartInput
|
||||||
{{ t("cookies.modal.no_domains") }}
|
v-model="newDomainText"
|
||||||
|
class="flex-1"
|
||||||
|
:placeholder="t('cookies.modal.new_domain_name')"
|
||||||
|
@keyup.enter="addNewDomain"
|
||||||
|
/>
|
||||||
|
<HoppButtonSecondary
|
||||||
|
outline
|
||||||
|
filled
|
||||||
|
:label="t('action.add')"
|
||||||
|
@click="addNewDomain"
|
||||||
|
/>
|
||||||
</div>
|
</div>
|
||||||
<div
|
<div class="flex flex-col space-y-4">
|
||||||
v-else
|
<HoppSmartPlaceholder
|
||||||
v-for="[domain, entries] in workingCookieJar.entries()"
|
v-if="workingCookieJar.size === 0"
|
||||||
:key="domain"
|
:src="`/images/states/${colorMode.value}/blockchain.svg`"
|
||||||
class="flex flex-col gap-y-2"
|
:alt="`${t('cookies.modal.empty_domains')}`"
|
||||||
>
|
:text="t('cookies.modal.empty_domains')"
|
||||||
<div class="flex items-center justify-between">
|
class="mt-6"
|
||||||
<h3>{{ domain }}</h3>
|
>
|
||||||
<div>
|
</HoppSmartPlaceholder>
|
||||||
<HoppButtonSecondary
|
<div
|
||||||
:icon="IconTrash2"
|
v-for="[domain, entries] in workingCookieJar.entries()"
|
||||||
@click="deleteDomain(domain)"
|
v-else
|
||||||
/>
|
:key="domain"
|
||||||
<HoppButtonSecondary
|
class="flex flex-col"
|
||||||
:icon="IconPlus"
|
>
|
||||||
@click="addCookieToDomain(domain)"
|
<div class="flex items-center justify-between flex-1">
|
||||||
/>
|
<label for="cookiesList" class="p-4">
|
||||||
</div>
|
{{ domain }}
|
||||||
</div>
|
</label>
|
||||||
|
<div class="flex">
|
||||||
<div class="border rounded border-divider">
|
<HoppButtonSecondary
|
||||||
<div class="divide-y divide-dividerLight">
|
v-tippy="{ theme: 'tooltip' }"
|
||||||
<div
|
:title="t('action.delete')"
|
||||||
v-if="entries.length === 0"
|
:icon="IconTrash2"
|
||||||
class="flex flex-col items-center p-5 gap-2"
|
@click="deleteDomain(domain)"
|
||||||
>
|
/>
|
||||||
<icon-lucide-info />
|
<HoppButtonSecondary
|
||||||
{{ t("cookies.modal.no_cookies_in_domain") }}
|
v-tippy="{ theme: 'tooltip' }"
|
||||||
|
:title="t('add.new')"
|
||||||
|
:icon="IconPlus"
|
||||||
|
@click="addCookieToDomain(domain)"
|
||||||
|
/>
|
||||||
</div>
|
</div>
|
||||||
<div
|
</div>
|
||||||
v-else
|
<div class="border rounded border-divider">
|
||||||
v-for="(entry, entryIndex) in entries"
|
<div class="divide-y divide-dividerLight">
|
||||||
:key="`${entry}-${entryIndex}`"
|
<div
|
||||||
class="flex divide-x divide-dividerLight"
|
v-if="entries.length === 0"
|
||||||
>
|
class="flex flex-col gap-2 p-4 items-center"
|
||||||
<input
|
>
|
||||||
class="flex flex-1 px-4 py-2 bg-transparent"
|
{{ t("cookies.modal.no_cookies_in_domain") }}
|
||||||
:value="entry"
|
</div>
|
||||||
readonly
|
<template v-else>
|
||||||
/>
|
<div
|
||||||
<HoppButtonSecondary
|
v-for="(entry, entryIndex) in entries"
|
||||||
:icon="IconEdit"
|
:key="`${entry}-${entryIndex}`"
|
||||||
@click="editCookie(domain, entryIndex, entry)"
|
class="flex divide-x divide-dividerLight"
|
||||||
/>
|
>
|
||||||
<HoppButtonSecondary
|
<input
|
||||||
color="red"
|
class="flex flex-1 px-4 py-2 bg-transparent"
|
||||||
:icon="IconTrash"
|
:value="entry"
|
||||||
@click="deleteCookie(domain, entryIndex)"
|
readonly
|
||||||
/>
|
/>
|
||||||
|
<HoppButtonSecondary
|
||||||
|
v-tippy="{ theme: 'tooltip' }"
|
||||||
|
:title="t('action.edit')"
|
||||||
|
:icon="IconEdit"
|
||||||
|
@click="editCookie(domain, entryIndex, entry)"
|
||||||
|
/>
|
||||||
|
<HoppButtonSecondary
|
||||||
|
v-tippy="{ theme: 'tooltip' }"
|
||||||
|
:title="t('action.remove')"
|
||||||
|
:icon="IconTrash"
|
||||||
|
color="red"
|
||||||
|
@click="deleteCookie(domain, entryIndex)"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
<template #footer>
|
<template v-if="currentInterceptorSupportsCookies" #footer>
|
||||||
<span class="flex space-x-2">
|
<span class="flex space-x-2">
|
||||||
<HoppButtonPrimary
|
<HoppButtonPrimary
|
||||||
v-focus
|
v-focus
|
||||||
@@ -110,7 +124,7 @@
|
|||||||
:label="t('action.clear_all')"
|
:label="t('action.clear_all')"
|
||||||
outline
|
outline
|
||||||
filled
|
filled
|
||||||
@click="hideModal"
|
@click="clearAllDomains"
|
||||||
/>
|
/>
|
||||||
</template>
|
</template>
|
||||||
</HoppSmartModal>
|
</HoppSmartModal>
|
||||||
@@ -134,6 +148,8 @@ import { cloneDeep } from "lodash-es"
|
|||||||
import { ref, watch, computed } from "vue"
|
import { ref, watch, computed } from "vue"
|
||||||
import { InterceptorService } from "~/services/interceptor.service"
|
import { InterceptorService } from "~/services/interceptor.service"
|
||||||
import { EditCookieConfig } from "./EditCookie.vue"
|
import { EditCookieConfig } from "./EditCookie.vue"
|
||||||
|
import { useColorMode } from "@composables/theming"
|
||||||
|
import { useToast } from "@composables/toast"
|
||||||
|
|
||||||
const props = defineProps<{
|
const props = defineProps<{
|
||||||
show: boolean
|
show: boolean
|
||||||
@@ -144,6 +160,8 @@ const emit = defineEmits<{
|
|||||||
}>()
|
}>()
|
||||||
|
|
||||||
const t = useI18n()
|
const t = useI18n()
|
||||||
|
const colorMode = useColorMode()
|
||||||
|
const toast = useToast()
|
||||||
|
|
||||||
const newDomainText = ref("")
|
const newDomainText = ref("")
|
||||||
|
|
||||||
@@ -161,6 +179,11 @@ const currentInterceptorSupportsCookies = computed(() => {
|
|||||||
})
|
})
|
||||||
|
|
||||||
function addNewDomain() {
|
function addNewDomain() {
|
||||||
|
if (newDomainText.value === "" || /^\s+$/.test(newDomainText.value)) {
|
||||||
|
toast.error(`${t("cookies.modal.empty_domain")}`)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
workingCookieJar.value.set(newDomainText.value, [])
|
workingCookieJar.value.set(newDomainText.value, [])
|
||||||
newDomainText.value = ""
|
newDomainText.value = ""
|
||||||
}
|
}
|
||||||
@@ -173,6 +196,11 @@ function addCookieToDomain(domain: string) {
|
|||||||
showEditModalFor.value = { type: "create", domain }
|
showEditModalFor.value = { type: "create", domain }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function clearAllDomains() {
|
||||||
|
workingCookieJar.value = new Map()
|
||||||
|
toast.success(`${t("state.cleared")}`)
|
||||||
|
}
|
||||||
|
|
||||||
watch(
|
watch(
|
||||||
() => props.show,
|
() => props.show,
|
||||||
(show) => {
|
(show) => {
|
||||||
|
|||||||
@@ -3,18 +3,52 @@
|
|||||||
v-if="show"
|
v-if="show"
|
||||||
dialog
|
dialog
|
||||||
:title="t('cookies.modal.set')"
|
:title="t('cookies.modal.set')"
|
||||||
aria-modal="true"
|
|
||||||
@close="hideModal"
|
@close="hideModal"
|
||||||
>
|
>
|
||||||
<template #body>
|
<template #body>
|
||||||
<div class="h-46 border rounded border-dividerLight">
|
<div class="border rounded border-dividerLight">
|
||||||
<div
|
<div class="flex flex-col">
|
||||||
ref="cookieEditor"
|
<div class="flex items-center justify-between pl-4">
|
||||||
class="h-full border-t rounded-b border-dividerLight"
|
<label class="font-semibold truncate text-secondaryLight">
|
||||||
></div>
|
{{ t("cookies.modal.cookie_string") }}
|
||||||
|
</label>
|
||||||
|
<div class="flex items-center">
|
||||||
|
<HoppButtonSecondary
|
||||||
|
v-tippy="{ theme: 'tooltip' }"
|
||||||
|
:title="t('action.clear_all')"
|
||||||
|
:icon="IconTrash2"
|
||||||
|
@click="clearContent()"
|
||||||
|
/>
|
||||||
|
<HoppButtonSecondary
|
||||||
|
v-tippy="{ theme: 'tooltip' }"
|
||||||
|
:title="t('state.linewrap')"
|
||||||
|
:class="{ '!text-accent': linewrapEnabled }"
|
||||||
|
:icon="IconWrapText"
|
||||||
|
@click.prevent="linewrapEnabled = !linewrapEnabled"
|
||||||
|
/>
|
||||||
|
<HoppButtonSecondary
|
||||||
|
v-tippy="{ theme: 'tooltip', allowHTML: true }"
|
||||||
|
:title="t('action.download_file')"
|
||||||
|
:icon="downloadIcon"
|
||||||
|
@click="downloadResponse"
|
||||||
|
/>
|
||||||
|
<HoppButtonSecondary
|
||||||
|
v-tippy="{ theme: 'tooltip', allowHTML: true }"
|
||||||
|
:title="t('action.copy')"
|
||||||
|
:icon="copyIcon"
|
||||||
|
@click="copyResponse"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="h-46">
|
||||||
|
<div
|
||||||
|
ref="cookieEditor"
|
||||||
|
class="h-full border-t rounded-b border-dividerLight"
|
||||||
|
></div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<template #footer>
|
<template #footer>
|
||||||
<div class="flex space-x-2">
|
<div class="flex space-x-2">
|
||||||
<HoppButtonPrimary
|
<HoppButtonPrimary
|
||||||
@@ -37,7 +71,6 @@
|
|||||||
filled
|
filled
|
||||||
outline
|
outline
|
||||||
@click="handlePaste"
|
@click="handlePaste"
|
||||||
class="self-end"
|
|
||||||
/>
|
/>
|
||||||
</span>
|
</span>
|
||||||
</template>
|
</template>
|
||||||
@@ -58,11 +91,17 @@ export type EditCookieConfig =
|
|||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import { useI18n } from "@composables/i18n"
|
import { useI18n } from "@composables/i18n"
|
||||||
import { useCodemirror } from "~/composables/codemirror"
|
import { useCodemirror } from "~/composables/codemirror"
|
||||||
import { watch, ref } from "vue"
|
import { watch, ref, reactive } from "vue"
|
||||||
import { refAutoReset } from "@vueuse/core"
|
import { refAutoReset } from "@vueuse/core"
|
||||||
|
import IconWrapText from "~icons/lucide/wrap-text"
|
||||||
import IconClipboard from "~icons/lucide/clipboard"
|
import IconClipboard from "~icons/lucide/clipboard"
|
||||||
import IconCheck from "~icons/lucide/check"
|
import IconCheck from "~icons/lucide/check"
|
||||||
|
import IconTrash2 from "~icons/lucide/trash-2"
|
||||||
import { useToast } from "~/composables/toast"
|
import { useToast } from "~/composables/toast"
|
||||||
|
import {
|
||||||
|
useCopyResponse,
|
||||||
|
useDownloadResponse,
|
||||||
|
} from "~/composables/lens-actions"
|
||||||
|
|
||||||
// TODO: Build Managed Mode!
|
// TODO: Build Managed Mode!
|
||||||
|
|
||||||
@@ -83,17 +122,22 @@ const toast = useToast()
|
|||||||
|
|
||||||
const cookieEditor = ref<HTMLElement>()
|
const cookieEditor = ref<HTMLElement>()
|
||||||
const rawCookieString = ref("")
|
const rawCookieString = ref("")
|
||||||
|
const linewrapEnabled = ref(true)
|
||||||
|
|
||||||
useCodemirror(cookieEditor, rawCookieString, {
|
useCodemirror(
|
||||||
extendedEditorConfig: {
|
cookieEditor,
|
||||||
mode: "text/plain",
|
rawCookieString,
|
||||||
placeholder: `${t("cookies.modal.cookie_string")}`,
|
reactive({
|
||||||
lineWrapping: true,
|
extendedEditorConfig: {
|
||||||
},
|
mode: "text/plain",
|
||||||
linter: null,
|
placeholder: `${t("cookies.modal.enter_cookie_string")}`,
|
||||||
completer: null,
|
lineWrapping: linewrapEnabled,
|
||||||
environmentHighlights: false,
|
},
|
||||||
})
|
linter: null,
|
||||||
|
completer: null,
|
||||||
|
environmentHighlights: false,
|
||||||
|
})
|
||||||
|
)
|
||||||
|
|
||||||
const pasteIcon = refAutoReset<typeof IconClipboard | typeof IconCheck>(
|
const pasteIcon = refAutoReset<typeof IconClipboard | typeof IconCheck>(
|
||||||
IconClipboard,
|
IconClipboard,
|
||||||
@@ -133,4 +177,14 @@ async function handlePaste() {
|
|||||||
function saveCookieChange() {
|
function saveCookieChange() {
|
||||||
emit("save-cookie", rawCookieString.value)
|
emit("save-cookie", rawCookieString.value)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const { copyIcon, copyResponse } = useCopyResponse(rawCookieString)
|
||||||
|
const { downloadIcon, downloadResponse } = useDownloadResponse(
|
||||||
|
"",
|
||||||
|
rawCookieString
|
||||||
|
)
|
||||||
|
|
||||||
|
function clearContent() {
|
||||||
|
rawCookieString.value = ""
|
||||||
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|||||||
Reference in New Issue
Block a user