Skip to content

Commit 109084e

Browse files
committed
Update to new ref properties format, fix a lot of bugs by consequence
1 parent 93c684f commit 109084e

22 files changed

+112
-116
lines changed

pnpm-lock.yaml

Lines changed: 7 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
import Endpoint from 'endpoint/Endpoint'
2+
3+
export default Endpoint('/v2/auth/patreon/campaign/begin', 'get').noResponse()
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
import Endpoint from 'endpoint/Endpoint'
2+
3+
export default Endpoint('/v2/auth/patreon/patron/begin', 'get').noResponse()

src/model/Chapters.ts

Lines changed: 14 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,43 +1,36 @@
1-
import type { ChapterMetadata, ChapterReference } from 'api.fluff4.me'
1+
import type { ChapterMetadata, ChapterReference, WorkReference } from 'api.fluff4.me'
22
import EndpointChapters$authorVanity$workVanity$chapterUrlDelete from 'endpoint/chapters/$author_vanity/$work_vanity/$chapter_url/EndpointChapters$authorVanity$workVanity$chapterUrlDelete'
3-
import type { NewWorkReference } from 'model/Works'
43
import type Component from 'ui/Component'
54
import ConfirmDialog from 'ui/component/core/ConfirmDialog'
65
import type { Quilt } from 'ui/utility/StringApplicator'
76
import Maths from 'utility/maths/Maths'
87

9-
export interface NewChapterReference extends ChapterReference {
10-
author_vanity: string
11-
work_vanity: string
12-
chapter_url: string
13-
}
14-
158
namespace Chapters {
169
export function resolve (reference: ChapterReference | null | undefined, chapters: ChapterMetadata[]): ChapterMetadata | undefined {
17-
return !reference ? undefined : chapters.find(chapter => chapter.author === reference.author && chapter.work === reference.work && chapter.url === reference.url)
10+
return !reference ? undefined : chapters.find(chapter => chapter.author_vanity === reference.author_vanity && chapter.work_vanity === reference.work_vanity && chapter.chapter_url === reference.chapter_url)
1811
}
1912

20-
export function work (reference: Omit<ChapterReference, 'url'>): NewWorkReference
21-
export function work (reference: Omit<ChapterReference, 'url'> | null | undefined): NewWorkReference | undefined
22-
export function work (reference: Omit<ChapterReference, 'url'> | null | undefined): NewWorkReference | undefined {
23-
return !reference ? undefined : { author_vanity: reference.author ?? reference.author_vanity!, work_vanity: reference.work ?? reference.work_vanity! }
13+
export function work (reference: Omit<ChapterReference, 'chapter_url'>): WorkReference
14+
export function work (reference: Omit<ChapterReference, 'chapter_url'> | null | undefined): WorkReference | undefined
15+
export function work (reference: Omit<ChapterReference, 'chapter_url'> | null | undefined): WorkReference | undefined {
16+
return !reference ? undefined : { author_vanity: reference.author_vanity, work_vanity: reference.work_vanity }
2417
}
2518

26-
export function reference (reference: ChapterReference): NewChapterReference
27-
export function reference (reference: ChapterReference | null | undefined): NewChapterReference | undefined
28-
export function reference (reference: ChapterReference | null | undefined): NewChapterReference | undefined {
29-
return !reference ? undefined : { author_vanity: reference.author ?? reference.author_vanity!, work_vanity: reference.work ?? reference.work_vanity!, chapter_url: reference.url ?? reference.chapter_url! }
19+
export function reference (reference: ChapterReference): ChapterReference
20+
export function reference (reference: ChapterReference | null | undefined): ChapterReference | undefined
21+
export function reference (reference: ChapterReference | null | undefined): ChapterReference | undefined {
22+
return !reference ? undefined : { author_vanity: reference.author_vanity, work_vanity: reference.work_vanity, chapter_url: reference.chapter_url }
3023
}
3124

3225
export function getName (chapter?: ChapterMetadata): string | Quilt.Handler | undefined {
3326
if (!chapter)
3427
return undefined
3528

36-
const chapterNumber = Maths.parseIntOrUndefined(chapter.url)
29+
const chapterNumber = Maths.parseIntOrUndefined(chapter.chapter_url)
3730
return _
3831
|| chapter.name
3932
|| (!chapterNumber ? undefined : quilt => quilt['view/chapter/number/label'](chapterNumber))
40-
|| (chapter.url.includes('.') ? quilt => quilt['view/chapter/number/interlude/label'](chapter.url) : undefined)
33+
|| (chapter.chapter_url.includes('.') ? quilt => quilt['view/chapter/number/interlude/label'](chapter.chapter_url) : undefined)
4134
}
4235
}
4336

@@ -59,8 +52,8 @@ export default Object.assign(
5952
if (toast.handleError(response))
6053
return false
6154

62-
if (navigate.isURL(`/work/${chapter.author}/${chapter.work}/chapter/${chapter.url}/**`))
63-
void navigate.toURL(`/work/${chapter.author}/${chapter.work}`)
55+
if (navigate.isURL(`/work/${chapter.author_vanity}/${chapter.work_vanity}/chapter/${chapter.chapter_url}/**`))
56+
void navigate.toURL(`/work/${chapter.author_vanity}/${chapter.work_vanity}`)
6457

6558
return true
6659
},

src/model/Works.ts

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -14,24 +14,19 @@ export const WORK_STATUS_ICONS = {
1414
Hiatus: 'circle-pause',
1515
} satisfies Record<WorkMetadata['status'], ButtonIcon>
1616

17-
export interface NewWorkReference extends WorkReference {
18-
author_vanity: string
19-
work_vanity: string
20-
}
21-
2217
namespace Works {
2318
export function resolve (reference: WorkReference | null | undefined, works: WorkMetadata[]): WorkMetadata | undefined {
24-
return !reference ? undefined : works.find(work => work.author === reference.author && work.vanity === reference.vanity)
19+
return !reference ? undefined : works.find(work => work.author_vanity === reference.author_vanity && work.work_vanity === reference.work_vanity)
2520
}
2621

2722
export function equals (a?: WorkReference | null, b?: WorkReference | null) {
28-
return !!a && !!b && a.author === b.author && a.vanity === b.vanity
23+
return !!a && !!b && a.author_vanity === b.author_vanity && a.work_vanity === b.work_vanity
2924
}
3025

31-
export function reference (work: WorkReference): NewWorkReference
32-
export function reference (work?: WorkReference | null): NewWorkReference | null
33-
export function reference (work?: WorkReference | null): NewWorkReference | null {
34-
return work ? { author_vanity: work.author ?? work.author_vanity!, work_vanity: work.vanity ?? work.work_vanity! } : null
26+
export function reference (work: WorkReference): WorkReference
27+
export function reference (work?: WorkReference | null): WorkReference | null
28+
export function reference (work?: WorkReference | null): WorkReference | null {
29+
return work ? { author_vanity: work.author_vanity, work_vanity: work.work_vanity } : null
3530
}
3631
}
3732

@@ -53,8 +48,8 @@ export default Object.assign(
5348
if (toast.handleError(response))
5449
return false
5550

56-
if (navigate.isURL(`/work/${work.author}/${work.vanity}/**`))
57-
void navigate.toURL(`/author/${work.author}`)
51+
if (navigate.isURL(`/work/${work.author_vanity}/${work.work_vanity}/**`))
52+
void navigate.toURL(`/author/${work.author_vanity}`)
5853

5954
return true
6055
},

src/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,6 @@
2525
}
2626
},
2727
"devDependencies": {
28-
"api.fluff4.me": "1.0.1140"
28+
"api.fluff4.me": "1.0.1145"
2929
}
3030
}

src/pnpm-lock.yaml

Lines changed: 5 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/ui/component/Chapter.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -58,12 +58,12 @@ interface Chapter extends Component, ChapterExtensions
5858
{ }
5959

6060
const Chapter = Component.Builder((component, chapter: ChapterMetadata, work: WorkMetadata, author: AuthorReference & Partial<AuthorMetadata>): Chapter => {
61-
component = Link(`/work/${author.vanity}/${work.vanity}/chapter/${chapter.url}`)
61+
component = Link(`/work/${author.vanity}/${work.work_vanity}/chapter/${chapter.chapter_url}`)
6262
.style('chapter')
6363
.style.toggle(chapter.visibility === 'Private', 'chapter--private')
6464
.style.toggle(chapter.visibility === 'Patreon', 'chapter--patreon', 'patreon-icon-after')
6565

66-
const chapterNumber = Maths.parseIntOrUndefined(chapter.url)
66+
const chapterNumber = Maths.parseIntOrUndefined(chapter.chapter_url)
6767
const number = Component()
6868
.style('chapter-number')
6969
.text.set(chapterNumber ? `${chapterNumber.toLocaleString(navigator.language)}` : '')
@@ -118,7 +118,7 @@ const Chapter = Component.Builder((component, chapter: ChapterMetadata, work: Wo
118118
return component
119119
},
120120
getActions (owner, actions) {
121-
const isOwnChapter = Session.Auth.loggedInAs(owner, chapter.author)
121+
const isOwnChapter = Session.Auth.loggedInAs(owner, chapter.author_vanity)
122122
const shouldShowReorder = State.Every(owner, isOwnChapter, reorderActionHandler.truthy)
123123
actions.addWhen(shouldShowReorder, Button()
124124
.type('flush')
@@ -132,7 +132,7 @@ const Chapter = Component.Builder((component, chapter: ChapterMetadata, work: Wo
132132
.type('flush')
133133
.setIcon('pencil')
134134
.text.use('chapter/action/label/edit')
135-
.event.subscribe('click', () => navigate.toURL(`/work/${author.vanity}/${work.vanity}/chapter/${State.value(chapter).url}/edit`))
135+
.event.subscribe('click', () => navigate.toURL(`/work/${author.vanity}/${work.work_vanity}/chapter/${State.value(chapter).chapter_url}/edit`))
136136
),
137137
(Button()
138138
.type('flush')
@@ -150,7 +150,7 @@ const Chapter = Component.Builder((component, chapter: ChapterMetadata, work: Wo
150150
.setIcon('flag')
151151
.text.use('chapter/action/label/report')
152152
.event.subscribe('click', event => ReportDialog.prompt(event.host, CHAPTER_REPORT, {
153-
reportedContentName: State.value(chapter).name ?? (quilt => quilt['view/chapter/number/label'](State.value(chapter).url)),
153+
reportedContentName: State.value(chapter).name ?? (quilt => quilt['view/chapter/number/label'](State.value(chapter).chapter_url)),
154154
async onReport (body) {
155155
const response = await EndpointReportsChapter$authorVanity$workVanity$chapterUrlAdd.query({ body, params: Chapters.reference(State.value(chapter)) })
156156
toast.handleError(response)

src/ui/component/Comment.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -143,12 +143,12 @@ const Comment = Component.Builder((component, source: CommentDataSource, comment
143143

144144
const ChapterContext = () => meta.context?.root_object.type === 'chapter' ? meta.context.root_object : undefined
145145
const WorkContext = () => meta.context?.root_object.type === 'work' ? meta.context.root_object : undefined
146-
const authorVanity = ChapterContext()?.chapter.author ?? WorkContext()?.work.author
147-
const workVanity = ChapterContext()?.chapter.work ?? WorkContext()?.work.vanity
148-
const chapterUrl = ChapterContext()?.chapter.url
146+
const authorVanity = ChapterContext()?.chapter.author_vanity ?? WorkContext()?.work.author_vanity
147+
const workVanity = ChapterContext()?.chapter.work_vanity ?? WorkContext()?.work.work_vanity
148+
const chapterUrl = ChapterContext()?.chapter.chapter_url
149149
const author = !authorVanity ? undefined : State.value(meta.context.authors)?.find(a => a.vanity === authorVanity)
150-
const work = !workVanity ? undefined : State.value(meta.context.works)?.find(w => w.author === authorVanity && w.vanity === workVanity)
151-
const chapter = !chapterUrl ? undefined : State.value(meta.context.chapters)?.find(c => c.author === authorVanity && c.work === workVanity && c.url === chapterUrl)
150+
const work = !workVanity ? undefined : State.value(meta.context.works)?.find(w => w.author_vanity === authorVanity && w.work_vanity === workVanity)
151+
const chapter = !chapterUrl ? undefined : State.value(meta.context.chapters)?.find(c => c.author_vanity === authorVanity && c.work_vanity === workVanity && c.chapter_url === chapterUrl)
152152

153153
isOnPrivateObject = meta.context.root_object.type === 'work_private' || meta.context.root_object.type === 'chapter_private'
154154
isOnPatronOnlyObject = chapter?.visibility === 'Patreon'
@@ -163,7 +163,7 @@ const Comment = Component.Builder((component, source: CommentDataSource, comment
163163
author ? AuthorLink(author) : '',
164164
],
165165
chapter: () => [
166-
(Link(`/work/${work?.author}/${work?.vanity}/chapter/${chapterUrl}`)
166+
(Link(`/work/${work?.author_vanity}/${work?.work_vanity}/chapter/${chapterUrl}`)
167167
.style('comment-header-context-chapter')
168168
.style.toggle(isOnPatronOnlyObject, 'comment-header-context-chapter--patreon', 'patreon-icon-before')
169169
.append(Component().text.set(Chapters.getName(chapter)))

src/ui/component/Notification.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ const Notification = Component.Builder('a', (component, data: NotificationData):
7676
const work = Works.resolve(data.work, Notifications.works.value)
7777
const WORK = !work ? undefined : WorkLink(work)
7878
const chapter = Chapters.resolve(data.chapter, Notifications.chapters.value)
79-
const CHAPTER = !chapter ? undefined : Link(`/work/${chapter.author}/${chapter.work}/chapter/${chapter.url}`).text.set(Chapters.getName(chapter))
79+
const CHAPTER = !chapter ? undefined : Link(`/work/${chapter.author_vanity}/${chapter.work_vanity}/chapter/${chapter.chapter_url}`).text.set(Chapters.getName(chapter))
8080

8181
const COMMENT = !!data.comment
8282

@@ -119,7 +119,7 @@ const Notification = Component.Builder('a', (component, data: NotificationData):
119119
.appendTo(notification)
120120

121121
if (chapter)
122-
notification.and(Link, `/work/${chapter.author}/${chapter.work}/chapter/${chapter.url}`)
122+
notification.and(Link, `/work/${chapter.author_vanity}/${chapter.work_vanity}/chapter/${chapter.chapter_url}`)
123123
.event.subscribe('Navigate', toggleRead)
124124
}
125125

0 commit comments

Comments
 (0)