From 8c894752cd260f8b799adf85c0cfe5a5378992e4 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Fri, 5 Dec 2025 06:29:12 +0000 Subject: [PATCH 1/4] Initial plan From e62fae7f851d228a5e8ded80f43842c65260b31a Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Fri, 5 Dec 2025 06:38:09 +0000 Subject: [PATCH 2/4] Add URL addressable version selection with path-based routing (/apps/[id]/[version]) Co-authored-by: rnwood <1327895+rnwood@users.noreply.github.com> --- components/SingleApp.js | 52 ++++++++++--- pages/apps/[id]/[version].js | 103 ++++++++++++++++++++++++++ pages/apps/{[id].js => [id]/index.js} | 14 ++-- 3 files changed, 153 insertions(+), 16 deletions(-) create mode 100644 pages/apps/[id]/[version].js rename pages/apps/{[id].js => [id]/index.js} (84%) diff --git a/components/SingleApp.js b/components/SingleApp.js index 39817a7..5585bda 100644 --- a/components/SingleApp.js +++ b/components/SingleApp.js @@ -28,14 +28,12 @@ import AppIcon from "./AppIcon"; import { compareVersion, timeAgo } from "../utils/helpers"; -let SingleApp = ({ app, all, onVersionChange = false, large = false, showTime = false, pack = false, displaySelect = false, preventGlobalSelect, hideBorder=false, preSelected=false}) => { +let SingleApp = ({ app, all, onVersionChange = false, large = false, showTime = false, pack = false, displaySelect = false, preventGlobalSelect, hideBorder=false, preSelected=false, initialVersion}) => { const [selected, setSelected] = useState(false); const { selectedApps, setSelectedApps } = useContext(SelectedContext); + const router = useRouter(); - const [version, setVersion] = useState(app.latestVersion); - - if (!app.selectedVersion) app.selectedVersion = version; - + // Sort versions if available if (app.versions && app.versions.length > 1) { app.versions = app.versions.sort((a, b) => compareVersion(b.version, a.version) @@ -44,6 +42,32 @@ let SingleApp = ({ app, all, onVersionChange = false, large = false, showTime = app.latestVersion = app.versions[0].version; } + // Get initial version from prop (passed from URL path) or use latestVersion + const getInitialVersion = () => { + if (large && initialVersion && app.versions) { + const isValidVersion = app.versions.some(v => v.version === initialVersion); + if (isValidVersion) { + return initialVersion; + } + } + return app.latestVersion; + }; + + const [version, setVersion] = useState(getInitialVersion()); + + // Update version when initialVersion prop changes (e.g., navigation between versions) + useEffect(() => { + if (large && initialVersion && app.versions) { + const isValidVersion = app.versions.some(v => v.version === initialVersion); + if (isValidVersion && initialVersion !== version) { + setVersion(initialVersion); + app.selectedVersion = initialVersion; + } + } + }, [initialVersion]); + + if (!app.selectedVersion) app.selectedVersion = version; + useEffect(() => { if(preSelected){ setSelected(true); @@ -111,12 +135,21 @@ let SingleApp = ({ app, all, onVersionChange = false, large = false, showTime = id="v-selector" name="Select app version" onChange={(e) => { - setVersion(e.target.value); - app.selectedVersion = e.target.value; + const newVersion = e.target.value; + setVersion(newVersion); + app.selectedVersion = newVersion; + + // Update URL with version path (only in large/detail mode) + if (large) { + const newPath = newVersion === app.latestVersion + ? `/apps/${app._id}` + : `/apps/${app._id}/${newVersion}`; + router.replace(newPath, undefined, { shallow: true }); + } if (selected) { let found = selectedApps.find((a) => a._id === app._id); - found.selectedVersion = e.target.value; + found.selectedVersion = newVersion; if(onVersionChange) onVersionChange(); } @@ -144,7 +177,8 @@ let SingleApp = ({ app, all, onVersionChange = false, large = false, showTime = }; const handleShare = () => { - const link = `https://twitter.com/intent/tweet?text=${encodeURIComponent(`Checkout ${app.name} by ${app.publisher} on @winstallHQ:`)}&url=${encodeURIComponent(`https://winstall.app/apps/${app._id}`)}` + const versionPath = version !== app.latestVersion ? `/${encodeURIComponent(version)}` : ''; + const link = `https://twitter.com/intent/tweet?text=${encodeURIComponent(`Checkout ${app.name} by ${app.publisher} on @winstallHQ:`)}&url=${encodeURIComponent(`https://winstall.app/apps/${app._id}${versionPath}`)}` window.open(link) } diff --git a/pages/apps/[id]/[version].js b/pages/apps/[id]/[version].js new file mode 100644 index 0000000..a685709 --- /dev/null +++ b/pages/apps/[id]/[version].js @@ -0,0 +1,103 @@ +import styles from "../../../styles/home.module.scss"; + +import SingleApp from "../../../components/SingleApp"; + +import Footer from "../../../components/Footer"; +import Error from "../../../components/Error"; + +import Skeleton from "react-loading-skeleton"; + +import { useRouter } from "next/router"; +import MetaTags from "../../../components/MetaTags"; +import fetchWinstallAPI from "../../../utils/fetchWinstallAPI"; +import DonateCard from "../../../components/DonateCard"; + +function AppSkeleton() { + return ( +
+
+ + +
+ +
+ +
+
+ +
+
+ ); +} + +function AppDetail({ app, initialVersion }) { + const router = useRouter(); + const fallbackMessage = { + title: "Sorry! We could not load this app.", + subtitle: "Unfortunately, this app could not be loaded. Either it does not exist, or something else went wrong. Please try again later." + } + + if(!router.isFallback && !app){ + return + } + + return ( +
+
+
+ {router.isFallback ? ( + + ) : ( +
+ +
+ +
+ )} +
+ winstall logo +
+
+
+ +
+ ); +} + +export async function getStaticPaths() { + return { + paths: [], + fallback: true, + }; +} + +export async function getStaticProps({ params }) { + try{ + let { response: app } = await fetchWinstallAPI(`/apps/${params.id}`); + + if (!app) { + return { props: {} }; + } + + // Validate that the version exists for this app + const versionExists = app.versions && app.versions.some(v => v.version === params.version); + + if (!versionExists) { + return { props: {} }; + } + + return { props: { app, initialVersion: params.version } } + } catch(err) { + return { props: {} }; + } +} + +export default AppDetail; diff --git a/pages/apps/[id].js b/pages/apps/[id]/index.js similarity index 84% rename from pages/apps/[id].js rename to pages/apps/[id]/index.js index 71875e4..e17beb4 100644 --- a/pages/apps/[id].js +++ b/pages/apps/[id]/index.js @@ -1,16 +1,16 @@ -import styles from "../../styles/home.module.scss"; +import styles from "../../../styles/home.module.scss"; -import SingleApp from "../../components/SingleApp"; +import SingleApp from "../../../components/SingleApp"; -import Footer from "../../components/Footer"; -import Error from "../../components/Error"; +import Footer from "../../../components/Footer"; +import Error from "../../../components/Error"; import Skeleton from "react-loading-skeleton"; import { useRouter } from "next/router"; -import MetaTags from "../../components/MetaTags"; -import fetchWinstallAPI from "../../utils/fetchWinstallAPI"; -import DonateCard from "../../components/DonateCard"; +import MetaTags from "../../../components/MetaTags"; +import fetchWinstallAPI from "../../../utils/fetchWinstallAPI"; +import DonateCard from "../../../components/DonateCard"; function AppSkeleton() { return ( From ef92ec691b5d603c9c86d0627881ebea278ff842 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Fri, 5 Dec 2025 06:41:56 +0000 Subject: [PATCH 3/4] Add mock API endpoints for local testing Co-authored-by: rnwood <1327895+rnwood@users.noreply.github.com> --- pages/api/apps/[id].js | 71 +++++++++++++++++++++++++++++++++++++++++ pages/api/apps/index.js | 56 ++++++++++++++++++++++++++++++++ 2 files changed, 127 insertions(+) create mode 100644 pages/api/apps/[id].js create mode 100644 pages/api/apps/index.js diff --git a/pages/api/apps/[id].js b/pages/api/apps/[id].js new file mode 100644 index 0000000..270bfbb --- /dev/null +++ b/pages/api/apps/[id].js @@ -0,0 +1,71 @@ +// Mock API endpoint for testing - returns a single app by ID +export default function handler(req, res) { + const { id } = req.query; + + const mockApps = { + "7zip.7zip": { + _id: "7zip.7zip", + name: "7-Zip", + publisher: "Igor Pavlov", + desc: "7-Zip is a file archiver with a high compression ratio. It supports packing and unpacking various archive formats including 7z, ZIP, GZIP, BZIP2, TAR, and more. The software features a high compression ratio in 7z format, strong AES-256 encryption, self-extracting capability, and integration with Windows Shell.", + icon: null, + homepage: "https://www.7-zip.org/", + latestVersion: "24.09", + updatedAt: new Date().toISOString(), + license: "LGPL-2.1", + licenseUrl: "https://www.7-zip.org/license.txt", + versions: [ + { version: "24.09", installers: ["https://example.com/7z2409-x64.exe"], installerType: "exe" }, + { version: "24.08", installers: ["https://example.com/7z2408-x64.exe"], installerType: "exe" }, + { version: "24.07", installers: ["https://example.com/7z2407-x64.exe"], installerType: "exe" }, + { version: "23.01", installers: ["https://example.com/7z2301-x64.exe"], installerType: "exe" }, + ], + tags: ["archive", "compression", "zip", "7z", "utility"], + }, + "Mozilla.Firefox": { + _id: "Mozilla.Firefox", + name: "Firefox", + publisher: "Mozilla", + desc: "Firefox is a free and open-source web browser developed by Mozilla. It uses the Gecko rendering engine to display web pages, which implements current and anticipated web standards. Firefox includes tabbed browsing, spell checking, incremental find, live bookmarking, and a download manager.", + icon: null, + homepage: "https://www.mozilla.org/firefox/", + latestVersion: "133.0", + updatedAt: new Date().toISOString(), + license: "MPL-2.0", + licenseUrl: "https://www.mozilla.org/MPL/2.0/", + versions: [ + { version: "133.0", installers: ["https://example.com/firefox-133.exe"], installerType: "exe" }, + { version: "132.0", installers: ["https://example.com/firefox-132.exe"], installerType: "exe" }, + { version: "131.0", installers: ["https://example.com/firefox-131.exe"], installerType: "exe" }, + ], + tags: ["browser", "web", "mozilla", "internet"], + }, + "Microsoft.VisualStudioCode": { + _id: "Microsoft.VisualStudioCode", + name: "Visual Studio Code", + publisher: "Microsoft", + desc: "Visual Studio Code is a code editor redefined and optimized for building and debugging modern web and cloud applications. It is free and built on open source. It features IntelliSense, debugging, built-in Git support, and thousands of extensions.", + icon: null, + homepage: "https://code.visualstudio.com/", + latestVersion: "1.95.0", + updatedAt: new Date().toISOString(), + license: "MIT", + licenseUrl: "https://code.visualstudio.com/license", + versions: [ + { version: "1.95.0", installers: ["https://example.com/vscode-1.95.exe"], installerType: "exe" }, + { version: "1.94.0", installers: ["https://example.com/vscode-1.94.exe"], installerType: "exe" }, + { version: "1.93.0", installers: ["https://example.com/vscode-1.93.exe"], installerType: "exe" }, + ], + tags: ["editor", "code", "ide", "microsoft", "development"], + }, + }; + + const app = mockApps[id]; + + if (!app) { + res.status(404).json({ error: "App not found" }); + return; + } + + res.status(200).json(app); +} diff --git a/pages/api/apps/index.js b/pages/api/apps/index.js new file mode 100644 index 0000000..fffea8e --- /dev/null +++ b/pages/api/apps/index.js @@ -0,0 +1,56 @@ +// Mock API endpoint for testing - returns a list of apps +export default function handler(req, res) { + const mockApps = [ + { + _id: "7zip.7zip", + name: "7-Zip", + publisher: "Igor Pavlov", + desc: "7-Zip is a file archiver with a high compression ratio.", + icon: null, + homepage: "https://www.7-zip.org/", + latestVersion: "24.09", + updatedAt: new Date().toISOString(), + versions: [ + { version: "24.09", installers: ["https://example.com/7z2409-x64.exe"], installerType: "exe" }, + { version: "24.08", installers: ["https://example.com/7z2408-x64.exe"], installerType: "exe" }, + { version: "24.07", installers: ["https://example.com/7z2407-x64.exe"], installerType: "exe" }, + { version: "23.01", installers: ["https://example.com/7z2301-x64.exe"], installerType: "exe" }, + ], + tags: ["archive", "compression", "zip", "7z"], + }, + { + _id: "Mozilla.Firefox", + name: "Firefox", + publisher: "Mozilla", + desc: "Firefox is a free and open-source web browser developed by Mozilla.", + icon: null, + homepage: "https://www.mozilla.org/firefox/", + latestVersion: "133.0", + updatedAt: new Date().toISOString(), + versions: [ + { version: "133.0", installers: ["https://example.com/firefox-133.exe"], installerType: "exe" }, + { version: "132.0", installers: ["https://example.com/firefox-132.exe"], installerType: "exe" }, + { version: "131.0", installers: ["https://example.com/firefox-131.exe"], installerType: "exe" }, + ], + tags: ["browser", "web", "mozilla"], + }, + { + _id: "Microsoft.VisualStudioCode", + name: "Visual Studio Code", + publisher: "Microsoft", + desc: "Visual Studio Code is a code editor redefined and optimized for building and debugging modern web and cloud applications.", + icon: null, + homepage: "https://code.visualstudio.com/", + latestVersion: "1.95.0", + updatedAt: new Date().toISOString(), + versions: [ + { version: "1.95.0", installers: ["https://example.com/vscode-1.95.exe"], installerType: "exe" }, + { version: "1.94.0", installers: ["https://example.com/vscode-1.94.exe"], installerType: "exe" }, + { version: "1.93.0", installers: ["https://example.com/vscode-1.93.exe"], installerType: "exe" }, + ], + tags: ["editor", "code", "ide", "microsoft"], + }, + ]; + + res.status(200).json(mockApps); +} From 825ff3bafebcf475dc43f8f865b060d6f59c932a Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Fri, 5 Dec 2025 06:44:00 +0000 Subject: [PATCH 4/4] Fix useEffect dependency array in SingleApp.js Co-authored-by: rnwood <1327895+rnwood@users.noreply.github.com> --- components/SingleApp.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/components/SingleApp.js b/components/SingleApp.js index 5585bda..ec0a36b 100644 --- a/components/SingleApp.js +++ b/components/SingleApp.js @@ -64,7 +64,7 @@ let SingleApp = ({ app, all, onVersionChange = false, large = false, showTime = app.selectedVersion = initialVersion; } } - }, [initialVersion]); + }, [initialVersion, large, app.versions]); if (!app.selectedVersion) app.selectedVersion = version;