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

Optimizations #87

Open
wants to merge 11 commits into
base: main
Choose a base branch
from
Open
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
2 changes: 1 addition & 1 deletion src/components/info/Size.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
const Size = ({ size }) => (
<span className='flex items-center'>
<span className='pr-2 text-gray-600 '>Size: </span>{' '}
<span className='inline-flex font-bold'>
<span className='inline-flex font-bold text-gray-800'>
<span>{size}</span>
</span>
</span>
Expand Down
2 changes: 1 addition & 1 deletion src/components/info/rating/Star.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ const Star = ({ starId, selected }) => {
strokeLinecap='round'
strokeLinejoin='round'
strokeWidth={2}
d='M11.049 2.927c.3-.921 1.603-.921 1.902 0l1.519 4.674a1 1 0 00.95.69h4.915c.969 0 1.371 1.24.588 1.81l-3.976 2.888a1 1 0 00-.363 1.118l1.518 4.674c.3.922-.755 1.688-1.538 1.118l-3.976-2.888a1 1 0 00-1.176 0l-3.976 2.888c-.783.57-1.838-.197-1.538-1.118l1.518-4.674a1 1 0 00-.363-1.118l-3.976-2.888c-.784-.57-.38-1.81.588-1.81h4.914a1 1 0 00.951-.69l1.519-4.674z'
d='M11 3a1 1 0 012 0l1.5 4.6a1 1 0 001 .7h4.8A1 1 0 0121 10L17 13a1 1 0 00-.3 1.1l1.5 4.7a1 1 0 01-1.5 1.1l-4-2.9a1 1 0 00-1.2 0l-4 2.9A1 1 0 016 18.8L7.4 14a1 1 0 00-.3-1.1L3 10a1 1 0 01.6-1.8h4.9a1 1 0 001-.7L11 2.9z'
/>
</svg>
</button>
Expand Down
24 changes: 14 additions & 10 deletions src/helpers/getStats.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,16 @@ function decodeDataURI(resource, resources) {
resource.uri = resourceUUID
}

function getTexturesSize() {
return document
.getRoot()
.listTextures()
.reduce(
(acc, curr) =>
ImageUtils.getMemSize(curr.getImage(), curr.getMimeType()) + acc
)
}

export const getStats = async (json) => {
try {
const io = new WebIO()
Expand Down Expand Up @@ -58,16 +68,10 @@ export const getStats = async (json) => {
const vertices = report.meshes.properties.reduce(
(acc, curr) => curr.vertices + acc
)
let totalBytes = 0
for (let accessor of document.getRoot().listAccessors()) {
totalBytes += accessor.getByteLength()
}
for (let texture of document.getRoot().listTextures()) {
totalBytes += ImageUtils.getMemSize(
texture.getImage(),
texture.getMimeType()
)
}
const totalBytes = document
.getRoot()
.listAccessors()
.reduce((acc, curr) => curr.getByteLength() + acc, getTexturesSize())

return {
extensions: json.extensionsUsed || json.extensionsRequired,
Expand Down
12 changes: 5 additions & 7 deletions src/helpers/slugify.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,14 @@ export function slugify(str) {
str = str.toLowerCase()

// remove accents, swap ñ for n, etc
var from = 'àáäâèéëêìíïîòóöôùúüûñç·/_,:;'
var to = 'aaaaeeeeiiiioooouuuunc------'
for (var i = 0, l = from.length; i < l; i++) {
str = str.replace(new RegExp(from.charAt(i), 'g'), to.charAt(i))
const from = ['àáäâ', 'èéëê', 'ìíïî', 'òóöô', 'ùúüû', 'ñ', 'ç', '·/_,:;']
const to = ['a', 'e', 'i', 'o', 'u', 'n', 'c', '-']
for (let i = 0, l = from.length; i < l; i++) {
str = str.replace(new RegExp(`[${from[i]}]`, 'g'), to[i])
}

str = str
return str
.replace(/[^a-z0-9 -]/g, '') // remove invalid chars
.replace(/\s+/g, '-') // collapse whitespace and replace by -
.replace(/-+/g, '-') // collapse dashes

return str
}
11 changes: 5 additions & 6 deletions src/helpers/store/addAsset.js
Original file line number Diff line number Diff line change
Expand Up @@ -254,10 +254,7 @@ const useAddAssetStore = create((set, get) => {
acc[curr] = state.maps[curr].size
return acc
}, {})
const size = Object.values(sizes).reduce((acc, curr) => {
acc = acc + curr
return acc
}, 0)
const size = Object.values(sizes).reduce((acc, curr) => acc + curr)

const data = {
...assetData,
Expand All @@ -275,8 +272,10 @@ const useAddAssetStore = create((set, get) => {
.insert({ thumbnail, file, creator, team, ...assetData })
}

set({ loadingText: 'We are done' })
set({ createdAsset: id })
set({
loadingText: 'We are done',
createdAsset: id,
})
} catch (e) {
console.error(e)
set({
Expand Down
46 changes: 16 additions & 30 deletions src/helpers/store/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,41 +72,27 @@ const useStore = create((set, get) => {
const user = get().user
const favoriteName = `${type}/${name}`
const currentFavorites = user.profile.favorites
let favorites
if (currentFavorites && currentFavorites.includes(favoriteName)) {
const favorites = currentFavorites.filter((fav) => fav !== favoriteName)

await supabase
.from('profiles')
.update({ favorites })
.eq('user_id', user.id)
set({
user: {
...user,
profile: {
...user.profile,
favorites,
},
},
})
favorites = currentFavorites.filter((fav) => fav !== favoriteName)
} else {
const favorites = currentFavorites
favorites = currentFavorites
? [...currentFavorites, favoriteName]
: [favoriteName]
await supabase
.from('profiles')
.update({ favorites })
.eq('user_id', user.id)

set({
user: {
...user,
profile: {
...user.profile,
favorites,
},
},
})
}
await supabase
.from('profiles')
.update({ favorites })
.eq('user_id', user.id)
set({
user: {
...user,
profile: {
...user.profile,
favorites,
},
},
})
},
createBuffer: async (name) => {
const buffer = await fetch(`${API_ENDPOINT}/models/${name}/buffer`).then(
Expand Down
6 changes: 4 additions & 2 deletions src/helpers/store/requests.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,10 @@ const useStore = create((set, get) => {
user_id: user?.id,
created: new Date(),
}
set({ requests: [{ id: 'fake-id', ...newRequest }, ...requests] })
useStore.setState({ requesting: false })
set({
requests: [{ id: 'fake-id', ...newRequest }, ...requests],
requesting: false,
})
const { error } = await supabase.from('requests').insert([newRequest])

if (error) {
Expand Down
3 changes: 2 additions & 1 deletion src/pages/add-asset.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import Layout from '@/components/layout/'
import AddAsset from '@/components/AddAsset/'
import useStore from '@/helpers/store'
import Head from 'next/head'
import Script from 'next/script'

const Page = () => {
const { user } = useStore()
Expand All @@ -11,7 +12,7 @@ const Page = () => {
<Layout title={'Add your own asset'} center>
<AddAsset />
<Head>
<script src='/draco/decoder.js' />
<Script strategy='beforeInteractive' src='/draco/decoder.js' />
</Head>
</Layout>
)
Expand Down