Skip to content

Commit

Permalink
#170 Category set up based on entered hashtags
Browse files Browse the repository at this point in the history
  • Loading branch information
mczachurski committed Jan 13, 2025
1 parent 3ecaa8b commit f45c1b9
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/app/models/category-hashtag.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
export class CategoryHashtag {
public id?: string;
public hashtag = '';
public hashtagNormalized = '';
}
3 changes: 3 additions & 0 deletions src/app/models/category.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
import { CategoryHashtag } from "./category-hashtag";

export class Category {
public id?: string;
public name = '';
public hashtags?: CategoryHashtag[];
}
1 change: 1 addition & 0 deletions src/app/pages/upload/upload.page.html
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ <h1>Upload a photos</h1>
cdkTextareaAutosize #autosize="cdkTextareaAutosize" cdkAutosizeMinRows="4" cdkAutosizeMaxRows="10"
#statusInput="ngModel"
[(ngModel)]="statusText"
(ngModelChange)="onStatusTextChange()"
required
aria-label="Status"
[appMaxLength]="maxStatusLength().toString()">
Expand Down
23 changes: 23 additions & 0 deletions src/app/pages/upload/upload.page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@ export class UploadPage extends ResponsiveComponent implements OnInit {
if (attachmentHashtags.hashtags && attachmentHashtags.hashtags.length > 0) {
const hashtags = attachmentHashtags.hashtags.map(tag => '#' + tag);
this.statusText.update((value) => value + '\n\n' + hashtags.join(' '));
this.setCategoryBasedOnHashtags();
}
} catch (error) {
console.error(error);
Expand Down Expand Up @@ -242,6 +243,28 @@ export class UploadPage extends ResponsiveComponent implements OnInit {
}
}

protected onStatusTextChange(): void {
this.setCategoryBasedOnHashtags();
}

private setCategoryBasedOnHashtags(): void {
if (this.categoryId()) {
return;
}

const statusTextNormalized = this.statusText().toUpperCase();
for (const category of this.categories()) {
if (category.hashtags) {
for (const hashtag of category.hashtags.filter(x => x.hashtagNormalized !== '')) {
if (statusTextNormalized.includes('#' + hashtag.hashtagNormalized)) {
this.categoryId.set(category.id);
return;
}
}
}
}
}

private setPhotoData(uploadPhoto: UploadPhoto): void {
const reader = new FileReader();

Expand Down

0 comments on commit f45c1b9

Please sign in to comment.