Skip to content

Commit

Permalink
feat: refactor of UI to use mantine (#290)
Browse files Browse the repository at this point in the history
A huge refactor. This replaces all uses of EUI in favor of Mantine. This was to remove some of the strange setup required by EUI (themes, icons, etc.)

Additionally contains the work of adding the blocknote (tiptap extended) description parser. Somewhat in a messy state, but works well enough to move forward with at the moment.
  • Loading branch information
mvdicarlo authored Sep 30, 2024
1 parent ba3f043 commit 8fa8208
Show file tree
Hide file tree
Showing 269 changed files with 12,792 additions and 13,100 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,13 @@ export class Account extends PostyBirbEntity implements IAccount {
supports: [],
};

constructor(account: Partial<IAccount> & Pick<IAccount, 'name' | 'website'>) {
super();
this.name = account.name;
this.website = account.website;
this.groups = account.groups;
}

toJSON(): IAccountDto {
return serialize(this) as IAccountDto;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,13 @@ export class DirectoryWatcher
})
template?: Rel<Submission>;

constructor(directoryWatcher: IDirectoryWatcher) {
super();
this.path = directoryWatcher.path;
this.importAction = directoryWatcher.importAction;
this.template = directoryWatcher.template as Submission;
}

toJSON(): DirectoryWatcherDto {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
return serialize(this as any, {
Expand Down
13 changes: 13 additions & 0 deletions apps/client-server/src/app/database/entities/post-record.entity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,19 @@ export class PostRecord extends PostyBirbEntity implements IPostRecord {
@Property({ type: 'string', nullable: false })
resumeMode: PostRecordResumeMode = PostRecordResumeMode.CONTINUE;

constructor(
postRecord: Pick<
IPostRecord,
'parent' | 'completedAt' | 'state' | 'resumeMode'
>
) {
super();
this.parent = postRecord.parent as unknown as Submission;
this.completedAt = postRecord.completedAt;
this.state = postRecord.state;
this.resumeMode = postRecord.resumeMode;
}

toJSON(): PostRecordDto {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
return serialize(this as any, { populate: ['children'] }) as PostRecordDto;
Expand Down
11 changes: 11 additions & 0 deletions apps/client-server/src/app/database/entities/submission.entity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,17 @@ export class Submission<T extends ISubmissionMetadata = ISubmissionMetadata>
})
posts: Collection<IPostRecord>;

@Property({ type: 'number', nullable: true })
order: number;

constructor(submission: Partial<ISubmission<T>>) {
super();
this.type = submission.type;
this.isScheduled = submission.isScheduled;
this.schedule = submission.schedule;
this.metadata = submission.metadata ?? ({} as T);
}

toJSON(): ISubmissionDto<T> {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
return serialize(this as any, {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,13 @@ export class WebsiteOptions<T extends IWebsiteFormFields = IWebsiteFormFields>
return this?.account?.id === NULL_ACCOUNT_ID;
}

constructor(websiteOptions: Partial<IWebsiteOptions<T>>) {
super();
this.submission = websiteOptions.submission as Submission;
this.data = websiteOptions.data;
this.account = websiteOptions.account as Account;
}

toJSON(): WebsiteOptionsDto<T> {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
return serialize(this as any, {
Expand Down
30 changes: 22 additions & 8 deletions apps/client-server/src/app/file/file.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,17 @@ import { readFileSync } from 'fs';
import { join } from 'path';
import { AccountService } from '../account/account.service';
import { DatabaseModule } from '../database/database.module';
import { FormGeneratorService } from '../form-generator/form-generator.service';
import { DescriptionParserService } from '../post-parsers/parsers/description-parser.service';
import { TagParserService } from '../post-parsers/parsers/tag-parser.service';
import { TitleParserService } from '../post-parsers/parsers/title-parser.service';
import { PostParsersService } from '../post-parsers/post-parsers.service';
import { SettingsService } from '../settings/settings.service';
import { CreateSubmissionDto } from '../submission/dtos/create-submission.dto';
import { FileSubmissionService } from '../submission/services/file-submission.service';
import { MessageSubmissionService } from '../submission/services/message-submission.service';
import { SubmissionService } from '../submission/services/submission.service';
import { TagConvertersService } from '../tag-converters/tag-converters.service';
import { UserSpecifiedWebsiteOptionsService } from '../user-specified-website-options/user-specified-website-options.service';
import { WebsiteOptionsService } from '../website-options/website-options.service';
import { WebsiteImplProvider } from '../websites/implementations';
Expand Down Expand Up @@ -76,6 +83,13 @@ describe('FileService', () => {
WebsiteRegistryService,
WebsiteOptionsService,
WebsiteImplProvider,
PostParsersService,
TagParserService,
DescriptionParserService,
TitleParserService,
TagConvertersService,
SettingsService,
FormGeneratorService,
],
}).compile();

Expand Down Expand Up @@ -107,11 +121,11 @@ describe('FileService', () => {
expect(file.size).toBe(fileInfo.size);
expect(file.hasThumbnail).toBe(true);
expect(file.props.hasCustomThumbnail).toBe(false);
expect(file.height).toBe(100);
expect(file.width).toBe(100);
expect(file.height).toBe(202);
expect(file.width).toBe(138);
expect(file.file.size).toBe(fileInfo.size);
expect(file.file.height).toBe(100);
expect(file.file.width).toBe(100);
expect(file.file.height).toBe(202);
expect(file.file.width).toBe(138);
expect(file.file.parent.id).toEqual(file.id);
expect(file.file.mimeType).toEqual(fileInfo.mimetype);
expect(file.file.buffer).toEqual(testFile);
Expand Down Expand Up @@ -143,11 +157,11 @@ describe('FileService', () => {
expect(updatedFile.size).toBe(updateFileInfo.size);
expect(updatedFile.hasThumbnail).toBe(true);
expect(updatedFile.props.hasCustomThumbnail).toBe(false);
expect(updatedFile.height).toBe(100);
expect(updatedFile.width).toBe(100);
expect(updatedFile.height).toBe(202);
expect(updatedFile.width).toBe(138);
expect(updatedFile.file.size).toBe(updateFileInfo.size);
expect(updatedFile.file.height).toBe(100);
expect(updatedFile.file.width).toBe(100);
expect(updatedFile.file.height).toBe(202);
expect(updatedFile.file.width).toBe(138);
expect(updatedFile.file.parent.id).toEqual(file.id);
expect(updatedFile.file.mimeType).not.toEqual(updateFileInfo.mimetype);
expect(updatedFile.file.buffer).toEqual(testFile);
Expand Down
21 changes: 4 additions & 17 deletions apps/client-server/src/app/file/services/create-file.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,9 @@ import {
import { PostyBirbRepository } from '../../database/repositories/postybirb-repository';
import { MulterFileInfo } from '../models/multer-file-info';
import { ImageUtil } from '../utils/image.util';
import { IsTestEnvironment } from '../../utils/test.util';

/**
* A Service that defines operations for creating a SubmissionFile.
* TODO check unit tests now that update has happened
* !Sharp hangs when run in test environment. Not sure why, but for now, returning
* !dummy data is enough for testing.
* TODO figure out why multi-submission sometimes breaks entity population
* @class CreateFileService
*/
@Injectable()
Expand Down Expand Up @@ -122,14 +117,10 @@ export class CreateFileService {
const sharpInstance = ImageUtil.load(buf);
let height = 0;
let width = 0;
if (IsTestEnvironment()) {
height = 100;
width = 100;
} else {
const meta = await sharpInstance.metadata();
height = meta.height;
width = meta.width;
}

const meta = await sharpInstance.metadata();
height = meta.height;
width = meta.width;

entity.width = width;
entity.height = height;
Expand Down Expand Up @@ -206,10 +197,6 @@ export class CreateFileService {
width = Math.min(fileWidth, width);
}

if (IsTestEnvironment()) {
return { buffer: Buffer.from([]), height, width };
}

const buffer = await sharpInstance
.resize(width, height)
.png({ quality: 90, force: true })
Expand Down
11 changes: 0 additions & 11 deletions apps/client-server/src/app/file/services/update-file.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import { PostyBirbRepository } from '../../database/repositories/postybirb-repos
import { MulterFileInfo } from '../models/multer-file-info';
import { ImageUtil } from '../utils/image.util';
import { CreateFileService } from './create-file.service';
import { IsTestEnvironment } from '../../utils/test.util';

/**
* A Service for updating existing SubmissionFile entities.
Expand All @@ -31,7 +30,6 @@ export class UpdateFileService {

/**
* Creates file entity and stores it.
* @todo extra data (image resize per website)
* @todo figure out what to do about non-image
*
* @param {MulterFileInfo} file
Expand Down Expand Up @@ -157,15 +155,6 @@ export class UpdateFileService {
if (ImageUtil.isImage(file.mimetype, false)) {
const sharpInstance = ImageUtil.load(buf);

if (IsTestEnvironment()) {
return {
height: 100,
width: 100,
buffer: buf,
sharpInstance,
};
}

const { height, width } = await sharpInstance.metadata();
return { buffer: buf, width, height, sharpInstance };
}
Expand Down
Loading

0 comments on commit 8fa8208

Please sign in to comment.