|
| 1 | +<script lang="ts"> |
| 2 | + import { fanslyApi } from '@/lib/api/fansly.svelte'; |
| 3 | + import { usernamePaintDesigns } from '@/lib/entryPoints/accountCard'; |
| 4 | + import { sharedState } from '@/lib/state/state.svelte'; |
| 5 | + import { ActionType } from '@/lib/types'; |
| 6 | + import Button from '../../button/button.svelte'; |
| 7 | + import Label from '../../label/label.svelte'; |
| 8 | + import Modal from '../../modal/Modal.svelte'; |
| 9 | +
|
| 10 | + interface Props { |
| 11 | + action: ActionType; |
| 12 | + } |
| 13 | +
|
| 14 | + let { action = $bindable() }: Props = $props(); |
| 15 | +
|
| 16 | + let selectedPaintId: number = $state(0); |
| 17 | + let previewText: string = $state('Preview'); |
| 18 | + let error: string | null = $state(null); |
| 19 | +
|
| 20 | + function onClose() { |
| 21 | + action = ActionType.None; |
| 22 | + } |
| 23 | +
|
| 24 | + async function onSavePaint() { |
| 25 | + error = null; |
| 26 | +
|
| 27 | + try { |
| 28 | + const result = await fanslyApi.sendChatMessage( |
| 29 | + sharedState.chatroomId!, |
| 30 | + `!setpaint ${selectedPaintId}` |
| 31 | + ); |
| 32 | +
|
| 33 | + if (!result) { |
| 34 | + error = 'Failed to set username paint, please try again later.'; |
| 35 | + return; |
| 36 | + } |
| 37 | +
|
| 38 | + onClose(); |
| 39 | +
|
| 40 | + // Reload the page to apply the new username paint |
| 41 | + setTimeout(() => { |
| 42 | + window.location.reload(); |
| 43 | + }, 100); |
| 44 | + } catch (err) { |
| 45 | + error = 'An error occurred while setting username paint.'; |
| 46 | + console.error('Error setting username paint:', err); |
| 47 | + } |
| 48 | + } |
| 49 | +
|
| 50 | + $effect(() => { |
| 51 | + // Load userpaint CSS if not already loaded |
| 52 | + const head = document.head; |
| 53 | + if (!head.querySelector('style#ftv-userpaint-css')) { |
| 54 | + import('@/assets/userpaint.css?inline').then((module) => { |
| 55 | + const style = document.createElement('style'); |
| 56 | + style.id = 'ftv-userpaint-css'; |
| 57 | + style.media = 'screen'; |
| 58 | + style.innerHTML = module.default; |
| 59 | + document.head.appendChild(style); |
| 60 | + }); |
| 61 | + } |
| 62 | + }); |
| 63 | +
|
| 64 | + const selectedDesign = $derived( |
| 65 | + usernamePaintDesigns.find((design) => design.id === selectedPaintId) || usernamePaintDesigns[0] |
| 66 | + ); |
| 67 | +</script> |
| 68 | + |
| 69 | +<Modal showModal={true} {onClose}> |
| 70 | + {#snippet header()} |
| 71 | + <h2>Set Username Paint</h2> |
| 72 | + {/snippet} |
| 73 | + |
| 74 | + {#snippet body()} |
| 75 | + <div class="flex flex-col space-y-4"> |
| 76 | + <div> |
| 77 | + <Label for="paint-select">Select Username Paint</Label> |
| 78 | + <select |
| 79 | + id="paint-select" |
| 80 | + class="mt-2 flex h-10 w-full items-center justify-between rounded-md border border-input bg-background px-3 py-2 text-sm ring-offset-background focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2" |
| 81 | + bind:value={selectedPaintId} |
| 82 | + > |
| 83 | + {#each usernamePaintDesigns as design} |
| 84 | + <option value={design.id}>{design.id}</option> |
| 85 | + {/each} |
| 86 | + </select> |
| 87 | + </div> |
| 88 | + |
| 89 | + <div> |
| 90 | + <Label>Preview</Label> |
| 91 | + <div class="mt-2 rounded-md border border-input bg-background p-4"> |
| 92 | + <div class="flex items-center justify-center"> |
| 93 | + <span |
| 94 | + class="relative inline-block text-lg font-bold {selectedDesign.class |
| 95 | + ? 'userpaints-' + selectedDesign.class |
| 96 | + : ''} {selectedDesign.textClass ? 'userpaints-' + selectedDesign.textClass : ''}" |
| 97 | + > |
| 98 | + {previewText} |
| 99 | + {#if selectedDesign.gif} |
| 100 | + <img |
| 101 | + src="https://zergo0botcdn.zergo0.dev/assets/{selectedDesign.gif}.gif" |
| 102 | + alt="Username paint effect" |
| 103 | + class="userpaints-effect-overlay" |
| 104 | + /> |
| 105 | + {/if} |
| 106 | + </span> |
| 107 | + </div> |
| 108 | + </div> |
| 109 | + </div> |
| 110 | + |
| 111 | + <div> |
| 112 | + <Label for="preview-text">Preview Text</Label> |
| 113 | + <input |
| 114 | + id="preview-text" |
| 115 | + type="text" |
| 116 | + class="mt-2 flex h-10 w-full rounded-md border border-input bg-background px-3 py-2 text-sm ring-offset-background placeholder:text-muted-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2" |
| 117 | + bind:value={previewText} |
| 118 | + placeholder="Enter preview text" |
| 119 | + /> |
| 120 | + </div> |
| 121 | + |
| 122 | + <hr /> |
| 123 | + |
| 124 | + {#if error} |
| 125 | + <p class="text-xs text-red-500">{error}</p> |
| 126 | + {/if} |
| 127 | + |
| 128 | + <div class="flex justify-end space-x-2"> |
| 129 | + <Button variant="secondary" size="sm" class="w-full" onclick={onClose}>Cancel</Button> |
| 130 | + <Button variant="default" size="sm" class="w-full" onclick={onSavePaint}>Save Paint</Button> |
| 131 | + </div> |
| 132 | + </div> |
| 133 | + {/snippet} |
| 134 | +</Modal> |
0 commit comments