Skip to content

Commit 7bb6af3

Browse files
committed
refact: simplified categories structure source, only from JSON
1 parent 4ecc1d4 commit 7bb6af3

File tree

4 files changed

+24
-102
lines changed

4 files changed

+24
-102
lines changed

src/components/statementWizard/StatementWizard.tsx

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -74,12 +74,13 @@ const StatementWizard: React.FC<StatementWizardProps> = ({
7474
...prev,
7575
atoms: { ...prev.atoms, subject: username },
7676
}));
77-
}
78-
79-
// For custom statements, set the default category to 'uncategorised'
80-
if (!presetQuestion) {
77+
} else {
78+
// For custom statements, set defaults:
8179
setSelection((prev) => ({
8280
...prev,
81+
// Set default subject to username
82+
atoms: { ...prev.atoms, subject: username },
83+
// Set default category to 'uncategorised'
8384
category: 'uncategorised',
8485
}));
8586
}

src/components/statementWizard/steps/CategoryStep.tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,10 @@ export const CategoryStep: React.FC<CategoryStepProps> = ({
1515
}) => {
1616
const subQuestion = `You can set a category for your statement`;
1717
const categories = statementsCategories.categories || [];
18-
const uncategorisedSelected = !selection || selection === 'uncategorised';
18+
// Handle all possible variations of "uncategorized"
19+
const uncategorisedSelected = !selection ||
20+
selection.toLowerCase() === 'uncategorised' ||
21+
selection.toLowerCase() === 'uncategorized';
1922

2023
return (
2124
<StepContainer subQuestion={subQuestion} showBack>

utils/categoryUtils.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,13 @@
11
import type { Category } from '../types/entries';
2+
import categoryStructure from '../data/categoryStructure.json';
3+
4+
/**
5+
* Gets the root category from the category structure.
6+
* This is a private helper function used within this module only.
7+
*/
8+
function getCategoryRoot(): Category {
9+
return categoryStructure.root as Category;
10+
}
211

312
/**
413
* Recursively searches for a category node with the given name.
@@ -35,7 +44,7 @@ export function getAllDescendants(node: Category): string[] {
3544
*/
3645
export function getVerbColor(
3746
verb: { categories: string[] },
38-
root: Category
47+
root: Category = getCategoryRoot()
3948
): string {
4049
for (const catName of verb.categories) {
4150
const cat = findCategoryByName(root, catName);

utils/verbUtils.ts

Lines changed: 5 additions & 96 deletions
Original file line numberDiff line numberDiff line change
@@ -2,101 +2,10 @@ import { Verb } from '../types/entries';
22
import nlp from 'compromise';
33
import verbData from '../data/verbs.json';
44

5-
const sentimentCategories = {
6-
positive: [
7-
{
8-
name: 'Support & Assistance',
9-
subcategories: ['Support & Help', 'Guide & Encourage'],
10-
},
11-
{
12-
name: 'Growth & Development',
13-
subcategories: ['Personal Growth', 'Adaptation & Learning'],
14-
},
15-
{
16-
name: 'Innovation & Creation',
17-
subcategories: ['Creative Process', 'Implementation'],
18-
},
19-
{
20-
name: 'Collaboration & Connection',
21-
subcategories: ['Teamwork', 'Engagement'],
22-
},
23-
{
24-
name: 'Achievement & Leadership',
25-
subcategories: ['Leadership', 'Achievement'],
26-
},
27-
],
28-
negative: [
29-
{
30-
name: 'Conflict & Opposition',
31-
subcategories: ['Direct Conflict', 'Resistance'],
32-
},
33-
{
34-
name: 'Obstruction & Hindrance',
35-
subcategories: ['Active Obstruction', 'Passive Hindrance'],
36-
},
37-
{
38-
name: 'Evasion & Avoidance',
39-
subcategories: ['Active Evasion', 'Passive Avoidance'],
40-
},
41-
{
42-
name: 'Criticism & Rejection',
43-
subcategories: ['Criticism', 'Rejection'],
44-
},
45-
{
46-
name: 'Neglect & Indifference',
47-
subcategories: ['Active Neglect', 'Passive Indifference'],
48-
},
49-
{
50-
name: 'Underperformance & Failure',
51-
subcategories: ['Underperformance', 'Failure'],
52-
},
53-
],
54-
};
55-
56-
const categorizeBySentiment = (verbs: Verb[]) => {
57-
const categorized: Record<string, Record<string, Record<string, Verb[]>>> = {
58-
positive: {},
59-
negative: {},
60-
};
61-
62-
// Initialize categories and subcategories
63-
sentimentCategories.positive.forEach((category) => {
64-
categorized.positive[category.name] = {};
65-
category.subcategories.forEach((subcategory) => {
66-
categorized.positive[category.name][subcategory] = [];
67-
});
68-
});
69-
sentimentCategories.negative.forEach((category) => {
70-
categorized.negative[category.name] = {};
71-
category.subcategories.forEach((subcategory) => {
72-
categorized.negative[category.name][subcategory] = [];
73-
});
74-
});
75-
76-
// Group verbs by their categories and subcategories
77-
verbs.forEach((verb) => {
78-
const sentiment = verb.categories.some((cat) =>
79-
sentimentCategories.positive.some((posCategory) =>
80-
posCategory.subcategories.includes(cat)
81-
)
82-
)
83-
? 'positive'
84-
: 'negative';
85-
86-
verb.categories.forEach((category) => {
87-
for (const mainCategory of sentimentCategories[sentiment]) {
88-
if (mainCategory.subcategories.includes(category)) {
89-
categorized[sentiment][mainCategory.name][category].push(verb);
90-
break;
91-
}
92-
}
93-
});
94-
});
95-
96-
return categorized;
97-
};
98-
99-
// Get verb name by id, processed with compromise.
5+
/**
6+
* Gets verb name by id, processed with compromise.
7+
* Converts to present tense and lowercase.
8+
*/
1009
const getVerbName = (verbId: string): string => {
10110
const found = (verbData.verbs as Verb[]).find((v) => v.id === verbId);
10211
if (found) {
@@ -106,4 +15,4 @@ const getVerbName = (verbId: string): string => {
10615
return verbId; // Fallback: return the id if not found.
10716
};
10817

109-
export { getVerbName, categorizeBySentiment, sentimentCategories, type Verb };
18+
export { getVerbName };

0 commit comments

Comments
 (0)