-
-
Notifications
You must be signed in to change notification settings - Fork 11
feat(editor): fetch current not-owned projects, add project forking #525
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
69552d3
473ac00
68a028c
0d74401
38e2eb4
08c837b
230779e
d8025b9
672da2b
16e6f2e
7504521
4863bdb
43f0060
17c852c
1cc568b
ff53672
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -27,7 +27,6 @@ | |
| &--orange, | ||
| &--warning { | ||
| background: $orange; | ||
| font-size: $font-size-small; | ||
| } | ||
|
|
||
| p { | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,6 +1,6 @@ | ||
| <script> | ||
| import SearchObjects from "@components/editor/SearchObjects.svelte" | ||
| import { projects, currentProject, isSignedIn, isMobile, modal } from "@stores/editor" | ||
| import { projects, currentProject, isSignedIn, isMobile, modal, currentProjectUUID } from "@stores/editor" | ||
| import { getSaveContent } from "@utils/editor" | ||
| import { createProject, destroyCurrentProject, fetchProject, setUrl } from "@utils/project" | ||
| import { escapeable } from "@components/actions/escapeable" | ||
|
|
@@ -12,16 +12,18 @@ | |
| let loading = false | ||
| let active = false | ||
| let showProjectSettings = false | ||
| let filteredProjects = $projects | ||
| let ownProjects = [] | ||
| let filteredProjects = [] | ||
|
|
||
| $: ownProjects = $projects.filter(({ is_owner }) => is_owner) | ||
|
Comment on lines
+15
to
+18
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't really want the state of projects that are not part of your project to be handled in the projects dropdown, I think it would make more sense somewhere else.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good point. Then |
||
| $: limit = $isMobile ? 5 : 25 | ||
|
|
||
| onMount(() => { | ||
| const urlParams = new URLSearchParams(window.location.search) | ||
| const uuid = urlParams.get("uuid") | ||
|
|
||
| if (uuid) getProject(uuid) | ||
| else if ($projects.length) getProject($projects[0].uuid) | ||
| else if (ownProjects.length) getProject(ownProjects[0].uuid) | ||
| }) | ||
|
|
||
| async function getProject(uuid) { | ||
|
|
@@ -52,7 +54,8 @@ | |
| loading = true | ||
|
|
||
| const content = getSaveContent() | ||
| const data = await createProject($currentProject.title + " (Copy)", content) | ||
|
|
||
| const data = await createProject(`${$currentProject.title} (Copy)`, content) | ||
| if (data) { | ||
| setUrl(data.uuid) | ||
| await fetchProject(data.uuid) | ||
|
|
@@ -63,39 +66,41 @@ | |
| } | ||
| </script> | ||
|
|
||
| <div class="dropdown" use:outsideClick on:outsideClick={() => active = false}> | ||
| <div class="dropdown" style:max-width="200px" use:outsideClick on:outsideClick={() => active = false}> | ||
| <button class="form-select pt-1/8 pb-1/8 pl-1/4 text-left" on:click|stopPropagation={() => active = !active} style:min-width="{$isMobile ? 75 : 200}px" disabled={loading}> | ||
| {#if loading} | ||
| Loading... | ||
| {:else if $currentProject} | ||
| <span class="w-100 text-truncate nowrap">{$currentProject.title}</span> | ||
| {:else} | ||
| {$currentProject?.title.substring(0, limit).trim() || "Select a project..."}{#if $currentProject?.title.length > limit}...{/if} | ||
| Select a project... | ||
| {/if} | ||
| </button> | ||
|
|
||
| {#if active} | ||
| <div transition:fly={{ duration: 150, y: 20 }} use:escapeable on:escape={() => active = false} class="dropdown__content dropdown__content--left block w-100" style:min-width="200px"> | ||
| <div class="pl-1/8 pr-1/8"> | ||
| <SearchObjects objects={$projects} bind:filteredObjects={filteredProjects} /> | ||
| <SearchObjects objects={ownProjects} bind:filteredObjects={filteredProjects} /> | ||
| </div> | ||
|
|
||
| <hr /> | ||
|
|
||
| {#each filteredProjects as project (project.uuid)} | ||
| <button class="dropdown__item" animate:flip={{ duration: 100 }} on:click={() => getProject(project.uuid)}> | ||
| <button class="dropdown__item text-truncate" animate:flip={{ duration: 100 }} on:click={() => getProject(project.uuid)}> | ||
| {project.title} | ||
| </button> | ||
| {/each} | ||
|
|
||
| {#if $projects?.length && !filteredProjects.length} | ||
| {#if ownProjects?.length && !filteredProjects.length} | ||
| <em class="block text-dark text-small pl-1/8 pr-1/8">No projects match your search.</em> | ||
| {/if} | ||
|
|
||
| {#if $projects?.length} | ||
| {#if ownProjects?.length} | ||
| <hr /> | ||
| {/if} | ||
|
|
||
| <div class="p-1/4"> | ||
| {#if !$projects?.length} | ||
| {#if !ownProjects?.length} | ||
| <em class="text-small block mb-1/4">Create a new project to get started.</em> | ||
| {/if} | ||
| <button class="button button--small w-100" on:click={() => { | ||
|
|
@@ -109,26 +114,28 @@ | |
| {/if} | ||
| </div> | ||
|
|
||
| {#if $isSignedIn && $currentProject?.is_owner && !loading} | ||
| <div class="dropdown" use:outsideClick on:outsideClick={() => showProjectSettings = false}> | ||
| <button class="w-auto text-base ml-1/8" on:click|stopPropagation={() => showProjectSettings = !showProjectSettings}> | ||
| Edit | ||
| </button> | ||
|
|
||
| {#if showProjectSettings} | ||
| <div transition:fly={{ duration: 150, y: 20 }} class="dropdown__content dropdown__content--left block w-100" style="width: 200px"> | ||
| <button class="dropdown__item" on:click={() => modal.show("create-project", { type: "rename" })}> | ||
| Rename | ||
| </button> | ||
|
|
||
| <button class="dropdown__item" on:click={duplicateProject}> | ||
| Duplicate | ||
| </button> | ||
|
|
||
| <button class="dropdown__item text-red" on:click={destroyProject}> | ||
| Destroy | ||
| </button> | ||
| </div> | ||
| {/if} | ||
| </div> | ||
| {#if $isSignedIn && !loading} | ||
| {#if $currentProject?.is_owner} | ||
| <div class="dropdown" use:outsideClick on:outsideClick={() => showProjectSettings = false}> | ||
| <button class="w-auto text-base ml-1/8" on:click|stopPropagation={() => showProjectSettings = !showProjectSettings}> | ||
| Edit | ||
| </button> | ||
|
|
||
| {#if showProjectSettings} | ||
| <div transition:fly={{ duration: 150, y: 20 }} class="dropdown__content dropdown__content--left block w-100" style="width: 200px"> | ||
| <button class="dropdown__item" on:click={() => modal.show("create-project", { type: "rename" })}> | ||
| Rename | ||
| </button> | ||
|
|
||
| <button class="dropdown__item" on:click={() => duplicateProject()}> | ||
| Duplicate | ||
| </button> | ||
|
|
||
| <button class="dropdown__item text-red" on:click={destroyProject}> | ||
| Destroy | ||
| </button> | ||
| </div> | ||
| {/if} | ||
| </div> | ||
| {/if} | ||
| {/if} | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd prefer
$projectsto not ever contain a project that is not owned by the userUh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would you be okay with at least renaming it
$user/ownProjects? Its naming is a bit vague otherwise.I also noticed a lot of checks for
$currentProject?.is_owner, making it seem like we could have a project in$projectsthat could be owned by some other user ($currentProjectderives from$projects).