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

Commit 38535e7

Browse files
Add download progress bar and optimize util files (#10914)
* download progress bar * optimize util files * move handleProjectDownload to projectDownload.tsx --------- Co-authored-by: aditya-mitra <55396651+aditya-mitra@users.noreply.github.com>
1 parent 3e648cd commit 38535e7

File tree

10 files changed

+303
-174
lines changed

10 files changed

+303
-174
lines changed

β€Žpackages/client-core/i18n/en/editor.jsonβ€Ž

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1217,6 +1217,7 @@
12171217
"uploadFiles": "Upload Files",
12181218
"uploadFolder": "Upload Folder",
12191219
"uploadingFiles": "Uploading Files ({{completed}}/{{total}})",
1220+
"downloadingProject": "Downloading Project ({{completed}}/{{total}})",
12201221
"search-placeholder": "Search",
12211222
"generatingThumbnails": "Generating Thumbnails ({{count}} remaining)",
12221223
"file": "File",
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
/*
2+
CPAL-1.0 License
3+
4+
The contents of this file are subject to the Common Public Attribution License
5+
Version 1.0. (the "License"); you may not use this file except in compliance
6+
with the License. You may obtain a copy of the License at
7+
https://github.com/EtherealEngine/etherealengine/blob/dev/LICENSE.
8+
The License is based on the Mozilla Public License Version 1.1, but Sections 14
9+
and 15 have been added to cover use of software over a computer network and
10+
provide for limited attribution for the Original Developer. In addition,
11+
Exhibit A has been modified to be consistent with Exhibit B.
12+
13+
Software distributed under the License is distributed on an "AS IS" basis,
14+
WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for the
15+
specific language governing rights and limitations under the License.
16+
17+
The Original Code is Ethereal Engine.
18+
19+
The Original Developer is the Initial Developer. The Initial Developer of the
20+
Original Code is the Ethereal Engine team.
21+
22+
All portions of the code written by the Ethereal Engine team are Copyright Β© 2021-2023
23+
Ethereal Engine. All Rights Reserved.
24+
*/
25+
26+
/**
27+
* Converts bytes to a human-readable size
28+
* @param bytes The number of bytes
29+
* @param decimals The number of decimal places to include
30+
* @returns The human-readable size
31+
*/
32+
33+
export function bytesToSize(bytes: number, decimals = 2) {
34+
if (bytes === 0) return '0 Bytes'
35+
36+
const k = 1024
37+
const dm = decimals < 0 ? 0 : decimals
38+
const sizes = ['Bytes', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB']
39+
40+
const i = Math.floor(Math.log(bytes) / Math.log(k))
41+
42+
return parseFloat((bytes / Math.pow(k, i)).toFixed(dm)) + ' ' + sizes[i]
43+
}

β€Žpackages/common/src/utils/getOS.tsβ€Ž renamed to β€Žpackages/common/src/utils/getDeviceStats.tsβ€Ž

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,3 +35,19 @@ export function getOS() {
3535
}
3636
return 'other'
3737
}
38+
39+
export const isApple = () => {
40+
if ('navigator' in globalThis === false) return false
41+
42+
const iOS_1to12 = /iPad|iPhone|iPod/.test(navigator.platform)
43+
44+
const iOS13_iPad = navigator.platform === 'MacIntel'
45+
46+
const iOS1to12quirk = () => {
47+
const audio = new Audio() // temporary Audio object
48+
audio.volume = 0.5 // has no effect on iOS <= 12
49+
return audio.volume === 1
50+
}
51+
52+
return iOS_1to12 || iOS13_iPad || iOS1to12quirk()
53+
}

β€Žpackages/common/src/utils/mapToObject.tsβ€Ž

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,3 +52,7 @@ export const iterativeMapToObject = (root: Record<any, any>) => {
5252
}
5353
return cloneDeep(iterate(root))
5454
}
55+
56+
export function objectToMap(object: object) {
57+
return new Map(Object.entries(object))
58+
}

β€Žpackages/common/src/utils/miscUtils.tsβ€Ž

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,11 @@ export function isNumber(value: string | number): boolean {
3838
return value != null && value !== '' && !isNaN(Number(value.toString()))
3939
}
4040

41+
export function toPrecision(value, precision) {
42+
const p = 1 / precision
43+
return Math.round(value * p) / p
44+
}
45+
4146
export function combine(first, second, third) {
4247
const res: any[] = []
4348

@@ -47,6 +52,23 @@ export function combine(first, second, third) {
4752

4853
return res
4954
}
55+
56+
export const unique = <T, S = T>(arr: T[], keyFinder: (item: T) => S): T[] => {
57+
const set = new Set<S>()
58+
const newArr = [] as T[]
59+
if (!keyFinder) keyFinder = (item: T) => item as any as S
60+
61+
for (const item of arr) {
62+
const key = keyFinder(item)
63+
if (set.has(key)) continue
64+
65+
newArr.push(item)
66+
set.add(key)
67+
}
68+
69+
return newArr
70+
}
71+
5072
export function combineArrays(arrays: [[]]) {
5173
const res = []
5274

@@ -59,6 +81,23 @@ export function combineArrays(arrays: [[]]) {
5981
return res
6082
}
6183

84+
export function insertArraySeparator(children, separatorFn) {
85+
if (!Array.isArray(children)) {
86+
return children
87+
}
88+
const length = children.length
89+
if (length === 1) {
90+
return children[0]
91+
}
92+
return children.reduce((acc, item, index) => {
93+
acc.push(item)
94+
if (index !== length - 1) {
95+
acc.push(separatorFn(index))
96+
}
97+
return acc
98+
}, [])
99+
}
100+
62101
export function arraysAreEqual(arr1: any[], arr2: any[]): boolean {
63102
if (arr1.length !== arr2.length) return false
64103

@@ -154,3 +193,14 @@ export const toCapitalCase = (source: string) => {
154193
return txt.charAt(0).toUpperCase() + txt.substr(1).toLowerCase()
155194
})
156195
}
196+
197+
export function toCamelPad(source: string) {
198+
return source
199+
.replace(/([A-Z]+)([A-Z][a-z])/g, ' $1 $2')
200+
.replace(/([a-z\d])([A-Z])/g, '$1 $2')
201+
.replace(/([a-zA-Z])(\d)/g, '$1 $2')
202+
.replace(/^./, (str) => {
203+
return str.toUpperCase()
204+
})
205+
.trim()
206+
}

β€Žpackages/editor/src/functions/utils.tsβ€Ž

Lines changed: 2 additions & 80 deletions
Original file line numberDiff line numberDiff line change
@@ -22,60 +22,7 @@ Original Code is the Ethereal Engine team.
2222
All portions of the code written by the Ethereal Engine team are Copyright Β© 2021-2023
2323
Ethereal Engine. All Rights Reserved.
2424
*/
25-
26-
export function insertSeparator(children, separatorFn) {
27-
if (!Array.isArray(children)) {
28-
return children
29-
}
30-
const length = children.length
31-
if (length === 1) {
32-
return children[0]
33-
}
34-
return children.reduce((acc, item, index) => {
35-
acc.push(item)
36-
if (index !== length - 1) {
37-
acc.push(separatorFn(index))
38-
}
39-
return acc
40-
}, [])
41-
}
42-
export function objectToMap(object: object) {
43-
return new Map(Object.entries(object))
44-
}
45-
46-
export const unique = <T, S = T>(arr: T[], keyFinder: (item: T) => S): T[] => {
47-
const set = new Set<S>()
48-
const newArr = [] as T[]
49-
if (!keyFinder) keyFinder = (item: T) => item as any as S
50-
51-
for (const item of arr) {
52-
const key = keyFinder(item)
53-
if (set.has(key)) continue
54-
55-
newArr.push(item)
56-
set.add(key)
57-
}
58-
59-
return newArr
60-
}
61-
62-
export const isApple = () => {
63-
if ('navigator' in globalThis === false) return false
64-
65-
const iOS_1to12 = /iPad|iPhone|iPod/.test(navigator.platform)
66-
67-
const iOS13_iPad = navigator.platform === 'MacIntel'
68-
69-
const iOS1to12quirk = () => {
70-
const audio = new Audio() // temporary Audio object
71-
audio.volume = 0.5 // has no effect on iOS <= 12
72-
return audio.volume === 1
73-
}
74-
75-
return iOS_1to12 || iOS13_iPad || iOS1to12quirk()
76-
}
77-
78-
export const cmdOrCtrlString = isApple() ? 'meta' : 'ctrl'
25+
import { isApple } from '@etherealengine/common/src/utils/getDeviceStats'
7926

8027
export function getStepSize(event, smallStep, mediumStep, largeStep) {
8128
if (event.altKey) {
@@ -86,29 +33,4 @@ export function getStepSize(event, smallStep, mediumStep, largeStep) {
8633
return mediumStep
8734
}
8835

89-
export function toPrecision(value, precision) {
90-
const p = 1 / precision
91-
return Math.round(value * p) / p
92-
}
93-
// https://stackoverflow.com/a/26188910
94-
export function camelPad(str) {
95-
return str
96-
.replace(/([A-Z]+)([A-Z][a-z])/g, ' $1 $2')
97-
.replace(/([a-z\d])([A-Z])/g, '$1 $2')
98-
.replace(/([a-zA-Z])(\d)/g, '$1 $2')
99-
.replace(/^./, (str) => {
100-
return str.toUpperCase()
101-
})
102-
.trim()
103-
}
104-
export function bytesToSize(bytes: number, decimals = 2) {
105-
if (bytes === 0) return '0 Bytes'
106-
107-
const k = 1024
108-
const dm = decimals < 0 ? 0 : decimals
109-
const sizes = ['Bytes', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB']
110-
111-
const i = Math.floor(Math.log(bytes) / Math.log(k))
112-
113-
return parseFloat((bytes / Math.pow(k, i)).toFixed(dm)) + ' ' + sizes[i]
114-
}
36+
export const cmdOrCtrlString = isApple() ? 'meta' : 'ctrl'

β€Žpackages/ui/src/components/editor/input/Numeric/index.tsxβ€Ž

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,8 @@ import React from 'react'
2727

2828
import { clamp } from '@etherealengine/spatial/src/common/functions/MathLerpFunctions'
2929

30-
import { getStepSize, toPrecision } from '@etherealengine/editor/src/functions/utils'
30+
import { toPrecision } from '@etherealengine/common/src/utils/miscUtils'
31+
import { getStepSize } from '@etherealengine/editor/src/functions/utils'
3132
import { useHookstate } from '@etherealengine/hyperflux'
3233
import { twMerge } from 'tailwind-merge'
3334
import Text from '../../../../primitives/tailwind/Text'

β€Žpackages/ui/src/components/editor/layout/Scrubber.tsxβ€Ž

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,8 @@ All portions of the code written by the Ethereal Engine team are Copyright Β© 20
2323
Ethereal Engine. All Rights Reserved.
2424
*/
2525

26-
import { getStepSize, toPrecision } from '@etherealengine/editor/src/functions/utils'
26+
import { toPrecision } from '@etherealengine/common/src/utils/miscUtils'
27+
import { getStepSize } from '@etherealengine/editor/src/functions/utils'
2728
import { useHookstate } from '@etherealengine/hyperflux'
2829
import React, { useRef } from 'react'
2930
import { twMerge } from 'tailwind-merge'

0 commit comments

Comments
Β (0)