Skip to content

Commit 2604a7f

Browse files
fix: recipe layout mobile fixes
1 parent fe29735 commit 2604a7f

4 files changed

Lines changed: 69 additions & 52 deletions

File tree

src/lib/components/comment/CommentList.svelte

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,8 @@
3333
formError = null,
3434
loading = false,
3535
loadComments,
36-
total = $bindable()
36+
total = $bindable(),
37+
preview = false
3738
}: {
3839
comments: CommentT[]
3940
isLoggedIn: boolean
@@ -42,6 +43,7 @@
4243
loading?: boolean
4344
loadComments: (page: number) => Promise<{ comments: CommentT[]; total: number }>
4445
total: number
46+
preview?: boolean
4547
} = $props()
4648
4749
let page = $state(0)
@@ -164,7 +166,7 @@
164166
name="content"
165167
placeholder="Add a comment..."
166168
rows="2"
167-
disabled={isSubmitting}
169+
disabled={isSubmitting || loading || preview}
168170
bind:value={commentContent}
169171
></textarea>
170172
{/snippet}
@@ -190,7 +192,7 @@
190192
<label
191193
for="image-upload"
192194
class="image-upload-label"
193-
class:disabled={isSubmitting || loading}
195+
class:disabled={isSubmitting || loading || preview}
194196
>
195197
<ImageIcon size={18} />
196198
<span>Add Image</span>
@@ -201,11 +203,11 @@
201203
id="image-upload"
202204
accept="image/jpeg,image/png,image/gif,image/webp"
203205
onchange={handleImageSelect}
204-
disabled={isSubmitting || loading}
206+
disabled={isSubmitting || loading || preview}
205207
/>
206208
</div>
207209

208-
<Button type="submit" color="primary" size="sm" disabled={isSubmitting || loading}>
210+
<Button type="submit" color="primary" size="sm" disabled={isSubmitting || loading || preview}>
209211
{isSubmitting ? 'Posting...' : 'Post Comment'}
210212
</Button>
211213
</div>

src/lib/components/recipe-popup/RecipePopup.svelte

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@
144144
.floating-actions {
145145
position: fixed;
146146
left: 50%;
147-
bottom: 70px;
147+
bottom: var(--spacing-md);
148148
transform: translateX(-50%);
149149
display: flex;
150150
gap: var(--spacing-xl);

src/lib/pages/recipe/MobileLayout.svelte

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<script lang="ts">
22
import type { Snippet } from 'svelte'
3-
import Activity from 'lucide-svelte/icons/activity'
3+
import ChartPie from 'lucide-svelte/icons/chart-pie'
44
import ListOrdered from 'lucide-svelte/icons/list-ordered'
55
import Carrot from 'lucide-svelte/icons/carrot'
66
import MessageSquare from 'lucide-svelte/icons/message-square'
@@ -15,7 +15,8 @@
1515
nutrition,
1616
ingredients,
1717
comments,
18-
instructions
18+
instructions,
19+
hasNutrition = true
1920
}: {
2021
image: Snippet
2122
tags: Snippet
@@ -26,6 +27,7 @@
2627
ingredients: Snippet
2728
comments: Snippet
2829
instructions: Snippet<[useCookingMode: boolean]>
30+
hasNutrition?: boolean | Promise<boolean>
2931
} = $props()
3032
3133
let activeTab = $state<'nutrition' | 'ingredients' | 'instructions' | 'comments'>('ingredients')
@@ -72,15 +74,19 @@
7274
>
7375
<ListOrdered size={18} />
7476
</button>
75-
<button
76-
class="tab-button {activeTab === 'nutrition' ? 'active' : ''}"
77-
type="button"
78-
aria-label="Nutrition"
79-
aria-pressed={activeTab === 'nutrition'}
80-
onclick={() => (activeTab = 'nutrition')}
81-
>
82-
<Activity size={18} />
83-
</button>
77+
{#await Promise.resolve(hasNutrition) then hasNut}
78+
{#if hasNut}
79+
<button
80+
class="tab-button {activeTab === 'nutrition' ? 'active' : ''}"
81+
type="button"
82+
aria-label="Nutrition"
83+
aria-pressed={activeTab === 'nutrition'}
84+
onclick={() => (activeTab = 'nutrition')}
85+
>
86+
<ChartPie size={18} />
87+
</button>
88+
{/if}
89+
{/await}
8490
<button
8591
class="tab-button {activeTab === 'comments' ? 'active' : ''}"
8692
type="button"

src/lib/pages/recipe/Recipe.svelte

Lines changed: 44 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,15 @@
8181
let imageBroken = $state(false)
8282
let currentServings = $state<number>(1)
8383
84+
let hasNutrition = $derived(
85+
data.then((r) => {
86+
const n = r.recipe.nutrition
87+
if (!n) return false
88+
const { calories, protein, carbs, fat } = n
89+
return !(calories === 0 && protein === 0 && carbs === 0 && fat === 0)
90+
})
91+
)
92+
8493
$effect(() => {
8594
data.then((r) => {
8695
totalComments = r.comments.total
@@ -391,41 +400,40 @@
391400
{/snippet}
392401

393402
{#snippet comments()}
394-
{#if !preview}
395-
<div class="comments-section" bind:this={commentsSection}>
396-
<div class="header no-top-margin-mobile">
397-
<h3 style:display="flex" style:align-items="center" style:gap="var(--spacing-sm)">
398-
<MessageSquare size={20} />
399-
Comments
400-
{#if totalComments}
401-
<span style:font-size="var(--font-size-xl)" style:font-weight="500">
402-
({totalComments})
403-
</span>
404-
{/if}
405-
</h3>
406-
</div>
407-
{#await data}
408-
<CommentList
409-
comments={[]}
410-
isLoggedIn={false}
411-
recipeId=""
412-
{formError}
413-
loading={true}
414-
total={0}
415-
loadComments={() => Promise.resolve({ comments: [], total: 0 })}
416-
/>
417-
{:then recipeData}
418-
<CommentList
419-
comments={recipeData.comments.comments}
420-
isLoggedIn={recipeData.isLoggedIn}
421-
recipeId={recipeData.recipe.id}
422-
{formError}
423-
bind:total={totalComments}
424-
{loadComments}
425-
/>
426-
{/await}
403+
<div class="comments-section" bind:this={commentsSection}>
404+
<div class="header no-top-margin-mobile">
405+
<h3 style:display="flex" style:align-items="center" style:gap="var(--spacing-sm)">
406+
<MessageSquare size={20} />
407+
Comments
408+
{#if totalComments}
409+
<span style:font-size="var(--font-size-xl)" style:font-weight="500">
410+
({totalComments})
411+
</span>
412+
{/if}
413+
</h3>
427414
</div>
428-
{/if}
415+
{#await data}
416+
<CommentList
417+
comments={[]}
418+
isLoggedIn={false}
419+
recipeId=""
420+
{formError}
421+
loading={true}
422+
total={0}
423+
loadComments={() => Promise.resolve({ comments: [], total: 0 })}
424+
/>
425+
{:then recipeData}
426+
<CommentList
427+
comments={recipeData.comments.comments}
428+
isLoggedIn={recipeData.isLoggedIn}
429+
recipeId={recipeData.recipe.id}
430+
{formError}
431+
bind:total={totalComments}
432+
{loadComments}
433+
{preview}
434+
/>
435+
{/await}
436+
</div>
429437
{/snippet}
430438

431439
<div class="recipe-desktop-view">
@@ -441,7 +449,8 @@
441449
</div>
442450

443451
<div class="recipe-mobile-view">
444-
<MobileLayout {tags} {title} {actionButtons} {nutrition} {ingredients} {instructions} {comments}>
452+
<MobileLayout {tags} {title} {actionButtons} {nutrition} {ingredients} {instructions} {comments}
453+
{...{ hasNutrition }}>
445454
{#snippet image()}
446455
{@render commonImage()}
447456
{/snippet}

0 commit comments

Comments
 (0)