diff options
author | (quasar) nebula <qznebula@protonmail.com> | 2022-11-28 23:25:05 -0400 |
---|---|---|
committer | (quasar) nebula <qznebula@protonmail.com> | 2022-11-28 23:25:05 -0400 |
commit | 690a7b53a72ac71f9f76260fa50c634566c4e984 (patch) | |
tree | 841653cf0e474c6edd437ec36884f2130b5b7b43 /src/data/things/group.js | |
parent | ae9dba60c4bbb327b402c500cc042922a954de74 (diff) |
divide things.js into modular files (hilariously)
Diffstat (limited to 'src/data/things/group.js')
-rw-r--r-- | src/data/things/group.js | 94 |
1 files changed, 94 insertions, 0 deletions
diff --git a/src/data/things/group.js b/src/data/things/group.js new file mode 100644 index 00000000..26fe9a55 --- /dev/null +++ b/src/data/things/group.js @@ -0,0 +1,94 @@ +import Thing from './thing.js'; + +import find from '../../util/find.js'; + +export class Group extends Thing { + static [Thing.referenceType] = 'group'; + + static [Thing.getPropertyDescriptors] = ({ + Album, + }) => ({ + // Update & expose + + name: Thing.common.name('Unnamed Group'), + directory: Thing.common.directory(), + + description: Thing.common.simpleString(), + + urls: Thing.common.urls(), + + // Update only + + albumData: Thing.common.wikiData(Album), + groupCategoryData: Thing.common.wikiData(GroupCategory), + + // Expose only + + descriptionShort: { + flags: {expose: true}, + + expose: { + dependencies: ['description'], + compute: ({description}) => description.split('<hr class="split">')[0], + }, + }, + + albums: { + flags: {expose: true}, + + expose: { + dependencies: ['albumData'], + compute: ({albumData, [Group.instance]: group}) => + albumData?.filter((album) => album.groups.includes(group)) ?? [], + }, + }, + + color: { + flags: {expose: true}, + + expose: { + dependencies: ['groupCategoryData'], + + compute: ({groupCategoryData, [Group.instance]: group}) => + groupCategoryData.find((category) => category.groups.includes(group)) + ?.color, + }, + }, + + category: { + flags: {expose: true}, + + expose: { + dependencies: ['groupCategoryData'], + compute: ({groupCategoryData, [Group.instance]: group}) => + groupCategoryData.find((category) => category.groups.includes(group)) ?? + null, + }, + }, + }); +} + +export class GroupCategory extends Thing { + static [Thing.getPropertyDescriptors] = ({ + Group, + }) => ({ + // Update & expose + + name: Thing.common.name('Unnamed Group Category'), + color: Thing.common.color(), + + groupsByRef: Thing.common.referenceList(Group), + + // Update only + + groupData: Thing.common.wikiData(Group), + + // Expose only + + groups: Thing.common.dynamicThingsFromReferenceList( + 'groupsByRef', + 'groupData', + find.group + ), + }); +} |