Skip to content
This repository has been archived by the owner on Feb 24, 2024. It is now read-only.

Commit

Permalink
feat: view png
Browse files Browse the repository at this point in the history
  • Loading branch information
neko-para committed Aug 14, 2023
1 parent 34dec8b commit 6396032
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 25 deletions.
23 changes: 4 additions & 19 deletions packages/client/src/components/atomic/ImageHover.vue
Original file line number Diff line number Diff line change
Expand Up @@ -2,27 +2,12 @@
import { NAvatar, NPopover } from 'naive-ui'
import { computed } from 'vue'
import { type Path, fs, pool } from '@/filesystem'
import { makePngUrl } from '@/data'
const props = defineProps<{
url: string | string[]
}>()
function makeUrl(v: string | null) {
const fallback = '/favicon-32x32.png'
if (v && v.endsWith('.png')) {
// TODO: maybe check?
const hash = fs.tree.readFile(v as Path)
if (hash) {
const url = pool.query(hash)
if (url) {
return url
}
}
}
return fallback
}
const first = computed(() => {
return props.url instanceof Array
? props.url.length > 0
Expand All @@ -37,15 +22,15 @@ const first = computed(() => {
<template #trigger>
<!-- <img :src="url" /> -->
<div class="w-8 h-8 flex justify-center items-center">
<NAvatar object-fit="contain" :src="makeUrl(first)"></NAvatar>
<NAvatar object-fit="contain" :src="makePngUrl(first)"></NAvatar>
</div>
</template>

<div class="flex flex-col items-center">
<template v-if="props.url instanceof Array">
<img v-for="(u, i) in props.url" :key="i" :src="makeUrl(u)" />
<img v-for="(u, i) in props.url" :key="i" :src="makePngUrl(u)" />
</template>
<img v-else :src="makeUrl(first)" />
<img v-else :src="makePngUrl(first)" />
</div>
</NPopover>
</template>
3 changes: 1 addition & 2 deletions packages/client/src/components/tree/TaskTree.vue
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@ function handleDrop({ node, dragNode, dropPosition }: TreeDropInfo) {
const [td, tf, th] = path.divide(toKey)
if (path.key_is_dir(fromKey)) {
// dragging directory
switch (dropPosition) {
case 'inside': {
if (!path.key_is_dir(toKey)) {
Expand Down Expand Up @@ -160,7 +159,7 @@ function handleDrop({ node, dragNode, dropPosition }: TreeDropInfo) {
<template>
<div class="flex flex-col gap-2 flex-1 min-h-0">
<div class="flex gap-2">
<NInput v-model:value="searchText" placeholder="task">
<NInput v-model:value="searchText" placeholder="task" clearable>
<template #prefix>
<NIcon>
<SearchOutlined></SearchOutlined>
Expand Down
24 changes: 23 additions & 1 deletion packages/client/src/data/filesystem.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,35 @@
import type { TreeOption, TreeSelectOption } from 'naive-ui'
import { computed, ref } from 'vue'

import { type PathKey, type PathSegments, fs, path } from '@/filesystem'
import {
type Path,
type PathKey,
type PathSegments,
fs,
path,
pool
} from '@/filesystem'
import type { TaskData } from '@/types'

export const expandKey = ref<PathKey[]>(['/' as PathKey])
export const renameKey = ref<string | null>(null)
export const renameInto = ref<string | null>(null)

export function makePngUrl(v: string | null) {
const fallback = '/favicon-32x32.png'
if (v && v.endsWith('.png')) {
// TODO: maybe check?
const hash = fs.tree.readFile(v as Path)
if (hash) {
const url = pool.query(hash)
if (url) {
return url
}
}
}
return fallback
}

export const filesystemTree = computed<TreeOption>(() => {
const rootOption: TreeOption = {
key: '/',
Expand Down
19 changes: 16 additions & 3 deletions packages/client/src/views/EditView.vue
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
import {
BuildOutlined,
CropOutlined,
EditOutlined,
FileDownloadOutlined,
FileUploadOutlined,
NavigateBeforeOutlined,
Expand All @@ -16,8 +15,8 @@ import { onMounted, onUnmounted, ref } from 'vue'
import { useRouter } from 'vue-router'
import { onEnterRename } from '@/components/tree/TaskTreeAction'
import { active, getTask, history, setTask } from '@/data'
import { type PathKey, fs } from '@/filesystem'
import { active, getTask, history, makePngUrl, setTask } from '@/data'
import { fs } from '@/filesystem'
import { loadFS, saveCfg, saveFS } from '@/loader'
import TaskEdit from '@/components/TaskEdit.vue'
Expand Down Expand Up @@ -147,6 +146,20 @@ onUnmounted(() => {
"
></TaskEdit>
</template>
<template
v-else-if="
active && active.endsWith('.png') && fs.tree.existsFile(active)
"
>
<div class="flex flex-col gap-4 max-h-full">
<div class="flex justify-center gap-2 items-center">
<span class="text-lg"> {{ active }} </span>
</div>
<div class="flex justify-center">
<img :src="makePngUrl(active)" />
</div>
</div>
</template>
</NCard>
</MainLayout>
</template>

0 comments on commit 6396032

Please sign in to comment.