@@ -2,11 +2,13 @@ import "./style.scss";
22import fsOperation from "fileSystem" ;
33import Contextmenu from "components/contextmenu" ;
44import Page from "components/page" ;
5+ import toast from "components/toast" ;
56import Ref from "html-tag-js/ref" ;
67import actionStack from "lib/actionStack" ;
78import markdownIt from "markdown-it" ;
89import markdownItFootnote from "markdown-it-footnote" ;
910import markdownItTaskLists from "markdown-it-task-lists" ;
11+ import helpers from "utils/helpers" ;
1012
1113export default async function Changelog ( ) {
1214 const GITHUB_API_URL =
@@ -19,6 +21,7 @@ export default async function Changelog() {
1921 let selectedStatus = "current" ;
2022 const versionIndicatorRef = Ref ( ) ;
2123 const versionTextRef = Ref ( ) ;
24+ const body = Ref ( ) ;
2225
2326 const versionSelector = (
2427 < div className = "changelog-version-selector" data-action = "select-version" >
@@ -39,6 +42,7 @@ export default async function Changelog() {
3942 right : "5px" ,
4043 toggler : versionSelector ,
4144 transformOrigin : "top right" ,
45+ onclick : menuClickHandler ,
4246 innerHTML : ( ) => {
4347 return `
4448 <li action="current">
@@ -57,10 +61,24 @@ export default async function Changelog() {
5761 } ,
5862 } ) ;
5963
60- const $content = < div className = "md" id = "changelog" > </ div > ;
61- $content . innerHTML = '<div class="loading">Loading changelog...</div>' ;
62- $page . content = $content ;
64+ const changelogMd = await import ( "../../../CHANGELOG.md" ) ;
65+
66+ toast ( "Loading changelog..." ) ;
67+ loadVersionChangelog ( ) ;
68+ body . onref = ( ) => renderChangelog ( changelogMd . default ) ;
69+ $page . body = < div className = "md" id = "changelog" ref = { body } /> ;
6370 app . append ( $page ) ;
71+ helpers . showAd ( ) ;
72+
73+ $page . onhide = function ( ) {
74+ actionStack . remove ( "changelog" ) ;
75+ helpers . hideAd ( ) ;
76+ } ;
77+
78+ actionStack . push ( {
79+ id : "changelog" ,
80+ action : $page . hide ,
81+ } ) ;
6482
6583 async function loadLatestRelease ( ) {
6684 try {
@@ -72,8 +90,8 @@ export default async function Changelog() {
7290 updateVersionSelector ( ) ;
7391 return renderChangelog ( releases . body ) ;
7492 } catch ( error ) {
75- $content . innerHTML =
76- '<div class="error">Failed to load latest release notes</div>' ;
93+ toast ( "Failed to load latest release notes" ) ;
94+ renderChangelog ( changelogMd . default ) ;
7795 }
7896 }
7997
@@ -82,16 +100,16 @@ export default async function Changelog() {
82100 const releases = await fsOperation ( GITHUB_API_URL ) . readFile ( "json" ) ;
83101 const betaRelease = releases . find ( ( r ) => r . prerelease ) ;
84102 if ( ! betaRelease ) {
85- $content . innerHTML = ' <div class ="error">No beta release found</div>' ;
103+ body . content = < div className = "error" > No beta release found</ div > ;
86104 return ;
87105 }
88106 selectedVersion = betaRelease . tag_name . replace ( "v" , "" ) ;
89107 selectedStatus = "prerelease" ;
90108 updateVersionSelector ( ) ;
91109 return renderChangelog ( betaRelease . body ) ;
92110 } catch ( error ) {
93- $content . innerHTML =
94- '<div class="error">Failed to load beta release notes</div>' ;
111+ toast ( "Failed to load beta release notes" ) ;
112+ renderChangelog ( changelogMd . default ) ;
95113 }
96114 }
97115
@@ -105,8 +123,8 @@ export default async function Changelog() {
105123 updateVersionSelector ( ) ;
106124 return renderChangelog ( cleanedText ) ;
107125 } catch ( error ) {
108- $content . innerHTML =
109- '<div class="error">Failed to load full changelog</div>' ;
126+ toast ( "Failed to load full changelog" ) ;
127+ renderChangelog ( changelogMd . default ) ;
110128 }
111129 }
112130
@@ -125,8 +143,8 @@ export default async function Changelog() {
125143 return loadLatestRelease ( ) ;
126144 }
127145 } catch ( error ) {
128- $content . innerHTML =
129- '<div class="error">Failed to load version changelog</div>' ;
146+ toast ( "Failed to load version changelog" ) ;
147+ renderChangelog ( changelogMd . default ) ;
130148 }
131149 }
132150
@@ -137,28 +155,24 @@ export default async function Changelog() {
137155 // Convert full PR URLs to #number format with links preserved in markdown
138156 . replace (
139157 / h t t p s : \/ \/ g i t h u b \. c o m \/ A c o d e - F o u n d a t i o n \/ A c o d e \/ p u l l \/ ( \d + ) / g,
140- " [#$1](https://github.com/Acode-Foundation/Acode/ pull/$1)" ,
158+ ` [#$1](${ REPO_URL } / pull/$1)` ,
141159 )
142160 // Convert existing #number references to links if they aren't already
143- . replace (
144- / (?< ! \[ ) # ( \d + ) (? ! \] ) / g,
145- "[#$1](https://github.com/Acode-Foundation/Acode/pull/$1)" ,
146- )
161+ . replace ( / (?< ! \[ ) # ( \d + ) (? ! \] ) / g, `[#$1](${ REPO_URL } /pull/$1)` )
147162 // Convert @username mentions to GitHub profile links
148163 . replace ( / @ ( \w + ) / g, "[@$1](https://github.com/$1)" ) ;
149164
150165 md . use ( markdownItTaskLists ) ;
151166 md . use ( markdownItFootnote ) ;
152- const htmlContent = md . render ( processedText ) ;
153- $content . innerHTML = htmlContent ;
167+ body . innerHTML = md . render ( processedText ) ;
154168 }
155169
156170 function updateVersionSelector ( ) {
157171 versionTextRef . textContent = selectedVersion ;
158172 versionIndicatorRef . className = "status-indicator status-" + selectedStatus ;
159173 }
160174
161- versionSelectorMenu . onclick = async function ( e ) {
175+ async function menuClickHandler ( e ) {
162176 const action = e . target . closest ( "li" ) ?. getAttribute ( "action" ) ;
163177 if ( ! action ) return ;
164178 versionSelectorMenu . hide ( ) ;
@@ -177,17 +191,5 @@ export default async function Changelog() {
177191 await loadFullChangelog ( ) ;
178192 break ;
179193 }
180- } ;
181-
182- // Load current version changelog by default
183- loadVersionChangelog ( ) ;
184-
185- $page . onhide = function ( ) {
186- actionStack . remove ( "changelog" ) ;
187- } ;
188-
189- actionStack . push ( {
190- id : "changelog" ,
191- action : $page . hide ,
192- } ) ;
194+ }
193195}
0 commit comments