Skip to content
This repository has been archived by the owner on Oct 7, 2024. It is now read-only.

Commit

Permalink
feat: set docs to 4.1.0
Browse files Browse the repository at this point in the history
  • Loading branch information
TimotheeMalard committed Mar 8, 2024
1 parent 14d6337 commit bcb3b9f
Show file tree
Hide file tree
Showing 7 changed files with 77 additions and 84 deletions.
14 changes: 0 additions & 14 deletions components/common/Button.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,20 +20,6 @@ export const ButtonLink = ({ label, url, className }: ButtonLinkProps) => {
</Link>
);
};
export const ButtonDownloadLink = ({
label,
className,
onClick,
}: ButtonLinkProps & { onClick?: () => void }) => {
return (
<button
onClick={onClick}
className={className ? `btn-link ${className}` : 'btn-link'}
>
{label}
</button>
);
};

export const ButtonCircle = ({ onClick, children }: ButtonCircleProps) => (
<button className="btn-circle" onClick={onClick}>
Expand Down
2 changes: 1 addition & 1 deletion components/download/Download.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import {
WithPrismicSlicedContent,
} from '../../utils/prismic/types';
import { Page } from '../common/Page';
import { DownloadProductItem } from './DownloadProdutItemProps';
import DownloadProductItem from './DownloadProductItem';

type DownloadSlicePrimary = {
changelog: RichTextField;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,13 @@ import React from 'react';
import { ArchifiltreProductVersionInfo, getDownloadLink } from '../../utils';
import { DownloadSlice } from './Download';

interface DownloadProdutItemProps {
interface DownloadProductItemProps {
product?: ArchifiltreProductVersionInfo[number];
slice: DownloadSlice;
}
export const DownloadProductItem = ({
slice,
product,
}: DownloadProdutItemProps) => {
const dlHref = getDownloadLink(product); // TODO: Change to proper url selection
const productName = product?.name?.substring(0, product?.name.indexOf('-')); // TODO: Change to proper title selection
const DownloadProductItem = ({ slice, product }: DownloadProductItemProps) => {
const downloadLink = getDownloadLink(product);
const productName = product?.name?.substring(0, product?.name.indexOf('-'));

return (
<div className="download__products__item">
Expand All @@ -28,8 +25,8 @@ export const DownloadProductItem = ({
<PrismicRichText field={slice.primary.changelog} />

<div className="download__products__item__doc">
{dlHref && (
<Link href={dlHref}>
{downloadLink && (
<Link href={downloadLink}>
<a className="btn-link download" target="_blank">
Télécharger {slice.primary.title}
</a>
Expand All @@ -54,3 +51,5 @@ export const DownloadProductItem = ({
</div>
);
};

export default DownloadProductItem;
6 changes: 2 additions & 4 deletions components/home/Home.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,11 @@ export const Home = ({ content }: HomeProps) => {
const slices = content.data.slices;
return (
<Page className="home">
{slices.slice(0, 1).map((slice, index) => (
{slices.slice(0, 1).map((slice, key) => (
<HomeProduct
index={index}
title={slice.primary.title ?? ''}
subtitle={slice.primary.subtitle ?? ''}
linkToProduct={index === 0 ? DOCS_SLUG : MAILS_SLUG}
key={index}
key={key}
>
<ul>
{slice.items.map((item, index) => (
Expand Down
64 changes: 42 additions & 22 deletions components/home/HomeProduct.tsx
Original file line number Diff line number Diff line change
@@ -1,51 +1,71 @@
import Link from 'next/link';
import React from 'react';
import { getDownloadLink } from '../../utils';
import { WithChildrenProps } from '../../utils/types';
import { ButtonDownloadLink, ButtonLink } from '../common/Button';

interface HomeProductProps extends WithChildrenProps {
index: number;
linkToProduct: string;
subtitle: string;
title: string;
}

export const HomeProduct = ({
title,
subtitle,
linkToProduct,
children,
index,
}: HomeProductProps) => {
const docsDownloadLink = getDownloadLink(undefined, 'docs');
const mailsDownloadLink = getDownloadLink(undefined, 'mails');

return (
<div className="home__product active" data-index={index} key={title}>
<div className="home__product active" key={title}>
<h1>{title}</h1>
<h2>{subtitle}</h2>
{children}
<div className="home__product__discover__wrapper">
<div className="home__product__discover">
<h3>Docs</h3>
<div className="home__product__discover__btn">
<ButtonLink url={linkToProduct} label="découvrir" />
<ButtonDownloadLink
onClick={() =>
window.open(getDownloadLink(undefined, 'docs'))
}
url={linkToProduct}
label="télécharger"
/>
<Link href={'/docs'}>
<a
className="btn-link documentation"
target="_blank"
>
découvrir
</a>
</Link>
{docsDownloadLink && (
<Link href={docsDownloadLink}>
<a
className="btn-link download"
target="_blank"
>
Télécharger
</a>
</Link>
)}
</div>
</div>
<div className="home__product__discover">
<h3>Mails</h3>
<div className="home__product__discover__btn">
<ButtonLink url={'mails'} label="découvrir" />
<ButtonDownloadLink
onClick={() =>
window.open(getDownloadLink(undefined, 'mails'))
}
url={linkToProduct}
label="télécharger"
/>
<Link href={'/mails'}>
<a
className="btn-link documentation"
target="_blank"
>
découvrir
</a>
</Link>
{mailsDownloadLink && (
<Link href={mailsDownloadLink}>
<a
className="btn-link download"
target="_blank"
>
Télécharger
</a>
</Link>
)}
</div>
</div>
</div>
Expand Down
4 changes: 4 additions & 0 deletions utils/downloadLink.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
export const BASE_URL_MAILS =
'https://github.com/SocialGouv/archifiltre-mails/releases/download/v1.0.0/archifiltre-mails';
export const BASE_URLS_DOCS =
'https://github.com/SocialGouv/archifiltre-docs/releases/download/v4.1.0/archifiltre-docs';
54 changes: 20 additions & 34 deletions utils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,23 +8,10 @@ import {
DMG_EXTENSION_DOCS_FIX,
EXE_EXTENSION_DOCS_FIX,
} from './constant';
import { BASE_URL_MAILS, BASE_URLS_DOCS } from './downloadLink';

export const HAS_WINDOW = typeof window !== 'undefined';

export const events = ['scroll', 'wheel', 'touchmove', 'pointermove'];

/**
*
*
Short of querySelector method.
*/
export const qs = (className: string) => document.querySelector(className);
/**
*
Short of querySelectorAll method.
*/
export const qsa = (className: string) => document.querySelectorAll(className);

// TODO: n products
export type ArchifiltreProductVersionInfo =
Endpoints['GET /repos/{owner}/{repo}/releases']['response']['data'];
Expand All @@ -46,7 +33,7 @@ const ERROR_MSG = 'Impossible de récupérer les dernières version de';
export const getVersionsFromGH = async (): Promise<ArchifiltreVersions> =>
Promise.allSettled([
fetch(
`https://api.github.com/repos/SocialGouv/archifiltre-docs/releases`,
'https://api.github.com/repos/SocialGouv/archifiltre-docs/releases',
),
fetch(
'https://api.github.com/repos/SocialGouv/archifiltre-mails/releases',
Expand Down Expand Up @@ -81,33 +68,32 @@ export const getDownloadLink = (
) => {
if (product || currentProduct) {
const os = getOSName();
const version = product?.name?.substring(1);
const name = product
? product?.url.includes('archifiltre-docs')
? 'docs'
: 'mails'
: currentProduct;

const baseUrlMail = `https://github.com/SocialGouv/archifiltre-mails/releases/download/v1.0.0/archifiltre-mails`;
const baseUrlDocs =
'https://github.com/SocialGouv/archifiltre-docs/releases/download/v4.0.0/archifiltre-docs';

if (name === 'mails') {
if (os === 'Mac OS') return baseUrlMail + DMG_EXTENSION_MAILS_FIX;
if (os === 'Linux')
return baseUrlMail + APP_IMAGE_EXTENSION_MAILS_FIX;
if (os?.startsWith('Windows'))
return baseUrlMail + EXE_EXTENSION_MAILS_FIX;
} else {
if (os === 'Mac OS') return baseUrlDocs + DMG_EXTENSION_DOCS_FIX;
if (os === 'Linux')
return baseUrlDocs + APP_IMAGE_EXTENSION_DOCS_FIX;
if (os?.startsWith('Windows'))
return baseUrlDocs + EXE_EXTENSION_DOCS_FIX;
if (os === 'Mac OS') {
return BASE_URL_MAILS + DMG_EXTENSION_MAILS_FIX;
}
if (os === 'Linux') {
return BASE_URL_MAILS + APP_IMAGE_EXTENSION_MAILS_FIX;
}
if (os?.startsWith('Windows')) {
return BASE_URL_MAILS + EXE_EXTENSION_MAILS_FIX;
}
}

// if (os === 'Mac OS') return url + DMG_EXTENSION;
// if (os === 'Linux') return url + APP_IMAGE_EXTENSION;
// if (os?.startsWith('Windows')) return url + EXE_EXTENSION;
if (os === 'Mac OS') {
return BASE_URLS_DOCS + DMG_EXTENSION_DOCS_FIX;
}
if (os === 'Linux') {
return BASE_URLS_DOCS + APP_IMAGE_EXTENSION_DOCS_FIX;
}
if (os?.startsWith('Windows')) {
return BASE_URLS_DOCS + EXE_EXTENSION_DOCS_FIX;
}
}
};

0 comments on commit bcb3b9f

Please sign in to comment.