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

Commit

Permalink
studio: update scene item UI (#10691)
Browse files Browse the repository at this point in the history
* update scene item for studio

* default image of thumbail dne

* use tailwind value for height and width

* address pr comments

* reusable sceneitem component

* rename scene component

* move scene container to client core

* add new file

* fix import for rename scene modal

* Updated scene item to use correct styles

---------

Co-authored-by: Hanzla Mateen <[email protected]>
  • Loading branch information
achen5671 and hanzlamateen authored Jul 30, 2024
1 parent ed90277 commit ee91400
Show file tree
Hide file tree
Showing 6 changed files with 208 additions and 176 deletions.
4 changes: 3 additions & 1 deletion packages/client-core/i18n/en/editor.json
Original file line number Diff line number Diff line change
Expand Up @@ -1271,12 +1271,14 @@
"info": "The scene Hierarchy contains all element currently in your scene (assets, lighting, items from the tool menu, etc).",
"lbl-rename": "Rename",
"lbl-renameScene": "Rename Scene",
"lbl-edited": "Edited",
"lbl-duplicate": "Duplicate",
"lbl-group": "Group",
"lbl-copy": "Copy",
"lbl-paste": "Paste",
"lbl-delete": "Delete",
"lbl-deleteScene": "Are you sure you want to delete '{{sceneName}}' scene?",
"lbl-deleteScene": "Delete Scene",
"lbl-deleteSceneDescription": "Are you sure you want to delete '{{sceneName}}' scene?",
"lbl-expandAll": "Expand All",
"lbl-collapseAll": "Collapse All",
"lbl-explode": "Explode Objects",
Expand Down
174 changes: 174 additions & 0 deletions packages/client-core/src/admin/components/scene/SceneItem.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,174 @@
/*
CPAL-1.0 License
The contents of this file are subject to the Common Public Attribution License
Version 1.0. (the "License"); you may not use this file except in compliance
with the License. You may obtain a copy of the License at
https://github.com/EtherealEngine/etherealengine/blob/dev/LICENSE.
The License is based on the Mozilla Public License Version 1.1, but Sections 14
and 15 have been added to cover use of software over a computer network and
provide for limited attribution for the Original Developer. In addition,
Exhibit A has been modified to be consistent with Exhibit B.
Software distributed under the License is distributed on an "AS IS" basis,
WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for the
specific language governing rights and limitations under the License.
The Original Code is Ethereal Engine.
The Original Developer is the Initial Developer. The Initial Developer of the
Original Code is the Ethereal Engine team.
All portions of the code written by the Ethereal Engine team are Copyright © 2021-2023
Ethereal Engine. All Rights Reserved.
*/
import { PopoverState } from '@etherealengine/client-core/src/common/services/PopoverState'
import { StaticResourceType } from '@etherealengine/common/src/schema.type.module'
import { timeAgo } from '@etherealengine/common/src/utils/datetime-sql'
import { useClickOutside } from '@etherealengine/common/src/utils/useClickOutside'
import { deleteScene } from '@etherealengine/editor/src/functions/sceneFunctions'
import { EditorState } from '@etherealengine/editor/src/services/EditorServices'
import { useHookstate, useMutableState } from '@etherealengine/hyperflux'
import RenameSceneModal from '@etherealengine/ui/src/components/editor/panels/Scenes/modals/RenameScene'
import ConfirmDialog from '@etherealengine/ui/src/components/tailwind/ConfirmDialog'
import Button from '@etherealengine/ui/src/primitives/tailwind/Button'
import Text from '@etherealengine/ui/src/primitives/tailwind/Text'
import { default as React, useEffect, useRef } from 'react'
import { useTranslation } from 'react-i18next'
import { BsThreeDotsVertical } from 'react-icons/bs'
import { LuTrash } from 'react-icons/lu'
import { MdOutlineEdit } from 'react-icons/md'
import { twMerge } from 'tailwind-merge'

type SceneItemProps = {
scene: StaticResourceType
updateEditorState?: boolean
handleOpenScene: () => void
refetchProjectsData: () => void
}

export const SceneItem = ({ scene, updateEditorState, handleOpenScene, refetchProjectsData }: SceneItemProps) => {
const { t } = useTranslation()
const editorState = useMutableState(EditorState)

const sceneName = scene.key.split('/').pop()!.replace('.gltf', '')

const deleteSelectedScene = async (scene: StaticResourceType) => {
if (scene) {
await deleteScene(scene.key)

if (updateEditorState) {
if (editorState.sceneAssetID.value === scene.id) {
editorState.sceneName.set(null)
editorState.sceneAssetID.set(null)
}
} else {
refetchProjectsData()
}
}
PopoverState.hidePopupover()
}

const showContentMenu = useHookstate(false)
const menuPosition = useHookstate({ top: 0, left: 0 })

const threeDotsContainRef = useRef<HTMLDivElement>(null)

useClickOutside(threeDotsContainRef, () => showContentMenu.set(false))

useEffect(() => {
if (!threeDotsContainRef.current) return

let animationFrameId: number

const updatePosition = () => {
if (!threeDotsContainRef.current) return
const rect = threeDotsContainRef.current.getBoundingClientRect()
menuPosition.set({ top: rect.bottom, left: rect.left })
animationFrameId = requestAnimationFrame(updatePosition)
}

updatePosition()

return () => cancelAnimationFrame(animationFrameId)
}, [threeDotsContainRef])

return (
<div className="col-span-2 inline-flex h-64 w-64 min-w-64 max-w-64 cursor-pointer flex-col items-start justify-start gap-3 rounded-lg bg-theme-highlight p-3 lg:col-span-1">
<img className="shrink grow basis-0 self-stretch rounded" src={scene.thumbnailURL} onClick={handleOpenScene} />
<div className="inline-flex items-start justify-between self-stretch">
<div className="inline-flex w-full flex-col items-start justify-start">
<div className="space-between flex w-full flex-row">
<Text component="h3" fontWeight="light" className="leading-6 text-neutral-100">
{sceneName}
</Text>
</div>
<Text component="h3" fontSize="xs" fontWeight="light" className="h-3.5 w-40 leading-5 text-neutral-100">
{t('editor:hierarchy.lbl-edited')} {t('common:timeAgo', { time: timeAgo(new Date(scene.updatedAt)) })}
</Text>
</div>
<div className="relative h-6 w-6" ref={threeDotsContainRef}>
<Button
variant="transparent"
size="small"
className="px-2 py-1.5"
startIcon={<BsThreeDotsVertical className="text-neutral-100" />}
onClick={() => showContentMenu.set((v) => !v)}
/>
<ul
className={twMerge(
'fixed z-10 block w-max translate-x-5 rounded-lg bg-theme-primary px-4 py-3 pr-10',
showContentMenu.value ? 'visible' : 'hidden'
)}
style={{
top: menuPosition.top.value,
left: menuPosition.left.value
}}
>
<li className="h-8">
<Button
variant="transparent"
size="medium"
className="h-full p-0 text-zinc-400 hover:text-[var(--text-primary)]"
startIcon={<MdOutlineEdit />}
onClick={() => {
showContentMenu.set(false)
PopoverState.showPopupover(
<RenameSceneModal
sceneName={sceneName}
scene={scene}
updateEditorState={updateEditorState}
refetchProjectsData={refetchProjectsData}
/>
)
}}
>
{t('editor:hierarchy.lbl-rename')}
</Button>
</li>
<li className="h-8">
<Button
variant="transparent"
size="medium"
className="h-full p-0 text-zinc-400 hover:text-[var(--text-primary)]"
startIcon={<LuTrash />}
onClick={() => {
showContentMenu.set(false)
PopoverState.showPopupover(
<ConfirmDialog
title={t('editor:hierarchy.lbl-deleteScene')}
text={t('editor:hierarchy.lbl-deleteSceneDescription', { sceneName })}
onSubmit={async () => deleteSelectedScene(scene)}
/>
)
}}
>
{t('editor:hierarchy.lbl-delete')}
</Button>
</li>
</ul>
</div>
</div>
</div>
)
}
89 changes: 6 additions & 83 deletions packages/editor/src/components/assets/styles.module.scss
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@

.extensionRibbon {
--stick-out: 0.5em;

font-size: 0.135em;
font-weight: bold;
text-align: right;
Expand All @@ -114,7 +114,7 @@

.table {
.tableHeaderRow {
background-color: var(--tableHeaderBackground) ;
background-color: var(--tableHeaderBackground);
border-bottom: 2px solid var(--dropdownMenuHoverBackground);
}

Expand Down Expand Up @@ -179,84 +179,6 @@
}
}

.sceneGridContainer {
display: grid;
grid-gap: 10px;
width: 100%;
margin-bottom: auto;
padding: 10px;
grid-template-columns: repeat(auto-fill, minmax(125px, 1fr));

.sceneContainer {
border-radius: 4px;
overflow: hidden;
background: var(--inputBackground);
min-height: 125px;
cursor: pointer;

.thumbnailContainer {
height: calc(100% - 40px);
width: 100%;
}

.detailBlock {
padding-left: 10px;
font-size: 14px;
display: flex;
align-items: center;
justify-content: space-between;
height: 40px;

span {
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
}

.inputContainer {
background: var(--inputBackground);
color: var(--textColor);

.input {
font-size: 12px !important;
padding: 0 5px !important;
}
}
}

button {
color: var(--textColor);
}

&:hover,
&:focus-visible {
outline: solid 2px var(--panelCardHoverOutline);

.detailBlock {
color: var(--textColor);
}
}
}
}

.sceneContextMenu {
background: var(--inputBackground);
color: var(--textColor);

.menuItem {
font-size: 14px;

&:hover,
&:focus-visible {
background: var(--dropdownMenuHoverBackground);
}

&:global(.Mui-selected) {
background: var(--dropdownMenuSelectedBackground);
}
}
}

%container {
height: 100%;
background: #fff;
Expand Down Expand Up @@ -399,9 +321,10 @@
}

.hideScrollbar {
scrollbar-width: none; /* firefox */
scrollbar-width: none; /* firefox */
-ms-overflow-style: none; /* edge */
::-webkit-scrollbar{/* Hide scrollbar for Chrome, Safari and Opera */
::-webkit-scrollbar {
/* Hide scrollbar for Chrome, Safari and Opera */
display: none;
}
}
}
Loading

0 comments on commit ee91400

Please sign in to comment.