Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add config page #75

Closed
wants to merge 6 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions src/components/ActionsMenu.vue
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,12 @@ const favorited = computed(() => isFavorited(props.collection.id))

<template>
<div flex="~ gap3" text-xl items-center>
<RouterLink
class="non-dragging text-xl mx-3 my-auto"
to="/config"
>
<IconButton icon="carbon:settings" style="padding-bottom: 3px" />
</RouterLink>
<DarkSwitcher />

<button
Expand Down
4 changes: 2 additions & 2 deletions src/components/IconDetail.vue
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
<script setup lang='ts'>
import copyText from 'copy-text-to-clipboard'
import { getIconSnippet, toComponentName } from '../utils/icons'
import { collections } from '../data'
import { activeMode, copyPreviewColor, getTransformedId, inBag, preferredCase, previewColor, showCaseSelect, showHelp, toggleBag } from '../store'
import { Download } from '../utils/pack'
import { idCases } from '../utils/case'
import { copyName } from '../utils/copy'

const props = defineProps({
icon: {
Expand Down Expand Up @@ -32,7 +32,7 @@ const copy = async (type: string) => {
if (!text)
return

emit('copy', copyText(text))
emit('copy', copyName(text))
}

const download = async (type: string) => {
Expand Down
4 changes: 2 additions & 2 deletions src/components/IconSet.vue
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
<script setup lang='ts'>
import copyText from 'copy-text-to-clipboard'
import { useRoute, useRouter } from 'vue-router'
import { activeMode, bags, getSearchResults, iconSize, isCurrentCollectionLoading, listType, showHelp, toggleBag } from '../store'
import { isLocalMode } from '../env'
import { cacheCollection } from '../data'
import { getIconSnippet } from '../utils/icons'
import { copyName } from '../utils/copy'

const { search, icons, category, collection } = getSearchResults()
const showBag = ref(false)
Expand Down Expand Up @@ -41,7 +41,7 @@ const onSelect = async (icon: string) => {
toggleBag(icon)
break
case 'copy':
onCopy(copyText(await getIconSnippet(icon, 'id', true) || icon))
onCopy(copyName(await getIconSnippet(icon, 'id', true) || icon))
break
default:
current.value = icon
Expand Down
11 changes: 10 additions & 1 deletion src/components/Navbar.vue
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
<script lang="ts">
import { getSearchResults, isDark } from '../store'

const showNavPages = ['/', '/config']

export default defineComponent(() => ({
...getSearchResults(),
isDark,
showNavPages,
}))
</script>

Expand All @@ -12,7 +15,7 @@ export default defineComponent(() => ({
class="dragging"
flex="~ gap4 none"
p4 relative bg-base z-10 border="b base" text-xl
:class="$route.path !== '/' ? 'md:hidden' : ''"
:class="showNavPages.includes($route.path) ? '' : 'md:hidden'"
>
<!-- In Collections -->
<template v-if="$route.path !== '/'">
Expand All @@ -38,6 +41,12 @@ export default defineComponent(() => ({
>
Icônes
</h1>
<RouterLink
class="non-dragging text-xl mx-3 my-auto"
to="/config"
>
<IconButton icon="carbon:settings" style="padding-bottom: 3px" />
</RouterLink>
<a
class="non-dragging"
i-carbon-logo-github icon-button flex-none
Expand Down
31 changes: 31 additions & 0 deletions src/pages/config.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<script setup lang='ts'>
import { userConfig } from '../store'
</script>

<template>
<WithNavbar>
<div py-8 px-8 text-gray-700 dark:text-dark-700>
<div text-gray-900 text-2xl mb-2 dark:text-gray-200>
Config page
</div>
<div op50 text-sm mb-6>
Edit your custom config below. Config will be auto saved in localStorage.
</div>
<div v-for="(_, configKey) in userConfig" :key="configKey" mb-6>
<div op70 text-xl mb-4 dark:text-gray-200>
{{ configKey }}
</div>
<div v-for="(__, subConfigKey) in userConfig[configKey]" :key="subConfigKey" flex items-center>
<div mr-2 op70>
{{ subConfigKey }}:
</div>
<input
v-model="userConfig[configKey][subConfigKey]"
text-base outline-none py-1 px-4 bg-transparent border rounded border-base
>
<Icon v-show="userConfig[configKey][subConfigKey]" icon="carbon:close" class="text-lg -ml-6 opacity-60" @click="userConfig[configKey][subConfigKey] = ''" />
</div>
</div>
</div>
</WithNavbar>
</template>
2 changes: 2 additions & 0 deletions src/store/localstorage.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import type { IdCase } from '../utils/case'
import { idCases } from '../utils/case'
import { defaultConfig } from '../utils/config'

const RECENT_CAPACITY = 10

Expand All @@ -15,6 +16,7 @@ export const recentIds = useStorage<string[]>('icones-recent-collections', [])
export const bags = useStorage<string[]>('icones-bags', [])
export const activeMode = useStorage<ActiveMode>('active-mode', 'normal')
export const preferredCase = useStorage<IdCase>('icones-preferfed-case', 'iconify')
export const userConfig = useStorage('icones-config', defaultConfig)

export function getTransformedId(icon: string) {
return idCases[preferredCase.value]?.(icon) || icon
Expand Down
5 changes: 5 additions & 0 deletions src/utils/config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
export const defaultConfig = {
'Name copying mode': {
prefix: '',
},
}
6 changes: 6 additions & 0 deletions src/utils/copy.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import copyText from 'copy-text-to-clipboard'
import { userConfig } from '../store'

export function copyName(icon: string) {
return copyText(userConfig.value['Name copying mode'].prefix + icon)
}