Skip to content

Commit

Permalink
feat(ui): import-export repos
Browse files Browse the repository at this point in the history
  • Loading branch information
itupix committed Jan 27, 2021
1 parent e97d265 commit 7cb869a
Show file tree
Hide file tree
Showing 4 changed files with 168 additions and 91 deletions.
97 changes: 6 additions & 91 deletions src/components/FollowedRepositories/FollowedRepositories.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -6,27 +6,18 @@
import { ProviderEnum } from 'models/skizzle/ProviderEnum';
import type { ProfileType } from 'models/skizzle';
import Modale from 'components/Modale';
import { HighlightSvelte } from "svelte-highlight";
import { a11yDark } from "svelte-highlight/styles";
import { json } from "svelte-highlight/languages";
import Tabs from 'components/Tabs';
import { copyToClipboard } from 'shared/utils';
import ImportExport from 'components/ImportExport';
export let profile: ProfileType;
let shareDisplayed:boolean = false;
let currentTab:string = 'export';
const changeTab = (tab:string) => currentTab = tab;
let shareDisplayed:boolean = false;
$: followedRepositories = $repositories.filter(
({ checked, provider }) => checked && provider === profile.provider,
);
</script>

<svelte:head>
{@html a11yDark}
</svelte:head>
<section>
<AccountTitle>
Vos repositories suivis
Expand Down Expand Up @@ -65,63 +56,13 @@
{/each}
</ul>
{#if shareDisplayed}
<Modale onClose={() => shareDisplayed = false} fullHeight={false}>
<AccountTitle>Importer / Exporter une liste de repositories.</AccountTitle>
<p class="intro">Skizzle permet d'importer et d'exporter une liste de repositories suivis. Vous pouvez partager votre liste avec les autres membres de votre équipe.</p>
<Tabs
onChange={changeTab}
current={currentTab}
data={{ import: { order: 1, label: 'Importer' }, export : { order: 0, label: 'Exporter' }}}
/>
<div class="container">
{#if currentTab === 'export'}
<p class="intro">Copiez le code JSON et importez-le dans une autre instance de Skizzle.</p>
<div class="code">

<HighlightSvelte language={json} code={JSON.stringify(followedRepositories, undefined, 2)} />
<button
class="copy"
on:click={() => copyToClipboard(JSON.stringify(followedRepositories, undefined, 2), 'Code copié dans le presse-papier.')}
disabled={$isFetchingData}
title="Copier l'url de ce repository"
>
<Icons.Copy />
</button>
</div>
{:else}
<p class="intro">Collez le code JSON provenant d'une autre instance de Skizzle.</p>
<textarea placeholder="Collez ici votre code JSON"></textarea>
<div class="bar">
<input type="submit" class="import-button" value="Importer les repositories" />
</div>
{/if}
</div>
</Modale>
<Modale onClose={() => shareDisplayed = false} fullHeight={false}>
<ImportExport {followedRepositories} />
</Modale>
{/if}
</section>

<style>
textarea {
margin-bottom: 0.5rem;
color: #fff;
width: 100%;
height: 10rem;
resize: vertical;
padding: 1rem;
border: none;
border-radius: 4px;
background-color: #2b2b2b;
}
.import-button {
padding: 0.5rem 1rem;
color: #fff;
font-size: 1rem;
border-radius: 4px;
border: none;
background-color: var(--color);
transition: opacity linear 0.2s;
}
.intro {
margin-bottom: 1rem;
font-size: 0.8rem;
Expand Down Expand Up @@ -181,27 +122,6 @@
margin-left: -2rem;
}
.container {
margin-left: -2rem;
margin-right: -2rem;
margin-bottom: -2rem;
padding: 1rem;
border-radius: 0 0 8px 8px;
background-color: #4e4e4e;
}
.code {
position: relative;
border-radius: 4px;
overflow: hidden;
}
.copy {
position: absolute;
top: 1rem;
right: 1rem;
}
:global(.modale) :global(h1) {
margin-bottom: 1rem;
}
Expand All @@ -210,9 +130,4 @@
display: flex;
flex-direction: column;
}
.bar {
display: flex;
justify-content: flex-end;
}
</style>
152 changes: 152 additions & 0 deletions src/components/ImportExport/ImportExport.svelte
Original file line number Diff line number Diff line change
@@ -0,0 +1,152 @@
<script lang="ts">
import { isFetchingData, repositories } from 'shared/stores/default.store';
import { HighlightSvelte } from "svelte-highlight";
import { a11yDark } from "svelte-highlight/styles";
import { json } from "svelte-highlight/languages";
import Tabs from 'components/Tabs';
import AccountTitle from 'components/AccountTitle';
import { copyToClipboard, isJson } from 'shared/utils';
import Icons from 'components/icons';
export let followedRepositories;
let currentTab:string = 'import';
let code:string = '';
const changeTab = (tab:string) => currentTab = tab;
const importCode = () => {
repositories.set(JSON.parse(code));
}
</script>

<svelte:head>
{@html a11yDark}
</svelte:head>
<AccountTitle>Importer / Exporter une liste de repositories.</AccountTitle>
<p class="intro">Skizzle permet d'importer et d'exporter une liste de repositories suivis. Vous pouvez partager votre liste avec les autres membres de votre équipe.</p>
<Tabs
onChange={changeTab}
current={currentTab}
data={{ import: { order: 0, label: 'Importer' }, export : { order: 1, label: 'Exporter' }}}
/>
<div class="container">
{#if currentTab === 'export'}
<p class="intro">Copiez le code JSON et importez-le dans une autre instance de Skizzle.</p>
<div class="code">

<HighlightSvelte language={json} code={JSON.stringify(followedRepositories, undefined, 2)} />
<button
class="copy"
on:click={() => copyToClipboard(JSON.stringify(followedRepositories, undefined, 2), 'Code copié dans le presse-papier.')}
disabled={$isFetchingData}
title="Copier l'url de ce repository"
>
<Icons.Copy />
</button>
</div>
{:else}
<form on:submit={importCode}>
<p class="intro">Collez le code JSON provenant d'une autre instance de Skizzle. <b>Attention</b> Skizzle remplacera les repositories que vous suivez actuellement.</p>
<textarea bind:value={code} placeholder="Collez ici votre code JSON"></textarea>
<div class="bar">
<input disabled={!isJson(code)} type="submit" class="import-button" value="Importer les repositories" />
</div>
</form>
{/if}
</div>

<style>
textarea {
margin-bottom: 0.5rem;
color: #fff;
width: 100%;
height: 10rem;
resize: vertical;
padding: 1rem;
border: none;
border-radius: 4px;
background-color: #2b2b2b;
}
.import-button {
padding: 0.5rem 1rem;
color: #fff;
font-size: 1rem;
cursor: pointer;
border-radius: 4px;
border: none;
background-color: var(--color);
transition: opacity linear 0.2s;
}
.import-button:disabled {
opacity: 0.5;
}
.import-button:not(:disabled):hover {
opacity: 0.8;
}
.intro {
margin-bottom: 1rem;
font-size: 0.8rem;
color: #ddd;
}
b {
color: var(--color);
}
button {
width: 1.5rem;
height: 1.5rem;
cursor: pointer;
border: none;
background-color: transparent;
transition: opacity linear 0.2s;
}
button:hover {
opacity: 0.5;
}
button:last-child {
margin-left: 1rem;
}
.container {
margin-left: -2rem;
margin-right: -2rem;
margin-bottom: -2rem;
padding: 1rem;
border-radius: 0 0 8px 8px;
background-color: #4e4e4e;
}
.code {
position: relative;
border-radius: 4px;
overflow: hidden;
}
.copy {
position: absolute;
top: 1rem;
right: 1rem;
}
:global(.modale) :global(h1) {
margin-bottom: 1rem;
}
:global(.modale) :global(.content) {
display: flex;
flex-direction: column;
}
.bar {
display: flex;
justify-content: flex-end;
}
</style>
1 change: 1 addition & 0 deletions src/components/ImportExport/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { default } from './ImportExport.svelte';
9 changes: 9 additions & 0 deletions src/shared/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,3 +50,12 @@ export const copyToClipboard = async (data: string, message: string) => {
]);
}
};

export const isJson = (str: string): boolean => {
try {
JSON.parse(str);
} catch (e) {
return false;
}
return true;
};

0 comments on commit 7cb869a

Please sign in to comment.