[READ-ONLY] Mirror of https://github.com/flo-bit/skywatched. review movies and tv shows, based on at proto skywatched.app
0

Configure Feed

Select the types of activity you want to include in your feed.

skywatched / src / lib / state.svelte.ts
4.0 kB 173 lines
1export const watchedItems = $state({ 2 ratedMovies: new Map<number, { rating: number; ratingText?: string; updatedAt: string }>(), 3 ratedShows: new Map<number, { rating: number; ratingText?: string; updatedAt: string }>(), 4 5 hasRated: (item: { movieId?: number; showId?: number }) => { 6 const id = item.movieId ?? item.showId; 7 if (!id) return false; 8 return item.movieId ? watchedItems.ratedMovies.has(id) : watchedItems.ratedShows.has(id); 9 }, 10 11 addRated: (item: { movieId?: number; showId?: number; rating: number; ratingText?: string }) => { 12 const id = item.movieId ?? item.showId; 13 if (!id) return; 14 if (item.movieId) 15 watchedItems.ratedMovies.set(id, { 16 rating: item.rating, 17 ratingText: item.ratingText, 18 updatedAt: new Date().toISOString() 19 }); 20 else 21 watchedItems.ratedShows.set(id, { 22 rating: item.rating, 23 ratingText: item.ratingText, 24 updatedAt: new Date().toISOString() 25 }); 26 }, 27 28 getRating: (item: { movieId?: number; showId?: number }) => { 29 const id = item.movieId ?? item.showId; 30 if (!id) return undefined; 31 return item.movieId ? watchedItems.ratedMovies.get(id) : watchedItems.ratedShows.get(id); 32 } 33}); 34 35type RateMovieModalItem = { 36 movieId: number | undefined; 37 showId: number | undefined; 38 kind: string | undefined; 39 name: string | undefined; 40 posterPath: string | undefined; 41 currentRating: number | undefined; 42 currentReview: string | undefined; 43}; 44 45export const rateMovieModal: { 46 showModal: boolean; 47 48 selectedItem: RateMovieModalItem; 49 50 show: (item: RateMovieModalItem) => void; 51 hide: () => void; 52 showEmpty: () => void; 53} = $state({ 54 showModal: false, 55 56 selectedItem: { 57 movieId: undefined, 58 showId: undefined, 59 kind: undefined, 60 name: undefined, 61 posterPath: undefined, 62 currentRating: undefined, 63 currentReview: undefined 64 }, 65 66 show: (item: RateMovieModalItem) => { 67 rateMovieModal.selectedItem = item; 68 rateMovieModal.showModal = true; 69 }, 70 71 hide: () => { 72 rateMovieModal.showModal = false; 73 }, 74 75 showEmpty: () => { 76 rateMovieModal.selectedItem = { 77 movieId: undefined, 78 showId: undefined, 79 kind: undefined, 80 name: undefined, 81 posterPath: undefined, 82 currentRating: undefined, 83 currentReview: undefined 84 }; 85 rateMovieModal.showModal = true; 86 } 87}); 88 89export const crosspostModal: { 90 showModal: boolean; 91 uri: string | undefined; 92 review: string | undefined; 93 rating: number | undefined; 94 title: string | undefined; 95 96 show: (uri: string, review: string, rating: number, title: string) => void; 97 hide: () => void; 98} = $state({ 99 showModal: false, 100 uri: undefined, 101 review: undefined, 102 rating: undefined, 103 title: undefined, 104 105 show: (uri: string, review: string, rating: number, title: string) => { 106 crosspostModal.uri = uri; 107 crosspostModal.review = review; 108 crosspostModal.rating = rating; 109 crosspostModal.title = title; 110 crosspostModal.showModal = true; 111 }, 112 113 hide: () => { 114 crosspostModal.showModal = false; 115 crosspostModal.uri = undefined; 116 crosspostModal.review = undefined; 117 crosspostModal.rating = undefined; 118 crosspostModal.title = undefined; 119 } 120}); 121 122export const settings: { 123 streamingRegion: string | undefined; 124 crosspostEnabled: boolean | undefined; 125} = $state({ 126 streamingRegion: undefined, 127 crosspostEnabled: undefined 128}); 129 130export const user: { 131 displayName: string | undefined; 132 handle: string | undefined; 133 avatar: string | undefined; 134} = $state({ 135 displayName: undefined, 136 handle: undefined, 137 avatar: undefined 138}); 139 140export const showLoginModal = $state({ 141 value: false, 142 toggle: () => { 143 showLoginModal.value = !showLoginModal.value; 144 } 145}); 146 147export const showSidebar = $state({ 148 value: false, 149 toggle: () => { 150 showSidebar.value = !showSidebar.value; 151 } 152}); 153 154export const videoPlayer: { 155 showing: boolean; 156 id: string | undefined; 157 158 show: (id: string) => void; 159 hide: () => void; 160} = $state({ 161 showing: false, 162 id: undefined, 163 164 show: (id: string) => { 165 videoPlayer.id = id; 166 videoPlayer.showing = true; 167 }, 168 169 hide: () => { 170 videoPlayer.id = undefined; 171 videoPlayer.showing = false; 172 } 173});