WARNING: THIS SITE IS A MIRROR OF GITHUB.COM / IT CANNOT LOGIN OR REGISTER ACCOUNTS / THE CONTENTS ARE PROVIDED AS-IS / THIS SITE ASSUMES NO RESPONSIBILITY FOR ANY DISPLAYED CONTENT OR LINKS / IF YOU FOUND SOMETHING MAY NOT GOOD FOR EVERYONE, CONTACT ADMIN AT ilovescratch@foxmail.com
Skip to content

Commit 9736834

Browse files
committed
fetcher.jsを廃止しrequest.jsに処理を統一
rails/request.js にAPIフェッチ処理を集約するため、fetcher.js を削除し、利用していた全コンポーネント・ファイルでのインポートと呼び出しをrequest.jsのgetに置き換えた 影響ファイル: - Bookmarks.jsx, BookmarksInDashboard.jsx, Events.jsx, Notifications.jsx, Products.jsx, RegularEvents.jsx, Reports.jsx, NotificationsBell.jsx, TagsInput.jsx, tag.js
1 parent faa809b commit 9736834

File tree

11 files changed

+32
-17
lines changed

11 files changed

+32
-17
lines changed

app/javascript/components/Bookmarks.jsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
import React, { useState, useEffect, useRef } from 'react'
22
import useSWR, { useSWRConfig } from 'swr'
3-
import fetcher from '../fetcher'
4-
import { destroy } from '@rails/request.js'
3+
import { get, destroy } from '@rails/request.js'
54
import userIcon from '../user-icon.js'
65
import Pagination from './Pagination'
76
import usePage from './hooks/usePage'
87
import { formatDateToJapanese } from '../dateFormatter'
8+
const fetcher = (url) =>
9+
get(url, { responseKind: 'json' }).then((res) => res.json)
910

1011
export default function Bookmarks() {
1112
const [editable, setEditable] = useState(false)

app/javascript/components/BookmarksInDashboard.jsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
import React, { useState, useEffect, useRef } from 'react'
22
import useSWR, { useSWRConfig } from 'swr'
3-
import fetcher from '../fetcher'
4-
import { destroy } from '@rails/request.js'
3+
import { get, destroy } from '@rails/request.js'
54
import userIcon from '../user-icon.js'
65
import { toast } from '../vanillaToast.js'
76
import { formatDateToJapanese } from '../dateFormatter'
7+
const fetcher = (url) =>
8+
get(url, { responseKind: 'json' }).then((res) => res.json)
89

910
export default function BookmarksInDashboard() {
1011
const [editable, setEditable] = useState(false)

app/javascript/components/Events.jsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,10 @@ import useSWR from 'swr'
33
import Pagination from './Pagination'
44
import LoadingListPlaceholder from './LoadingListPlaceholder'
55
import userIcon from '../user-icon.js'
6-
import fetcher from '../fetcher'
6+
import { get } from '@rails/request.js'
77
import usePage from './hooks/usePage'
8+
const fetcher = (url) =>
9+
get(url, { responseKind: 'json' }).then((res) => res.json)
810

911
export default function Events() {
1012
const per = 20

app/javascript/components/Notifications.jsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,10 @@ import LoadingListPlaceholder from './LoadingListPlaceholder'
44
import Pagination from './Pagination'
55
import UnconfirmedLink from './UnconfirmedLink'
66
import useSWR from 'swr'
7-
import fetcher from '../fetcher'
7+
import { get } from '@rails/request.js'
88
import usePage from './hooks/usePage'
9+
const fetcher = (url) =>
10+
get(url, { responseKind: 'json' }).then((res) => res.json)
911

1012
export default function Notifications({ isMentor }) {
1113
const per = 20

app/javascript/components/NotificationsBell/NotificationsBell.jsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@ import BellButton from './BellButton'
44
import Header from './Header'
55
import Notifications from './Notifications'
66
import Footer from './Footer'
7-
import fetcher from '../../fetcher'
7+
import { get } from '@rails/request.js'
8+
const fetcher = (url) =>
9+
get(url, { responseKind: 'json' }).then((res) => res.json)
810

911
export function useNotification(status) {
1012
const baseUrl = '/api/notifications.json'

app/javascript/components/Products.jsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,11 @@ import Pagination from './Pagination'
44
import LoadingListPlaceholder from './LoadingListPlaceholder'
55
import UnconfirmedLink from './UnconfirmedLink'
66
import Product from './Product'
7-
import fetcher from '../fetcher'
7+
import { get } from '@rails/request.js'
88
import elapsedDays from '../elapsed-days.js'
99
import usePage from './hooks/usePage'
10+
const fetcher = (url) =>
11+
get(url, { responseKind: 'json' }).then((res) => res.json)
1012

1113
export default function Products({
1214
title,

app/javascript/components/RegularEvents.jsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
import React, { useState, useEffect } from 'react'
22
import useSWR from 'swr'
3-
import fetcher from '../fetcher'
3+
import { get } from '@rails/request.js'
44
import queryString from 'query-string'
55
import Pagination from './Pagination'
66
import LoadingListPlaceholder from './LoadingListPlaceholder'
77
import RegularEvent from './RegularEvent'
88
import usePage from './hooks/usePage'
9+
const fetcher = (url) =>
10+
get(url, { responseKind: 'json' }).then((res) => res.json)
911

1012
const RegularEvents = () => {
1113
const getTargetQueryParam = () => {

app/javascript/components/Reports.jsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
import React, { useState } from 'react'
22
import useSWR from 'swr'
3-
import fetcher from '../fetcher'
3+
import { get } from '@rails/request.js'
44
import LoadingListPlaceholder from './LoadingListPlaceholder'
55
import Report from './Report'
66
import Pagination from './Pagination'
77
import PracticeFilterDropdown from './PracticeFilterDropdown'
88
import UnconfirmedLink from './UnconfirmedLink'
99
import usePage from './hooks/usePage'
10+
const fetcher = (url) =>
11+
get(url, { responseKind: 'json' }).then((res) => res.json())
1012

1113
export default function Reports({
1214
userId = '',

app/javascript/components/Tags/TagsInput.jsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,13 @@ import React, { useState, useCallback, useRef, useEffect } from 'react'
22
import TagifyTags from '@yaireo/tagify/dist/react.tagify'
33
import '@yaireo/tagify/dist/tagify.css' // Tagify CSS
44
import useSWR from 'swr'
5-
import fetcher from '../../fetcher'
5+
import { get } from '@rails/request.js'
66
import transformHeadSharp from './transform-head-sharp.js'
77
import validateTagName from './validate-tag-name'
88
import headIsSharpOrOctothorpe from './head-is-sharp-or-octothorpe'
99
import parseTags from './parse_tags'
10+
const fetcher = (url) =>
11+
get(url, { responseKind: 'json' }).then((res) => res.json)
1012

1113
export default function TagsInput({
1214
tagsInitialValue,

app/javascript/fetcher.js

Lines changed: 0 additions & 3 deletions
This file was deleted.

0 commit comments

Comments
 (0)