Skip to content

Commit 06b5530

Browse files
feat(ProjectCard): open project on card click (no Open button click required)
1 parent c4602f2 commit 06b5530

File tree

1 file changed

+49
-45
lines changed

1 file changed

+49
-45
lines changed

src/components/ProjectCard/ProjectCard.vue

Lines changed: 49 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,13 @@ import type { JeMenuOptionProps } from 'jetv-ui'
33
import { JeLink, JeMenu, JeTransparentToolButton } from 'jetv-ui'
44
import { useI18n } from 'vue-i18n'
55
6-
import { showRemoveDialog } from '~/components/RemoveProjectDialog/RemoveProjectDialogProvider'
6+
import { showRemoveDialog } from '~/components/RemoveProjectDialog'
77
import { ViewEnum } from '~/constants/appEnums'
88
import { LicenseEnum } from '~/constants/license'
99
import type { LocalProject } from '~/constants/localProject'
1010
import { ProjectKind } from '~/constants/localProject'
1111
import { openLink } from '~/utils/common'
12-
import { initializeUpdateProjectState } from '~/views/ProjectConfig/ProjectConfigProvider'
12+
import { initializeUpdateProjectState } from '~/views/ProjectEditorView'
1313
1414
import LanguageButton from './LanguageButton.vue'
1515
import LicenseButton from './LicenseButton.vue'
@@ -35,7 +35,8 @@ const projectExists = computed(() => projectItem.value.isExists)
3535
3636
const { t } = useI18n()
3737
38-
const projectCard = ref<HTMLDivElement | null>(null)
38+
const projectCardRef = ref<HTMLDivElement | null>(null)
39+
const openButtonRef = ref<HTMLDivElement | null>(null)
3940
const projectCardActive = ref(false)
4041
const langGroup = ref(projectLangGroup.value)
4142
@@ -45,27 +46,26 @@ async function formatPath(path: string) {
4546
return window.api.formatPath(path)
4647
}
4748
48-
// eslint-disable-next-line unused-imports/no-unused-vars
49-
function handleClick(path: string) {
50-
projectCardActive.value = true
51-
}
52-
53-
function handleClicked() {
54-
projectCardActive.value = false
55-
}
56-
5749
function handleDragStart(event: DragEvent) {
5850
if (event.dataTransfer) {
5951
event.dataTransfer.effectAllowed = 'move'
6052
event.dataTransfer.setData('text/plain', projectAppendTime.value.toString())
6153
}
6254
}
6355
64-
watch(() => props.projectItem.langGroup, (newLangGroup, oldLangGroup) => {
65-
if (newLangGroup !== oldLangGroup) {
66-
langGroup.value = newLangGroup
67-
}
68-
}, { deep: true }) // 使用 deep 监听 langGroup 的内部变化
56+
function handleClick() {
57+
openButtonRef.value?.handleClick()
58+
}
59+
60+
watch(
61+
() => props.projectItem.langGroup,
62+
(newLangGroup, oldLangGroup) => {
63+
if (newLangGroup !== oldLangGroup) {
64+
langGroup.value = newLangGroup
65+
}
66+
},
67+
{ deep: true },
68+
) // 使用 deep 监听 langGroup 的内部变化
6969
7070
onMounted(async () => {
7171
formattedPath.value = await formatPath(projectPath.value)
@@ -76,9 +76,7 @@ function getDeleteLabel() {
7676
if (!projectExists.value) {
7777
return t('project_card.remove')
7878
}
79-
return projectIsTemporary?.value === true
80-
? t('project_card.delete')
81-
: t('project_card.remove')
79+
return projectIsTemporary?.value === true ? t('project_card.delete') : t('project_card.remove')
8280
}
8381
8482
const projectActions = computed<JeMenuOptionProps[]>(() => [
@@ -112,12 +110,12 @@ const projectActions = computed<JeMenuOptionProps[]>(() => [
112110
onClick: () => showRemoveDialog(props.projectItem),
113111
},
114112
])
115-
const menuVisible = ref(false)
113+
const menuVisible = ref<boolean>(false)
116114
const activatedView = inject('activatedView') as Ref<ViewEnum>
117115
118116
function changeHomeView() {
119117
if (activatedView)
120-
activatedView.value = ViewEnum.NewProject
118+
activatedView.value = ViewEnum.ProjectEditor
121119
}
122120
123121
function showMenu() {
@@ -127,23 +125,29 @@ function showMenu() {
127125

128126
<template>
129127
<div
130-
ref="projectCard"
128+
ref="projectCardRef"
131129
class="project-card group/item"
132130
:class="{ active: projectCardActive }"
133131
relative
134132
hover:bg="light:$gray-12 dark:$gray-3"
135-
p="10px" rounded="5px"
136-
flex="~ row justify-between" gap="10px"
137-
transition-all duration="150" ease-in-out
133+
active:bg="light:$gray-13 dark:$gray-2"
134+
p="10px"
135+
rounded="5px"
136+
flex="~ row justify-between"
137+
gap="10px"
138+
transition-all
139+
duration="150"
140+
ease-in-out
138141
cursor-pointer
142+
tabindex="0"
139143
draggable="true"
140-
@mousedown="handleClick(projectPath)"
141-
@mouseup="handleClicked"
142144
@dragstart="handleDragStart"
145+
@click.self="handleClick"
143146
>
144147
<div
145-
:class=" { 'opacity-30': !projectExists }"
146-
flex="~ col justify-between" gap="8px"
148+
:class="{ 'opacity-30': !projectExists }"
149+
flex="~ col justify-between"
150+
gap="8px"
147151
overflow-x-hidden
148152
>
149153
<!-- Info -->
@@ -162,7 +166,8 @@ function showMenu() {
162166
v-if="projectIsTemporary"
163167
text="medium"
164168
color="light:$yellow-5 dark:$yellow-9"
165-
b="solid 1px light:$yellow-5 dark:$yellow-9" rounded-full
169+
b="solid 1px light:$yellow-5 dark:$yellow-9"
170+
rounded-full
166171
p="x-4px"
167172
>
168173
{{ t('project_card.temporary') }}
@@ -171,15 +176,18 @@ function showMenu() {
171176

172177
<!-- Link -->
173178
<span
174-
v-if="(projectKind === ProjectKind.FORK || projectKind === ProjectKind.CLONE) && (projectFromUrl || projectFromName)"
175-
truncate text="secondary"
179+
v-if="
180+
(projectKind === ProjectKind.FORK || projectKind === ProjectKind.CLONE)
181+
&& (projectFromUrl || projectFromName)
182+
"
183+
truncate
184+
text="secondary"
176185
>
177186
{{ projectKind === ProjectKind.FORK ? 'Forked from' : 'Cloned from' }}
178187
<JeLink
179188
v-if="projectFromUrl"
180189
type="web"
181-
:on-click=" () => openLink(projectFromUrl) "
182-
@mousedown.stop @mouseup.stop
190+
:on-click="() => openLink(projectFromUrl)"
183191
>
184192
{{ projectFromName || projectFromUrl }}
185193
</JeLink>
@@ -192,9 +200,7 @@ function showMenu() {
192200

193201
<!-- Button -->
194202
<div flex="~ row" gap="15px">
195-
<LanguageButton
196-
:project-item="projectItem"
197-
/>
203+
<LanguageButton :project-item="projectItem" />
198204

199205
<LicenseButton
200206
v-if="projectLicense && projectLicense !== LicenseEnum.NONE"
@@ -206,6 +212,8 @@ function showMenu() {
206212
<div flex="~ row items-center" gap="10px">
207213
<OpenButton
208214
v-if="projectExists"
215+
ref="openButtonRef"
216+
:append-time="projectAppendTime"
209217
:default-open="projectDefaultOpen"
210218
:project-path="projectPath"
211219
/>
@@ -216,23 +224,19 @@ function showMenu() {
216224
icon="light:i-jet:more-vertical dark:i-jet:more-vertical-dark"
217225
icon-size="17px"
218226
@click="showMenu"
219-
@mousedown.stop @mouseup.stop
220227
/>
221228
<JeMenu
222229
v-model:visible="menuVisible"
223230
:options="projectActions"
224-
absolute translate-y="45px" right="5px"
225-
@mousedown.stop @mouseup.stop
231+
absolute
232+
translate-y="45px"
233+
right="5px"
226234
/>
227235
</div>
228236
</div>
229237
</template>
230238

231239
<style lang="scss" scoped>
232-
.project-card.active {
233-
@apply active:light:bg-$gray-13 active:dark:bg-$gray-2;
234-
}
235-
236240
.je-link:not(.disabled) {
237241
@apply dark:color-$blue-6;
238242
}

0 commit comments

Comments
 (0)