Skip to content

Commit a9d6a2c

Browse files
committed
Hot-update: cleanup, format
- Remove some unnecessary print statements - Clean up styling on navbar buttons - Change user menu to user framer-motion
1 parent 5319c74 commit a9d6a2c

File tree

11 files changed

+150
-119
lines changed

11 files changed

+150
-119
lines changed

backend/util/crud/users.py

-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ def read_users(db: Session, query: str | None = None, offset: int = 0):
2828

2929
# Create User
3030
def create_user(db: Session, user: UserCreate):
31-
print("troll")
3231
hashed_password = bcrypt.hashpw(user.password.encode("utf-8"), bcrypt.gensalt())
3332

3433
db_user = User(

frontend/src/main/lib/local-assets.ts

+78-70
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
11
import archiver from 'archiver';
22
import { app, shell } from 'electron';
33
import extract from 'extract-zip';
4+
import { hashElement } from 'folder-hash';
45
import { createWriteStream } from 'fs';
5-
import { existsSync, copyFile } from 'node:fs';
6+
import { copyFile, existsSync } from 'node:fs';
67
import fsPromises from 'node:fs/promises';
78
import path from 'node:path';
8-
import { hashElement } from 'folder-hash';
99
import process from 'process';
10-
import fs from 'fs';
1110

1211
import { DownloadedEntry, Version } from '../../types/ipc';
1312
import { getAuthToken } from './authentication';
@@ -53,31 +52,31 @@ function setDownloadedVersion(
5352
store.set('downloadedAssetVersions', newDownloads);
5453
}
5554

56-
export async function getFolderHash(filePath: string): Promise<string>{
55+
export async function getFolderHash(filePath: string): Promise<string> {
5756
return hashElement(filePath)
58-
.then(hash => {
59-
return hash['hash'].toString()
60-
})
61-
.catch(error => {
62-
console.error('hashing failed:', error);
63-
});
57+
.then((hash) => {
58+
return hash['hash'].toString();
59+
})
60+
.catch((error) => {
61+
console.error('hashing failed:', error);
62+
});
6463
}
6564

6665
export async function ifFilesChanged(asset_id: string): Promise<boolean> {
67-
// compare current with saved hash
68-
const downloads = await getDownloadedVersions()
69-
const saved_asset = downloads.find((a) => asset_id === a.asset_id)
66+
// compare current with saved hash
67+
const downloads = await getDownloadedVersions();
68+
const saved_asset = downloads.find((a) => asset_id === a.asset_id);
7069
if (saved_asset === undefined) {
71-
return true
70+
return true;
7271
}
73-
const saved_hash = saved_asset.folderHash
72+
const saved_hash = saved_asset.folderHash;
7473

7574
// what is the current hash
76-
const folderName = saved_asset.folderName
75+
const folderName = saved_asset.folderName;
7776
const folderPath = path.join(getDownloadFolder(), folderName);
78-
const current_hash = await getFolderHash(folderPath)
79-
80-
return (current_hash !== saved_hash)
77+
const current_hash = await getFolderHash(folderPath);
78+
79+
return current_hash !== saved_hash;
8180
}
8281

8382
/**
@@ -100,7 +99,7 @@ export async function createInitialVersion({
10099
console.log('adding to store');
101100

102101
// hash new folder
103-
const folderHash = await getFolderHash(folderPath)
102+
const folderHash = await getFolderHash(folderPath);
104103
setDownloadedVersion(asset_id, { semver: null, folderName, folderHash });
105104
}
106105

@@ -190,7 +189,7 @@ export async function commitChanges(asset_id: string, message: string, is_major:
190189
}
191190

192191
// Update saved hash
193-
const folderHash = await getFolderHash(sourceFolder)
192+
const folderHash = await getFolderHash(sourceFolder);
194193

195194
// Update store with currently downloaded version
196195
const { semver } = result.data as Version;
@@ -244,7 +243,7 @@ export async function downloadVersion({ asset_id, semver }: { asset_id: string;
244243
// previously had semver in here but probably not necessary
245244
// const folderName = `${asset_name}_${semver}_${asset_id.substring(0, 8)}/`;
246245
const folderName = `${asset_name}_${asset_id.substring(0, 8)}/`;
247-
const folderPath = path.join(getDownloadFolder(), folderName)
246+
const folderPath = path.join(getDownloadFolder(), folderName);
248247

249248
// remove old copy of folder
250249
await fsPromises.rm(path.join(getDownloadFolder(), folderName), { force: true, recursive: true });
@@ -253,7 +252,7 @@ export async function downloadVersion({ asset_id, semver }: { asset_id: string;
253252
console.log('removing zip file...');
254253
await fsPromises.rm(zipFilePath);
255254

256-
const folderHash = await getFolderHash(folderPath)
255+
const folderHash = await getFolderHash(folderPath);
257256
console.log('marking as stored!');
258257
setDownloadedVersion(asset_id, { semver, folderName, folderHash });
259258

@@ -281,10 +280,13 @@ export async function unsyncAsset(asset_id: string) {
281280
}
282281

283282
function getCommandLine() {
284-
switch (process.platform) {
285-
case 'darwin' : return 'open ';
286-
case 'win32' : return 'start ';
287-
default : return 'xdg-open';
283+
switch (process.platform) {
284+
case 'darwin':
285+
return 'open ';
286+
case 'win32':
287+
return 'start ';
288+
default:
289+
return 'xdg-open';
288290
}
289291
}
290292

@@ -304,48 +306,52 @@ export async function openHoudini(asset_id: string) {
304306
if (!process.env.HFS) return;
305307
const houdiniCmd = path.join(process.env.HFS, '/bin/houdini');
306308

307-
const { spawn, exec } = require("child_process");
309+
const { spawn, exec } = require('child_process');
308310

309311
// If there's an existing Houdini file, open it.
310312
const destination = path.join(downloadsFullpath, `${assetName}.hipnc`);
311313
if (existsSync(destination)) {
312314
exec(getCommandLine() + destination);
313315
console.log(`Launching the existing Houdini file for ${asset_id}...`);
314-
}
316+
}
315317
// Otherwise, load asset in a new template.
316318
else {
317319
const existsUsdOld = existsSync(path.join(downloadsFullpath, 'root.usda'));
318320
const existsUsdNew = existsSync(path.join(downloadsFullpath, `${assetName}.usda`));
319-
const houdiniTemplate = (!existsUsdOld && !existsUsdNew) ? 'CreateNew.hipnc' : 'Update.hipnc';
321+
const houdiniTemplate = !existsUsdOld && !existsUsdNew ? 'CreateNew.hipnc' : 'Update.hipnc';
320322
const templateFullpath = path.join(process.cwd(), `${houdini_src}${houdiniTemplate}`);
321-
323+
322324
// Copy template to asset's folder so we don't always edit on the same file
323325
copyFile(templateFullpath, destination, (err) => {
324326
if (err) throw err;
325327
console.log(`${houdiniTemplate} was copied to ${destination}`);
326328
});
327-
329+
328330
const pythonScript = path.join(process.cwd(), `${houdini_src}/launchTemplate.py`);
329-
331+
330332
// Launch houdini with a python session attached
331-
const bat = spawn(houdiniCmd, [
332-
destination, // Argument for cmd to carry out the specified file
333-
pythonScript, // Path to your script
334-
"-a", // First argument
335-
assetName, // n-th argument
336-
"-o",
337-
downloadsFullpath,
338-
"-n",
339-
downloadsFullpath
340-
], {
341-
shell: true,
342-
});
343-
344-
bat.stdout.on("data", (data) => {
333+
const bat = spawn(
334+
houdiniCmd,
335+
[
336+
destination, // Argument for cmd to carry out the specified file
337+
pythonScript, // Path to your script
338+
'-a', // First argument
339+
assetName, // n-th argument
340+
'-o',
341+
downloadsFullpath,
342+
'-n',
343+
downloadsFullpath,
344+
],
345+
{
346+
shell: true,
347+
},
348+
);
349+
350+
bat.stdout.on('data', (data) => {
345351
console.log(data.toString());
346352
});
347-
348-
bat.stderr.on("data", (err) => {
353+
354+
bat.stderr.on('data', (err) => {
349355
console.log(err.toString());
350356
});
351357
}
@@ -366,40 +372,42 @@ export async function quietRenderHoudini(asset_id: string) {
366372
if (!process.env.HFS) return;
367373
const houdiniHython = path.join(process.env.HFS, '/bin/hython');
368374

369-
const { spawn } = require("child_process");
375+
const { spawn } = require('child_process');
370376

371377
const pythonScript = path.join(process.cwd(), `${houdini_src}/quietRender.py`);
372-
378+
373379
// locate the asset USD file based on different asset structures
374380
const usdNewFullpath = path.join(downloadsFullpath, 'root.usda');
375381
const usdOldFullpath = path.join(downloadsFullpath, `${assetName}.usda`);
376382
let assetFullpath;
377383
if (existsSync(usdOldFullpath)) {
378384
assetFullpath = usdOldFullpath;
379-
}
380-
else if (existsSync(usdNewFullpath)) {
385+
} else if (existsSync(usdNewFullpath)) {
381386
assetFullpath = usdNewFullpath;
382-
}
383-
else {
384-
console.log("No correct asset USD to render!");
387+
} else {
388+
console.log('No correct asset USD to render!');
385389
return;
386390
}
387-
388-
const bat = spawn(houdiniHython, [
389-
pythonScript, // Argument for cmd to carry out the specified file
390-
"-a", // First argument
391-
assetFullpath, // n-th argument
392-
"-o",
393-
downloadsFullpath
394-
], {
395-
shell: true,
396-
});
397-
398-
bat.stdout.on("data", (data) => {
391+
392+
const bat = spawn(
393+
houdiniHython,
394+
[
395+
pythonScript, // Argument for cmd to carry out the specified file
396+
'-a', // First argument
397+
assetFullpath, // n-th argument
398+
'-o',
399+
downloadsFullpath,
400+
],
401+
{
402+
shell: true,
403+
},
404+
);
405+
406+
bat.stdout.on('data', (data) => {
399407
console.log(data.toString());
400408
});
401-
402-
bat.stderr.on("data", (err) => {
409+
410+
bat.stderr.on('data', (err) => {
403411
console.log(err.toString());
404412
});
405413
}

frontend/src/main/message-handlers.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ import {
1515
// Types for these can be found in `src/types/ipc.d.ts`
1616
const messageHandlers: MessageHandlers = {
1717
'assets:list-downloaded': async () => {
18-
// console.log('getting downloaded:', getStoredVersions());
1918
return { ok: true, versions: getDownloadedVersions() };
2019
},
2120
'assets:download-asset': async (_, { asset_id }) => {
@@ -33,6 +32,7 @@ const messageHandlers: MessageHandlers = {
3332
return { ok: true };
3433
},
3534
'assets:remove-download': async (_, { asset_id }) => {
35+
console.log(`Unsyncing ${asset_id}`);
3636
await unsyncAsset(asset_id);
3737
return { ok: true };
3838
},

frontend/src/renderer/src/components/forms/new-user-form.tsx

+3-3
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ export default function NewUserForm({
5353
// --------------------------------------------
5454

5555
const submitHandler = async (data: NewUserFormData) => {
56-
// create profile pic uri
56+
// create profile pic uri
5757
let encoded_uri = '';
5858

5959
// check if picture file exists
@@ -65,8 +65,8 @@ export default function NewUserForm({
6565
console.error('Error encoding profile image:', err);
6666
return;
6767
}
68-
}
69-
68+
}
69+
7070
// Create the user
7171
try {
7272
const { error } = await fetchClient.POST('/api/v1/users/', {

frontend/src/renderer/src/components/input/filter-keywords-input.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ function ControlledInput({ inputName, inputs, setInputs }: ControlledInputProps)
3333

3434
return (
3535
<label className="block">
36-
<Label label={`By ${inputName}`} />
36+
<Label label={inputName} />
3737
<div className="relative w-full">
3838
<input
3939
type="text"

frontend/src/renderer/src/components/layout/navbar-filter.tsx

+6-4
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,13 @@ import ControlledKeywordsInput from '../input/filter-keywords-input';
99
import Label from '../input/label';
1010

1111
const NavbarFilter = () => {
12-
const [dropdownVisible, setDropdownVisible] = useState(false); // State to control dropdown visibility
12+
// State to control dropdown visibility
13+
const [dropdownVisible, setDropdownVisible] = useState(false);
1314

1415
const { keywords, archived, setKeywords, setArchived } = useSearchParamsStore();
1516
const { sort, setSort } = useSearchParamsStore();
1617

18+
// close on click outside
1719
const ref = useRef<HTMLDivElement>(null!);
1820
useOnClickOutside(ref, () => setDropdownVisible(false));
1921

@@ -25,7 +27,7 @@ const NavbarFilter = () => {
2527
<div
2628
tabIndex={0}
2729
role="button"
28-
className="btn btn-outline flex items-center"
30+
className="btn btn-ghost flex items-center"
2931
onClick={() => setDropdownVisible((v) => !v)}
3032
>
3133
<CiFilter className="h-6 w-6" />
@@ -56,7 +58,7 @@ const NavbarFilter = () => {
5658
{/* Keyword constraints */}
5759
<li className="mb-4">
5860
<ControlledKeywordsInput
59-
inputName={'Keywords'}
61+
inputName={'Require Keywords'}
6062
inputs={keywords}
6163
setInputs={setKeywords}
6264
/>
@@ -77,7 +79,7 @@ const NavbarFilter = () => {
7779
<li className="form-control">
7880
<label className="label cursor-pointer">
7981
<span
80-
className={`label-text flex items-center gap-2 transition-colors ${archived ? 'text-warning' : ''}`}
82+
className={`label-text -mx-3 -my-1 flex items-center gap-2 rounded-badge px-3 py-1 transition-colors ${archived ? 'bg-warning text-warning-content' : ''}`}
8183
>
8284
<MdArchive />
8385
Show Archived

frontend/src/renderer/src/components/layout/navbar.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ const Navbar = () => {
3131
{/* Center Group */}
3232
<div className="flex flex-grow items-center justify-center gap-x-4 ">
3333
{/* New Asset Button */}
34-
<Link className="btn btn-outline" to={loggedIn ? '/new-asset' : '/user-login'}>
34+
<Link className="btn btn-ghost" to={loggedIn ? '/new-asset' : '/user-login'}>
3535
{loggedIn ? (
3636
<>
3737
<MdCreate /> New Asset

0 commit comments

Comments
 (0)