diff --git a/src/lib/api/types/generated.ts b/src/lib/api/types/generated.ts index 2eeb6c5b..8a36d52f 100644 --- a/src/lib/api/types/generated.ts +++ b/src/lib/api/types/generated.ts @@ -644,6 +644,8 @@ export interface CreatePost { nsfw?: boolean language_id?: LanguageId custom_thumbnail?: string + poll?: PostPoll + event?: PostEvent } export interface CreatePostLike { @@ -801,6 +803,8 @@ export interface EditPost { nsfw?: boolean language_id?: LanguageId custom_thumbnail?: string + poll?: PostPoll + event?: PostEvent } export interface EditPrivateMessage { diff --git a/src/lib/app/i18n/en.json b/src/lib/app/i18n/en.json index 10cb0ca9..9773ab46 100644 --- a/src/lib/app/i18n/en.json +++ b/src/lib/app/i18n/en.json @@ -146,7 +146,12 @@ "unset": "Unset", "readMore": "Read more", "flair": "Add flair", - "fetching": "Fetching site metadata" + "fetching": "Fetching site metadata", + "types": { + "normal": "Discussion", + "poll": "Poll", + "event": "Event" + } }, "profile": { "displayName": "Display name", @@ -587,7 +592,11 @@ "show": "Show results", "hide": "Hide results", "ends": "Ends {{time}}" - } + }, + "choices": "Choices", + "single": "Single choice", + "multiple": "Multiple choice", + "mode": "Mode" } }, "comment": { diff --git a/src/lib/feature/post/form/PostForm.svelte b/src/lib/feature/post/form/PostForm.svelte index f13ded7e..d7c31282 100644 --- a/src/lib/feature/post/form/PostForm.svelte +++ b/src/lib/feature/post/form/PostForm.svelte @@ -5,12 +5,17 @@ import { errorMessage } from '$lib/app/error' import { t } from '$lib/app/i18n' import MarkdownEditor from '$lib/app/markdown/MarkdownEditor.svelte' + import { settings } from '$lib/app/settings.svelte' import { placeholders } from '$lib/app/util.svelte' + import Duration from '$lib/ui/form/Duration.svelte' import FreeTextInput from '$lib/ui/form/FreeTextInput.svelte' import ObjectAutocomplete from '$lib/ui/form/ObjectAutocomplete.svelte' + import MultiSelect from '$lib/ui/form/Switch.svelte' import Avatar from '$lib/ui/generic/Avatar.svelte' import ErrorContainer, { pushError } from '$lib/ui/info/ErrorContainer.svelte' - import { Header } from '$lib/ui/layout' + import { CommonList, Header } from '$lib/ui/layout' + import EndPlaceholder from '$lib/ui/layout/EndPlaceholder.svelte' + import { publishedToDate } from '$lib/ui/util/date' import { Badge, Button, @@ -36,6 +41,8 @@ Photo, Plus, Sparkles, + Tag, + Trash, XMark, } from 'svelte-hero-icons/dist' import { autofillPost, PostFormState } from './postform.svelte' @@ -50,6 +57,9 @@ let { editPost, init, title, onsubmit }: Props = $props() let form = $state(init ?? new PostFormState()) + let type = $derived<'normal' | 'poll' | 'event'>( + init?.poll ? 'poll' : init?.event ? 'event' : 'normal', + ) let extendedCommunity = $derived.by(() => { const api = client() @@ -64,6 +74,20 @@ let uploadImage = $state(false) +{#if client() instanceof PiefedClient} +
+ +
+{/if} + {#if uploadImage} {#await import('$lib/ui/form/ImageInputModal.svelte') then { default: UploadModal }} { e.preventDefault() loading = true + form - .submit(editPost) + .submit(type, editPost) .then(onsubmit) .catch((err) => pushError({ message: errorMessage(err as string), scope: 'post-form' }), @@ -208,6 +233,7 @@ bind:value={form.title} placeholder={placeholders.get('post')} label={$t('form.post.title')} + class="font-display font-medium text-2xl" /> - {#if form.url !== undefined} + {#if type == 'normal' && form.url !== undefined} {/if} + {#if type == 'poll' && form.poll} +
+ + + {#each form.poll.choices as choice, index} +
  • +
    + +
    +
    + +
    +
  • + {/each} +
  • + +
  • +
    +
    + + + + {#snippet action()} + {#if !editPost} + { + return form.poll?.end_poll + ? Math.floor( + Date.now() - + publishedToDate(form.poll?.end_poll).getTime(), + ) + : Date.now() + 24 * 60 * 60 + }, + (v) => { + if (v == -1) form.poll!.end_poll = undefined + else + form.poll!.end_poll = new Date( + Date.now() + v * 1000, + ).toISOString() + } + } + /> + {/if} + {/snippet} + + {/if} + + {#if settings.debugInfo} + {form.poll?.end_poll} + {/if} +
    - - - {#if form.url && URL.canParse(form.url)} + {#if type == 'normal'} + + {#if form.url && URL.canParse(form.url)} + + {/if} {/if} {#if form.language === undefined} diff --git a/src/lib/feature/post/form/postform.svelte.ts b/src/lib/feature/post/form/postform.svelte.ts index 74925549..77fb56af 100644 --- a/src/lib/feature/post/form/postform.svelte.ts +++ b/src/lib/feature/post/form/postform.svelte.ts @@ -1,6 +1,12 @@ import { client } from '$lib/api/client.svelte' import { PiefedClient } from '$lib/api/piefed/adapter' -import type { Community, CommunityFlair, PostView } from '$lib/api/types' +import type { + Community, + CommunityFlair, + PostEvent, + PostPoll, + PostView, +} from '$lib/api/types' export type PostFormInit = { community?: Community @@ -11,6 +17,8 @@ export type PostFormInit = { alt_text?: string thumbnail?: string language_id?: number + poll?: PostPoll + event?: PostEvent flair_list?: CommunityFlair[] } @@ -23,6 +31,8 @@ export class PostFormState { altText?: string thumbnail?: string language?: string + poll?: PostPoll + event?: PostEvent flairList: CommunityFlair[] constructor(post?: PostFormInit) { @@ -33,6 +43,27 @@ export class PostFormState { this.nsfw = $state(post?.nsfw ?? false) this.altText = $state(post?.alt_text) this.language = $state(post?.language_id?.toString()) + this.poll = $state( + post?.poll ?? { + mode: 'single', + local_only: false, + choices: [ + { + choice_text: 'Option 1', + id: 1, + num_votes: 0, + sort_order: 0, + }, + { + choice_text: 'Option 2', + id: 2, + num_votes: 0, + sort_order: 1, + }, + ], + }, + ) + this.event = $state(post?.event) this.flairList = $state(post?.flair_list ?? []) } @@ -43,7 +74,10 @@ export class PostFormState { return true } - async submit(postId?: number): Promise { + async submit( + type: 'normal' | 'poll' | 'event' = 'normal', + postId?: number, + ): Promise { if (!this.validate(postId ? 'edit' : 'create')) throw new Error('failed validation') @@ -61,6 +95,8 @@ export class PostFormState { alt_text: this.altText, custom_thumbnail: this.thumbnail, language_id: Number(this.language) || undefined, + poll: type == 'poll' ? this.poll : undefined, + event: type == 'event' ? this.event : undefined, }) ).post_view } else { @@ -74,6 +110,8 @@ export class PostFormState { custom_thumbnail: this.thumbnail, nsfw: this.nsfw, language_id: Number(this.language) || undefined, + poll: type == 'poll' ? this.poll : undefined, + event: type == 'event' ? this.event : undefined, }) ).post_view } diff --git a/src/lib/ui/form/FreeTextInput.svelte b/src/lib/ui/form/FreeTextInput.svelte index ae2c0ecb..2018d5bf 100644 --- a/src/lib/ui/form/FreeTextInput.svelte +++ b/src/lib/ui/form/FreeTextInput.svelte @@ -47,6 +47,6 @@ {required} {...rest} rows={1} - class="font-semibold text-2xl focus:outline-hidden w-full bg-transparent resize-none {clazz}" + class={['focus:outline-hidden w-full bg-transparent resize-none', clazz]} > diff --git a/src/lib/ui/shared/button/Button.svelte b/src/lib/ui/shared/button/Button.svelte index 101719a7..da153ccb 100644 --- a/src/lib/ui/shared/button/Button.svelte +++ b/src/lib/ui/shared/button/Button.svelte @@ -314,21 +314,25 @@ .btn-square-sm { width: calc(var(--spacing) * 6); height: calc(var(--spacing) * 6); + padding: 0; } .btn-square-md { width: calc(var(--spacing) * 8); height: calc(var(--spacing) * 8); + padding: 0; } .btn-square-lg { width: calc(var(--spacing) * 9.5); height: calc(var(--spacing) * 9.5); + padding: 0; } .btn-square-xl { width: calc(var(--spacing) * 12); height: calc(var(--spacing) * 12); + padding: 0; } .btn-disabled { diff --git a/src/lib/ui/shared/button/ButtonGroup.svelte b/src/lib/ui/shared/button/ButtonGroup.svelte index 477fddb6..6ff46d45 100644 --- a/src/lib/ui/shared/button/ButtonGroup.svelte +++ b/src/lib/ui/shared/button/ButtonGroup.svelte @@ -39,7 +39,7 @@ .btn-group.btn-group-horizontal :global(> *) { position: relative; - border-radius: 8px 8px 8px 8px !important; + border-radius: 8px !important; &:first-child { border-radius: 24px 12px 12px 24px !important; diff --git a/src/routes/create/+layout.svelte b/src/routes/create/+layout.svelte index 477466bd..0c3c7996 100644 --- a/src/routes/create/+layout.svelte +++ b/src/routes/create/+layout.svelte @@ -7,26 +7,24 @@ let { children } = $props() +{#if !site || !(site.data?.site_view.local_site.community_creation_admin_only && !profile.isAdmin)} + +{/if} +
    {$t('nav.create.label')} - {#snippet extended()} - {#if !site || !(site.data?.site_view.local_site.community_creation_admin_only && !profile.isAdmin)} - - {/if} - {/snippet}
    {@render children?.()}