-
-
Notifications
You must be signed in to change notification settings - Fork 1
Creating a collection #43
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
Merged
Changes from all commits
Commits
Show all changes
20 commits
Select commit
Hold shift + click to select a range
dec9451
wip
sakithb e55d1a2
use switch
sakithb 71fd414
wip
sakithb aaec74f
add serializer package
sakithb c91dc6a
ui
sakithb 482a4bd
add bottom margin
sakithb 6ca1f21
endpoint + tests
sakithb 82633e2
fix failing test
sakithb fa059b3
wip
sakithb d83796f
use switch
sakithb ba8c053
wip
sakithb dcff3f2
add serializer package
sakithb 8055d6e
use AuthInterface
sakithb 1d267eb
remove security bundle
sakithb c256f8d
LICENSE
supun-io f3a594a
Merge branch 'main' into issue/40
supun-io 96d9c53
Merge remote-tracking branch 'origin/issue/40' into issue/40
Nadil-K 9241771
minor fixes
Nadil-K 00f5f88
remove duplicate modals
Nadil-K ace225f
Merge branch 'issue/38' into issue/40
Nadil-K File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| <?php | ||
|
|
||
| namespace App\Api\App\Input; | ||
|
|
||
| use Symfony\Component\Validator\Constraints as Assert; | ||
|
|
||
| class AddCollectionInput | ||
| { | ||
| #[Assert\NotBlank] | ||
| public string $name = ''; | ||
|
|
||
| #[Assert\Type('bool')] | ||
| public bool $is_public = false; | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2,7 +2,7 @@ | |
| import IconChevronDown from '@hyvor/icons/IconChevronDown'; | ||
| import IconBoxArrowUpRight from '@hyvor/icons/IconBoxArrowUpRight'; | ||
| import IconPlus from '@hyvor/icons/IconPlus'; | ||
| import { Button, Dropdown, ActionList, ActionListItem, Loader, Modal, TextInput } from '@hyvor/design/components'; | ||
| import { Button, Dropdown, ActionList, ActionListItem, Loader, Modal, TextInput, Switch } from '@hyvor/design/components'; | ||
| import { | ||
| collections, | ||
| publications, | ||
|
|
@@ -26,6 +26,10 @@ | |
| let showCollections = $state(false); | ||
| let showAddPublicationModal = $state(false); | ||
| let rssUrl = $state(''); | ||
| let publicationTitle = $state(''); | ||
| let showCreateCollectionModal = $state(false); | ||
| let collectionName = $state(''); | ||
| let collectionIsPublic = $state(false); | ||
| let selectedItem: Item | null = $state(null); | ||
| let currentItemIndex = $derived( | ||
| selectedItem ? $items.findIndex(item => item.id === selectedItem!.id) : -1 | ||
|
|
@@ -38,6 +42,22 @@ | |
| goto(`/app/${collection.slug}`); | ||
| } | ||
|
|
||
| async function handleCreateCollection() { | ||
| const trimmed = collectionName.trim(); | ||
| if (!trimmed) return; | ||
| try { | ||
| const res = await api.post('/collections', { name: trimmed, is_public: collectionIsPublic }); | ||
| const created: Collection = res.collection; | ||
| $collections = [...$collections, created]; | ||
| showCreateCollectionModal = false; | ||
| collectionName = ''; | ||
| collectionIsPublic = false; | ||
| goto(`/app/${created.slug}`); | ||
| } catch (e) { | ||
| console.error('Failed to create collection', e); | ||
| } | ||
| } | ||
|
|
||
| function selectPublication(publication?: Publication) { | ||
| if (publication) { | ||
| goto(`/app/${$page.params.collection_slug}/${publication.slug}`); | ||
|
|
@@ -127,14 +147,16 @@ | |
| } | ||
| const res = await api.post('/publications', { | ||
| collection_slug: collectionSlug, | ||
| url: value | ||
| url: value, | ||
| title: publicationTitle.trim(), | ||
| }); | ||
| const exists = $publications.find(p => p.slug === res.publication.slug); | ||
| if (!exists) { | ||
| publications.set([...$publications, res.publication]); | ||
| } | ||
| showAddPublicationModal = false; | ||
| rssUrl = ''; | ||
| publicationTitle = ''; | ||
| } catch (e) { | ||
| console.error('Failed to add publication', e); | ||
| addPublicationError = e instanceof Error ? e.message : 'Failed to add publication'; | ||
|
|
@@ -184,6 +206,9 @@ | |
| {collection.name} | ||
| </ActionListItem> | ||
| {/each} | ||
| <ActionListItem on:select={() => { showCreateCollectionModal = true; showCollections = false; }}> | ||
|
Member
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.
|
||
| + Create collection | ||
| </ActionListItem> | ||
| </ActionList> | ||
| {/snippet} | ||
| </Dropdown> | ||
|
|
@@ -238,7 +263,7 @@ | |
| {/if} | ||
| </div> | ||
| <div class="publications-footer"> | ||
| <Button class="add-publication-button" on:click={() => { rssUrl = ''; addPublicationError = null; showAddPublicationModal = true; }}> | ||
| <Button class="add-publication-button" on:click={() => { rssUrl = ''; publicationTitle = ''; addPublicationError = null; showAddPublicationModal = true; }}> | ||
| {#snippet start()} | ||
| <IconPlus size={12} /> | ||
| {/snippet} | ||
|
|
@@ -336,6 +361,37 @@ | |
| </div> | ||
| </main> | ||
|
|
||
| <Modal | ||
| bind:show={showCreateCollectionModal} | ||
| size="small" | ||
| title="Create Collection" | ||
| closeOnOutsideClick={true} | ||
| closeOnEscape={true} | ||
| footer={{ | ||
| cancel: { text: 'Cancel', props: { color: 'input' } }, | ||
| confirm: { text: 'Create', props: { disabled: !collectionName.trim() } } | ||
| }} | ||
| on:cancel={() => { showCreateCollectionModal = false; }} | ||
| on:confirm={handleCreateCollection} | ||
| > | ||
| <div class="modal-body"> | ||
| <TextInput | ||
| id="collectionName" | ||
| type="text" | ||
| placeholder="My collection" | ||
| autofocus | ||
| bind:value={collectionName} | ||
| on:keydown={(e: KeyboardEvent) => { | ||
| if (e.key === 'Enter' && collectionName.trim()) { | ||
| handleCreateCollection(); | ||
| } | ||
| }} | ||
| /> | ||
| <Switch id="collectionPublic" bind:checked={collectionIsPublic}> | ||
| Public | ||
| </Switch> | ||
| </div> | ||
| </Modal> | ||
|
|
||
| <Modal | ||
|
Member
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.
|
||
| bind:show={showAddPublicationModal} | ||
|
|
@@ -355,6 +411,7 @@ | |
| {#if addPublicationError} | ||
| <div class="error-text">{addPublicationError}</div> | ||
| {/if} | ||
|
|
||
| <TextInput | ||
| id="rssUrl" | ||
| type="url" | ||
|
|
@@ -368,8 +425,26 @@ | |
| }} | ||
| disabled={addingPublication} | ||
| /> | ||
|
|
||
| <TextInput | ||
| id="publicationTitle" | ||
| type="text" | ||
| placeholder="Publication Title" | ||
| bind:value={publicationTitle} | ||
| on:keydown={(e: KeyboardEvent) => { | ||
| if (e.key === 'Enter' && publicationTitle.trim()) { | ||
| handleAdd(); | ||
| } | ||
| }} | ||
| /> | ||
| </div> | ||
|
|
||
| {#snippet footer()} | ||
| <div class="modal-footer"> | ||
| <Button disabled={!isValidUrl(rssUrl) || !publicationTitle.trim()} on:click={handleAdd}>Add</Button> | ||
| <Button color="input" on:click={() => { showAddPublicationModal = false; }}>Cancel</Button> | ||
| </div> | ||
| {/snippet} | ||
|
|
||
| </Modal> | ||
|
|
||
|
|
||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Why do we need these
createdandattachedbooleans? Within the current codebase, I don't see any instance of it being used. Shall we remove it @supun-io?