|
1 | 1 | <script lang="ts"> |
2 | | - import { Navbar } from '$components'; |
3 | | - import { IconCard, RepoCard, PackageCard, CardList, ItemCardGrid } from '$components/card'; |
4 | | - import { ItemChipList } from '$components/chip'; |
5 | | - import Background from '$components/Background.svelte'; |
6 | | - import EditableMarkdown from '$components/markdown'; |
7 | | - import api from '$endpoints'; |
8 | | - import consts from '$lib/consts'; |
9 | | - import { generateKeywords } from '$lib/seo'; |
10 | | - import EditControls from '$components/EditControls.svelte'; |
| 2 | + import { Navbar } from "$components"; |
| 3 | + import { |
| 4 | + IconCard, |
| 5 | + RepoCard, |
| 6 | + PackageCard, |
| 7 | + CardList, |
| 8 | + ItemCardGrid, |
| 9 | + } from "$components/card"; |
| 10 | + import { ItemChipList } from "$components/chip"; |
| 11 | + import Background from "$components/Background.svelte"; |
| 12 | + import EditableMarkdown from "$components/markdown"; |
| 13 | + import api from "$endpoints"; |
| 14 | + import consts from "$lib/consts"; |
| 15 | + import { generateKeywords } from "$lib/seo"; |
| 16 | + import EditControls from "$components/EditControls.svelte"; |
11 | 17 | // import AsciinemaPlayer from "$components"; |
12 | 18 |
|
13 | | - export let data: import('./$types').PageData; |
| 19 | + export let data: import("./$types").PageData; |
14 | 20 |
|
15 | 21 | let groupData = data.globals.groups[data.groupId]; |
16 | 22 | let itemData = data.globals.items[data.groupId][data.itemId]; |
17 | 23 |
|
18 | 24 | let editing = false; |
19 | 25 |
|
20 | | - let readme = ''; |
| 26 | + let readme = ""; |
21 | 27 |
|
22 | | - let chipLinks = itemData.info.links.filter(([l]) => l.style === 'chip'); |
23 | | - let cardLinks = itemData.info.links.filter(([l]) => l.style === 'card'); |
| 28 | + let chipLinks = itemData.info.links.filter(([l]) => l.style === "chip"); |
| 29 | + let cardLinks = itemData.info.links.filter(([l]) => l.style === "card"); |
24 | 30 |
|
25 | 31 | function beginEditing() { |
26 | 32 | editing = true; |
|
30 | 36 | editing = false; |
31 | 37 | if (save) { |
32 | 38 | itemData.readme = readme; |
33 | | - await api().group.withId(data.groupId).item.withId(data.itemId).readme.set(readme); |
| 39 | + await api() |
| 40 | + .group.withId(data.groupId) |
| 41 | + .item.withId(data.itemId) |
| 42 | + .readme.set(readme); |
34 | 43 | // Update other info |
35 | | - await api().group.withId(data.groupId).item.withId(data.itemId).info.set(itemData.info); |
| 44 | + await api() |
| 45 | + .group.withId(data.groupId) |
| 46 | + .item.withId(data.itemId) |
| 47 | + .info.set(itemData.info); |
36 | 48 | } |
37 | 49 | // Reset data |
38 | 50 | setupData(data.groupId, data.itemId); |
|
43 | 55 | groupData = data.globals.groups[groupId]; |
44 | 56 | itemData = data.globals.items[groupId][itemId]; |
45 | 57 | readme = itemData.readme; |
46 | | - chipLinks = itemData.info.links.filter(([l]) => l.style === 'chip'); |
47 | | - cardLinks = itemData.info.links.filter(([l]) => l.style === 'card'); |
| 58 | + chipLinks = itemData.info.links.filter(([l]) => l.style === "chip"); |
| 59 | + cardLinks = itemData.info.links.filter(([l]) => l.style === "card"); |
48 | 60 | } |
49 | 61 |
|
50 | 62 | function changeLinkTitle(linkedGroup: string, newTitle: string) { |
51 | | - const linkInfo = itemData.info.links.find(link => link[0].groupId === linkedGroup); |
| 63 | + const linkInfo = itemData.info.links.find( |
| 64 | + (link) => link[0].groupId === linkedGroup, |
| 65 | + ); |
52 | 66 | if (!linkInfo) { |
53 | 67 | // This shouldn't happen |
54 | 68 | throw Error(`changeLinkTitle: linkInfo not found for ${linkedGroup}`); |
|
57 | 71 | } |
58 | 72 |
|
59 | 73 | async function toggleLink(linkedGroup: string, linkedItem: string) { |
60 | | - const linkInfo = itemData.info.links.find(link => link[0].groupId === linkedGroup); |
| 74 | + const linkInfo = itemData.info.links.find( |
| 75 | + (link) => link[0].groupId === linkedGroup, |
| 76 | + ); |
61 | 77 | if (!linkInfo) { |
62 | 78 | // This shouldn't happen |
63 | | - throw Error(`toggleLink: linkInfo not found for ${linkedGroup}/${linkedItem}`); |
| 79 | + throw Error( |
| 80 | + `toggleLink: linkInfo not found for ${linkedGroup}/${linkedItem}`, |
| 81 | + ); |
64 | 82 | } |
65 | 83 | const newState = !linkInfo[1].includes(linkedItem); |
66 | 84 | if (newState) { |
67 | 85 | // Create link |
68 | | - await api().group.withId(data.groupId).item.withId(data.itemId).links.create(linkedGroup, linkedItem); |
| 86 | + await api() |
| 87 | + .group.withId(data.groupId) |
| 88 | + .item.withId(data.itemId) |
| 89 | + .links.create(linkedGroup, linkedItem); |
69 | 90 | // Update state in browser to match |
70 | 91 | linkInfo[1].push(linkedItem); |
71 | 92 | } else { |
72 | 93 | // Unlink |
73 | | - await api().group.withId(data.groupId).item.withId(data.itemId).links.remove(linkedGroup, linkedItem); |
74 | | - linkInfo[1] = linkInfo[1].filter(item => item !== linkedItem); |
| 94 | + await api() |
| 95 | + .group.withId(data.groupId) |
| 96 | + .item.withId(data.itemId) |
| 97 | + .links.remove(linkedGroup, linkedItem); |
| 98 | + linkInfo[1] = linkInfo[1].filter((item) => item !== linkedItem); |
75 | 99 | } |
76 | 100 | // Force update chip and card links |
77 | 101 | chipLinks = [...chipLinks]; |
|
83 | 107 |
|
84 | 108 | <!-- TODO: Find a less repetitive way to get SEO working nicely --> |
85 | 109 | <svelte:head> |
86 | | - <title>{itemData.info.name} - {groupData.info.name} - {data.globals.config.siteShortName}</title> |
87 | | - <meta name="description" content="{itemData.info.pageDescription}"> |
88 | | - <meta name="generator" content="{consts.APP_NAME}"> |
89 | | - <meta name="keywords" content="{generateKeywords(data.globals, data.groupId, data.itemId)}"> |
90 | | - <meta name="theme-color" content="{itemData.info.color}"> |
| 110 | + <title |
| 111 | + >{itemData.info.name} - {groupData.info.name} - {data.globals.config |
| 112 | + .siteShortName}</title |
| 113 | + > |
| 114 | + <meta name="description" content={itemData.info.pageDescription} /> |
| 115 | + <meta name="generator" content={consts.APP_NAME} /> |
| 116 | + <meta |
| 117 | + name="keywords" |
| 118 | + content={generateKeywords(data.globals, data.groupId, data.itemId)} |
| 119 | + /> |
| 120 | + <meta name="theme-color" content={itemData.info.color} /> |
91 | 121 | </svelte:head> |
92 | 122 |
|
93 | 123 | <Background color={itemData.info.color}></Background> |
|
102 | 132 | /> |
103 | 133 |
|
104 | 134 | <main> |
105 | | - <EditControls {editing} on:beginEdits={beginEditing} on:finishEdits={e => finishEditing(e.detail)}/> |
| 135 | + <EditControls |
| 136 | + {editing} |
| 137 | + loggedIn={data.loggedIn} |
| 138 | + on:beginEdits={beginEditing} |
| 139 | + on:finishEdits={(e) => finishEditing(e.detail)} |
| 140 | + /> |
106 | 141 | {#if itemData.info.banner} |
107 | 142 | <img |
108 | 143 | src="/{data.groupId}/{data.itemId}/{itemData.info.banner}" |
|
111 | 146 | /> |
112 | 147 | {/if} |
113 | 148 | <div id="info-container"> |
114 | | - <EditableMarkdown |
115 | | - bind:source={readme} |
116 | | - {editing} |
117 | | - /> |
| 149 | + <EditableMarkdown bind:source={readme} {editing} /> |
118 | 150 | <!-- Display linked items as chips --> |
119 | 151 | <div id="chip-links"> |
120 | 152 | {#each chipLinks as [linkOptions, linkedItems]} |
121 | | - {#if !editing} |
| 153 | + {#if !editing} |
122 | 154 | <div class="chip-link-row"> |
123 | 155 | <h2>{linkOptions.title}</h2> |
124 | 156 | <ItemChipList |
125 | 157 | globals={data.globals} |
126 | | - items={[linkedItems.map(i => ({ groupId: linkOptions.groupId, itemId: i, selected: false }))]} |
| 158 | + items={[ |
| 159 | + linkedItems.map((i) => ({ |
| 160 | + groupId: linkOptions.groupId, |
| 161 | + itemId: i, |
| 162 | + selected: false, |
| 163 | + })), |
| 164 | + ]} |
127 | 165 | link={true} |
128 | 166 | /> |
129 | 167 | </div> |
130 | 168 | {:else} |
131 | 169 | <div class="chip-link-row"> |
132 | | - <input type="text" bind:value={linkOptions.title} on:input={() => changeLinkTitle(linkOptions.groupId, linkOptions.title)} /> |
| 170 | + <input |
| 171 | + type="text" |
| 172 | + bind:value={linkOptions.title} |
| 173 | + on:input={() => |
| 174 | + changeLinkTitle(linkOptions.groupId, linkOptions.title)} |
| 175 | + /> |
133 | 176 | <div class="chip-link-items"> |
134 | 177 | <ItemChipList |
135 | 178 | globals={data.globals} |
136 | | - items={[Object.keys(data.globals.items[linkOptions.groupId]).map(itemId => ({ groupId: linkOptions.groupId, itemId, selected: linkedItems.includes(itemId) }))]} |
137 | | - on:click={e => toggleLink(e.detail.groupId, e.detail.itemId)} |
| 179 | + items={[ |
| 180 | + Object.keys(data.globals.items[linkOptions.groupId]).map( |
| 181 | + (itemId) => ({ |
| 182 | + groupId: linkOptions.groupId, |
| 183 | + itemId, |
| 184 | + selected: linkedItems.includes(itemId), |
| 185 | + }), |
| 186 | + ), |
| 187 | + ]} |
| 188 | + on:click={(e) => toggleLink(e.detail.groupId, e.detail.itemId)} |
138 | 189 | /> |
139 | 190 | </div> |
140 | 191 | </div> |
|
152 | 203 | link={itemData.info.urls.site} |
153 | 204 | color={itemData.info.color} |
154 | 205 | > |
155 | | - <i slot="icon" class="las la-globe"></i> |
| 206 | + <i slot="icon" class="las la-globe"></i> |
156 | 207 | </IconCard> |
157 | 208 | {/if} |
158 | 209 | {#if itemData.info.urls.docs} |
|
165 | 216 | </IconCard> |
166 | 217 | {/if} |
167 | 218 | {#if itemData.info.urls.repo} |
168 | | - <RepoCard |
169 | | - repo={itemData.info.urls.repo} |
170 | | - color={itemData.info.color} |
171 | | - /> |
| 219 | + <RepoCard repo={itemData.info.urls.repo} color={itemData.info.color} /> |
172 | 220 | {/if} |
173 | 221 | {#if itemData.info.package} |
174 | | - <PackageCard |
175 | | - info={itemData.info.package} |
176 | | - color={itemData.info.color} |
177 | | - /> |
| 222 | + <PackageCard info={itemData.info.package} color={itemData.info.color} /> |
178 | 223 | {/if} |
179 | 224 | </CardList> |
180 | 225 | </div> |
|
190 | 235 | <!-- Display linked items as cards --> |
191 | 236 | <div id="card-links"> |
192 | 237 | {#each cardLinks as [linkOptions, linkedItems]} |
193 | | - <h2 contenteditable={editing}> |
194 | | - {linkOptions.title} |
195 | | - </h2> |
| 238 | + <h2 contenteditable={editing}> |
| 239 | + {linkOptions.title} |
| 240 | + </h2> |
196 | 241 | <ItemCardGrid |
197 | 242 | globals={data.globals} |
198 | 243 | groupId={linkOptions.groupId} |
|
0 commit comments