Skip to content

Commit

Permalink
order from backend
Browse files Browse the repository at this point in the history
  • Loading branch information
mruwnik committed Feb 20, 2024
1 parent a78b656 commit 716e68c
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 2 deletions.
8 changes: 6 additions & 2 deletions app/routes/questions.toc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ export type TOCItem = {
hasText: boolean
children?: TOCItem[]
category?: Category
order: number
}
type LoaderResp = {
data: TOCItem[]
Expand All @@ -29,16 +30,19 @@ const getCategory = (tags: string[]): Category => {
return undefined
}

const byOrder = (a: TOCItem, b: TOCItem) => a.order - b.order
const formatQuestion =
(level: number) =>
({title, pageid, subtitle, icon, children, text, tags}: Question): TOCItem => ({
({title, pageid, subtitle, icon, children, text, tags, order}: Question): TOCItem => ({
title,
subtitle: subtitle ? subtitle : undefined,
pageid,
icon: icon ? icon : undefined,
hasText: !!text,
children: level < MAX_LEVELS ? children?.map(formatQuestion(level + 1)) : undefined,
children:
level < MAX_LEVELS ? children?.map(formatQuestion(level + 1)).sort(byOrder) : undefined,
category: getCategory(tags),
order: order || 0,
})

const getToc = async (request: any) => {
Expand Down
3 changes: 3 additions & 0 deletions app/server-utils/stampy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ export type Question = {
icon?: string
parents?: string[]
children?: Question[]
order?: number
}
export type PageId = Question['pageid']
export type NewQuestion = {
Expand Down Expand Up @@ -133,6 +134,7 @@ export type AnswersRow = CodaRowCommon & {
Subtitle?: string
Icon?: string
Parents?: Entity[]
Order?: number
}
}
type TagsRow = CodaRowCommon & {
Expand Down Expand Up @@ -292,6 +294,7 @@ const convertToQuestion = ({name, values, updatedAt} = {} as AnswersRow): Questi
icon: extractText(values.Icon),
parents: !values.Parents ? [] : values.Parents?.map(({name}) => name),
updatedAt: updatedAt || values['Doc Last Edited'],
order: values.Order || 0,
})

export const loadQuestionDetail = withCache('questionDetail', async (question: string) => {
Expand Down
16 changes: 16 additions & 0 deletions stories/ArticlesNav.stories.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,85 +18,101 @@ const article = {
pageid: '9OGZ',
icon: '/assets/coded-banner.svg',
hasText: true,
order: 0,
children: [
{
title: 'What would an AGI be able to do?',
pageid: 'NH51',
hasText: false,
order: 0,
},
{
title: 'Types of AI',
pageid: 'NH50',
hasText: false,
order: 0,
children: [
{
title: 'What are the differences between AGI, transformative AI, and superintelligence?',
pageid: '5864',
hasText: true,
order: 0,
},
{
title: 'What is intelligence?',
pageid: '6315',
hasText: true,
order: 0,
},
{
title: 'What is artificial general intelligence (AGI)?',
pageid: '2374',
hasText: true,
order: 0,
},
{
title: 'What is "superintelligence"?',
pageid: '6207',
hasText: true,
order: 0,
},
{
title: 'What is artificial intelligence (AI)?',
pageid: '8G1H',
hasText: true,
order: 0,
},
],
},
{
title: 'Introduction to ML',
pageid: 'NH50',
hasText: false,
order: 0,
children: [
{
title: 'What are large language models?',
pageid: '8161',
hasText: true,
order: 0,
},
{
title: 'What is compute?',
pageid: '9358',
hasText: true,
order: 0,
},
],
},
{
title: 'Introduction to AI Safety',
pageid: 'NH53',
hasText: false,
order: 0,
children: [
{
title: 'Why would an AI do bad things?',
pageid: '2400',
hasText: true,
order: 0,
},
{
title: 'How likely is extinction from superintelligent AI?',
pageid: '7715',
hasText: true,
order: 0,
},
{
title: 'What is AI safety?',
pageid: '8486',
hasText: true,
order: 0,
},
{
title: 'Why is safety important for smarter-than-human AI?',
pageid: '6297',
hasText: true,
order: 0,
},
],
},
Expand Down
8 changes: 8 additions & 0 deletions stories/Grid.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,55 +8,63 @@ const toc = [
icon: 'https://cataas.com/cat/says/section1',
pageid: 'https://google.com',
hasText: true,
order: 0,
},
{
title: 'Governance',
subtitle: 'Lorem ipsum dolor sit amet consectetur',
icon: 'https://cataas.com/cat/says/section2',
pageid: 'https://google.com',
hasText: true,
order: 0,
},
{
title: 'Existential risk concepts',
subtitle: 'Lorem ipsum dolor sit amet consectetur',
icon: 'https://cataas.com/cat/says/section3',
pageid: 'https://google.com',
hasText: true,
order: 0,
},
{
title: 'Predictions on advanced AI',
subtitle: 'Lorem ipsum dolor sit amet consectetur',
icon: 'https://cataas.com/cat/says/section4',
pageid: 'https://google.com',
hasText: true,
order: 0,
},
{
title: 'Prominent research organizations',
subtitle: 'Lorem ipsum dolor sit amet consectetur',
icon: 'https://cataas.com/cat/says/section5',
pageid: 'https://google.com',
hasText: true,
order: 0,
},
{
title: '6th item',
subtitle: 'Lorem ipsum dolor sit amet consectetur',
icon: 'https://cataas.com/cat/says/section6',
pageid: 'https://google.com',
hasText: true,
order: 10,
},
{
title: '7th item',
subtitle: 'Lorem ipsum dolor sit amet consectetur',
icon: 'https://cataas.com/cat/says/section7',
pageid: 'https://google.com',
hasText: true,
order: 20,
},
{
title: '8th item',
subtitle: 'Lorem ipsum dolor sit amet consectetur',
icon: 'https://cataas.com/cat/says/section8',
pageid: 'https://google.com',
hasText: true,
order: 30,
},
]

Expand Down
16 changes: 16 additions & 0 deletions stories/Nav.stories.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,86 +81,102 @@ export const Primary: Story = {
subtitle: 'Basic information about all of this',
pageid: '9OGZ',
hasText: true,
order: 0,
children: [
{
title: 'What would an AGI be able to do?',
pageid: 'NH50',
hasText: false,
order: 0,
},
{
title: 'Types of AI',
pageid: 'NH50',
hasText: false,
order: 0,
children: [
{
title:
'What are the differences between AGI, transformative AI, and superintelligence?',
pageid: '5864',
hasText: true,
order: 0,
},
{
title: 'What is intelligence?',
pageid: '6315',
hasText: true,
order: 12,
},
{
title: 'What is artificial general intelligence (AGI)?',
pageid: '2374',
hasText: true,
order: 14,
},
{
title: 'What is "superintelligence"?',
pageid: '6207',
hasText: true,
order: 15,
},
{
title: 'What is artificial intelligence (AI)?',
pageid: '8G1H',
hasText: true,
order: 17,
},
],
},
{
title: 'Introduction to ML',
pageid: 'NH50',
hasText: false,
order: 13,
children: [
{
title: 'What are large language models?',
pageid: '8161',
hasText: true,
order: 1,
},
{
title: 'What is compute?',
pageid: '9358',
hasText: true,
order: 15,
},
],
},
{
title: 'Introduction to AI Safety',
pageid: 'NH50',
hasText: false,
order: 1,
children: [
{
title: 'Why would an AI do bad things?',
pageid: '2400',
hasText: true,
order: 1,
},
{
title: 'How likely is extinction from superintelligent AI?',
pageid: '7715',
hasText: true,
order: 1,
},
{
title: 'What is AI safety?',
pageid: '8486',
hasText: true,
order: 1,
},
{
title: 'Why is safety important for smarter-than-human AI?',
pageid: '6297',
hasText: true,
order: 51,
},
],
},
Expand Down

0 comments on commit 716e68c

Please sign in to comment.