Browse Source

fix view when no opportunities exist

Mokhtar Naamani 5 years ago
parent
commit
ad5995a8ff
2 changed files with 18 additions and 19 deletions
  1. 2 2
      packages/joy-roles/src/elements.tsx
  2. 16 17
      packages/joy-roles/src/transport.substrate.ts

+ 2 - 2
packages/joy-roles/src/elements.tsx

@@ -136,9 +136,9 @@ export function GroupLeadView(props: GroupLead & inset) {
           </Label>
         </Card.Description>
       </Card.Content>
-      <Card.Content extra>
+      {/* <Card.Content extra>
         <Label>Something about <Label.Detail> the lead </Label.Detail></Label>
-      </Card.Content>
+      </Card.Content> */}
     </Card>
   )
 }

+ 16 - 17
packages/joy-roles/src/transport.substrate.ts

@@ -268,30 +268,29 @@ export class Transport extends TransportBase implements ITransport {
     )
   }
 
-  currentOpportunities(): Promise<Array<WorkingGroupOpening>> {
-    return new Promise<Array<WorkingGroupOpening>>(async (resolve, reject) => {
+  async currentOpportunities(): Promise<Array<WorkingGroupOpening>> {
       const output = new Array<WorkingGroupOpening>()
-      const highestId = (await this.cachedApi.query.contentWorkingGroup.nextCuratorOpeningId() as u32).toNumber() - 1
-      if (highestId < 0) {
-        resolve([])
-      }
+      const nextId = await this.cachedApi.query.contentWorkingGroup.nextCuratorOpeningId() as CuratorOpeningId;
+
+      // This is chain specfic, but if next id is still 0, it means no curator openings have been added yet
+      if (!nextId.eq(0)) {
+        const highestId = nextId.toNumber() - 1;
 
-      for (let i = highestId; i >= 0; i--) {
-        output.push(await this.curationGroupOpening(i))
+        for (let i = highestId; i >= 0; i--) {
+          output.push(await this.curationGroupOpening(i))
+        }
       }
 
-      resolve(output)
-    })
+      return output
   }
 
   protected async opening(id: number): Promise<Opening> {
-    return new Promise<Opening>(async (resolve, reject) => {
-      const opening = new SingleLinkedMapEntry<Opening>(
-        Opening,
-        await this.cachedApi.query.hiring.openingById(id),
-      )
-      resolve(opening.value)
-    })
+    const opening = new SingleLinkedMapEntry<Opening>(
+      Opening,
+      await this.cachedApi.query.hiring.openingById(id),
+    );
+
+    return opening.value
   }
 
   protected async curatorOpeningApplications(curatorOpeningId: number): Promise<Array<WorkingGroupPair<Application, CuratorApplication>>> {