Skip to content

Commit 06d8cba

Browse files
authored
Merge pull request #154 from xsnippet/snippet-id-as-string
Pass snippet id and marker as strings without additional convertation
2 parents 8bba5d3 + d4fec0a commit 06d8cba

File tree

5 files changed

+11
-11
lines changed

5 files changed

+11
-11
lines changed

src/api/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import parseLinkHeader from 'parse-link-header'
33
import { getApiUri } from '../misc/url'
44
import { Snippet } from '../store'
55

6-
export const fetchSnippet = (id: number): Promise<Snippet> => {
6+
export const fetchSnippet = (id: string): Promise<Snippet> => {
77
return fetch(getApiUri(`snippets/${id}`))
88
.then(response => response.json())
99
}
@@ -13,7 +13,7 @@ export const fetchSyntaxes = (): Promise<string[]> => {
1313
.then(response => response.json())
1414
}
1515

16-
export const fetchRecentSnippets = (marker: number): Promise<{ snippets: Snippet[], pagination: parseLinkHeader.Links | null}> => {
16+
export const fetchRecentSnippets = (marker: string): Promise<{ snippets: Snippet[], pagination: parseLinkHeader.Links | null}> => {
1717
let qs = ''
1818
if (marker) { qs = `&marker=${marker}` }
1919
let pagination: parseLinkHeader.Links

src/components/RecentSnippets.jsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ const RecentSnippets = () => {
2222
setSnippets(snippets)
2323

2424
const getSetOfSnippets = (direction) => {
25-
setMarker(Number(pagination[direction].marker))
25+
setMarker(pagination[direction].marker)
2626
scrollTop()
2727
}
2828

src/components/Snippet.jsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ import '../styles/Snippet.styl'
1818

1919
const Snippet = ({ match }) => {
2020
const [isShowEmbed, setIsShowEmbed] = useState(false)
21-
const fetchedSnippet = useRecoilValueLoadable(snippetById(Number(match.params.id)))
21+
const fetchedSnippet = useRecoilValueLoadable(snippetById(match.params.id))
2222
const embeddedRef = useRef()
2323

2424
if (fetchedSnippet.state !== 'hasValue') return <Spinner />

src/misc/url.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import conf from '../conf'
22

3-
export const getRawUrl = (id: number): string => conf.RAW_SNIPPET_URI_FORMAT.replace('%s', id)
3+
export const getRawUrl = (id: string): string => conf.RAW_SNIPPET_URI_FORMAT.replace('%s', id)
44

55
export const getApiUri = (endpoint: string, version = 'v1'): string => (
66
`${conf.API_BASE_URI}/${version}/${endpoint}`

src/store/index.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,12 @@ import { fetchSnippet, fetchSyntaxes, fetchRecentSnippets } from '../api'
44
import { normalizedSyntaxes } from '../misc/modes'
55

66
export type Snippet = {
7-
content: string;
8-
created_at: string;
9-
id: number;
7+
id: string;
8+
title: string;
109
syntax: string;
10+
content: string;
1111
tags: string[];
12-
title: string;
12+
created_at: string;
1313
updated_at: string;
1414
}
1515

@@ -28,7 +28,7 @@ export const syntaxesQuery = selector({
2828

2929
export const recentSnippetsQuery = selectorFamily({
3030
key: 'recentSnippetsQuery',
31-
get: (marker: number) => async () => {
31+
get: (marker: string) => async () => {
3232
const { snippets, pagination } = await fetchRecentSnippets(marker)
3333

3434
return {
@@ -41,7 +41,7 @@ export const recentSnippetsQuery = selectorFamily({
4141

4242
export const snippetById = selectorFamily({
4343
key: 'snippetById',
44-
get: (id: number) => async ({ get }) => {
44+
get: (id: string) => async ({ get }) => {
4545
const snippets = get(recentSnippetsState)
4646

4747
if (snippets) {

0 commit comments

Comments
 (0)